Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained
Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained
Terraforming is no longer actively maintained.
If you want to generate Terraform configurations from existing cloud resources, consider using other tools, such as
Thank you for your contributions and supports in the past 6 years.
Export existing AWS resources to Terraform style (tf, tfstate)
iam_instance_profile) uses newer resource specificationAdd this line to your application's Gemfile:
gem 'terraforming'And then execute:
$ bundleOr install it yourself as:
$ gem install terraformingYou need to set AWS credentials.
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AWS_REGION=xx-yyyy-0You can also specify credential profile in ~/.aws/credentials by --profile option.
$ cat ~/.aws/credentials
[hoge]
aws_access_key_id = Hoge
aws_secret_access_key = FugaFuga
# Pass profile name by --profile option
$ terraforming s3 --profile hogeYou can assume a role by using the --assume option.
$ terraforming s3 --assume arn:aws:iam::123456789123:role/test-roleYou can force the AWS SDK to utilize the CA certificate that is bundled with the SDK for systems where the default OpenSSL certificate is not installed (e.g. Windows) by utilizing the --use-bundled-cert option.
PS C:\> terraforming ec2 --use-bundled-cert…$ terraforming <resource> [--profile PROFILE](e.g. S3 buckets):
$ terraforming s3resource "aws_s3_bucket" "hoge" {
bucket = "hoge"
acl = "private"
}
resource "aws_s3_bucket" "fuga" {
bucket = "fuga"
acl = "private"
}$ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite] [--profile PROFILE](e.g. S3 buckets):
$ terraforming s3 --tfstate…If you want to merge exported tfstate to existing terraform.tfstate, specify --tfstate --merge=/path/to/terraform.tfstate option.
You can overwrite existing terraform.tfstate by specifying --overwrite option together.
Existing terraform.tfstate:
…To generate merged tfstate:
$ terraforming s3 --tfstate --merge=/path/to/tfstate…After writing exported tf and tfstate to files, execute terraform plan and check the result.
There should be no diff.
$ terraform plan
No changes. Infrastructure is up-to-date. This means that Terraform
could not detect any differences between your configuration and
the real physical resources that exist. As a result, Terraform
doesn't need to do anything.Example assuming you want to export everything from us-west-2 and you are using ~/.aws/credentials with a default profile
export AWS_REGION=us-west-2
terraforming help | grep terraforming | grep -v help | awk '{print "terraforming", $2, "--profile", "default", ">", $2".tf";}' | bash
# find files that only have 1 empty line (likely nothing in AWS)
find . -type f -name '*.tf' | xargs wc -l | grep ' 1 .'terraforming kmsk does not export EXTERNAL origin key, bacause Terraform does not support it.Terraforming Docker Image is available at quay.io/dtan4/terraforming and developed at dtan4/dockerfile-terraforming.
Pull the Docker image:
$ docker pull quay.io/dtan4/terraforming:latestAnd then run Terraforming as a Docker container:
$ docker run \
--rm \
--name terraforming \
-e AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX \
-e AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
-e AWS_REGION=xx-yyyy-0 \
quay.io/dtan4/terraforming:latest \
terraforming s3After checking out the repo, run script/setup to install dependencies. Then, run script/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Please read Contribution Guide at first.
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)There are some similar tools to import your existing infrastructure to Terraform configuration.
No open issues yet, or sync has not completed.