Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

terraforming

> 数据库
Open source

Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained

4.3K stars0 likes1 views
WebsiteGitHub

About

Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained

Terraforming

Project Status (2021-12-11): 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

  • Terraformer which supports many cloud providers not only AWS but also GCP, Azure, GitHub, Kubernetes, etc., and is able to generate configurations based on the latest provider's resource schema.
  • Terracognita

Thank you for your contributions and supports in the past 6 years.


Export existing AWS resources to Terraform style (tf, tfstate)

  • Supported version
  • Installation
  • Prerequisites
  • Usage
    • Export tf
    • Export tfstate
    • Example: Export all
  • Run as Docker container
  • Development
  • Contributing
  • Similar projects
  • License

Supported version

  • Ruby 2.3 or higher is required
  • Terraform v0.9.3 or higher is recommended
    • Some resources (e.g. iam_instance_profile) uses newer resource specification

Installation

Add this line to your application's Gemfile:

ruby
gem 'terraforming'

And then execute:

$ bundle

Or install it yourself as:

$ gem install terraforming

Prerequisites

You need to set AWS credentials.

bash
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AWS_REGION=xx-yyyy-0

You can also specify credential profile in ~/.aws/credentials by --profile option.

bash
$ cat ~/.aws/credentials
[hoge]
aws_access_key_id = Hoge
aws_secret_access_key = FugaFuga

# Pass profile name by --profile option
$ terraforming s3 --profile hoge

You can assume a role by using the --assume option.

bash
$ terraforming s3 --assume arn:aws:iam::123456789123:role/test-role

You 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.

bash
PS C:\> terraforming ec2 --use-bundled-cert

Usage

…

Export tf

bash
$ terraforming <resource> [--profile PROFILE]

(e.g. S3 buckets):

bash
$ terraforming s3
hcl
resource "aws_s3_bucket" "hoge" {
    bucket = "hoge"
    acl    = "private"
}

resource "aws_s3_bucket" "fuga" {
    bucket = "fuga"
    acl    = "private"
}

Export tfstate

bash
$ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite] [--profile PROFILE]

(e.g. S3 buckets):

bash
$ 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:

bash
$ 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.

bash
$ 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: Export all

Example assuming you want to export everything from us-west-2 and you are using ~/.aws/credentials with a default profile

bash
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 .'

Caveats

  • terraforming kmsk does not export EXTERNAL origin key, bacause Terraform does not support it.

Run as Docker container

Terraforming Docker Image is available at quay.io/dtan4/terraforming and developed at dtan4/dockerfile-terraforming.

Pull the Docker image:

bash
$ docker pull quay.io/dtan4/terraforming:latest

And then run Terraforming as a Docker container:

bash
$ 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 s3

Development

After 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.

Contributing

Please read Contribution Guide at first.

  1. Fork it ( https://github.com/dtan4/terraforming/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Similar projects

There are some similar tools to import your existing infrastructure to Terraform configuration.

  • GoogleCloudPlatform/terraformer
  • cycloidio/terracognita

License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyawsruby-gemterraformtfstate

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库