Skip to content

Instantly share code, notes, and snippets.

@neurogenesis
Created September 27, 2019 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neurogenesis/53e436cc3f7674720047cbd7917c8e45 to your computer and use it in GitHub Desktop.
Save neurogenesis/53e436cc3f7674720047cbd7917c8e45 to your computer and use it in GitHub Desktop.
generate terraform templates from existing infrastructure (via terraforming)
#!/usr/bin/env ruby
# USAGE:
# gem install terraforming
# export AWS_PROFILE=xxx
# mkdir -p ~/projects/terraform
# cd ~/projects/terraform
# mkdir -p imports/[account]/[region]
# cd imports/[account]/[region]
# ../../../bin/terraforming-import-all
tf_targets = %W[ alb asg cwa dbpg dbsg dbsn ddb ec2 ecc ecsn efs
eip elb iamg iamgm iamgp iamip iamp iampa iamr iamrp iamu
iamup igw kmsa kmsk lc nacl nat nif r53r r53z rds rs rt
rta s3 sg sn snss snst sqs vgw vpc
]
if ENV['AWS_PROFILE'].nil?
puts "ERROR: AWS profile not defined"
exit 1
end
puts "INFO: importing resources for 'AWS_PROFILE=#{ENV['AWS_PROFILE']}' ..."
date = Time.now.strftime("%Y%m%d")
tf_targets.each do |target|
cmd = "terraforming #{target} > #{target}-#{date}.tf.import"
puts "INFO: running '#{cmd}'"
`#{cmd}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment