Created
September 27, 2019 22:28
-
-
Save neurogenesis/53e436cc3f7674720047cbd7917c8e45 to your computer and use it in GitHub Desktop.
generate terraform templates from existing infrastructure (via terraforming)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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