terraformer README

The project's README from github.com/GoogleCloudPlatform/terraformer. As one markdown file: README.md.

Terraformer

tests linter Go Report Card AUR package Homebrew

This project is no longer maintained and is deprecated.

As of March 16, 2026, this repository has been archived. It is now read-only, and no further updates, security patches, or support will be provided.

A CLI tool that generates tf/json and tfstate files based on existing infrastructure (reverse Terraform).

Waze SRE logo

Table of Contents

Demo GCP

asciicast

Capabilities

  1. Generate tf/json + tfstate files from existing infrastructure for all supported objects by resource.
  2. Remote state can be uploaded to a GCS bucket.
  3. Connect between resources with terraform_remote_state (local and bucket).
  4. Save tf/json files using a custom folder tree pattern.
  5. Import by resource name and type.
  6. Support terraform 0.13 (for terraform 0.11 use v0.7.9).

Terraformer uses Terraform providers and is designed to easily support newly added resources. To upgrade resources with new fields, all you need to do is upgrade the relevant Terraform providers.

Import current state to Terraform configuration from a provider

Usage:
   import [provider] [flags]
   import [provider] [command]

Available Commands:
  list        List supported resources for a provider

Flags:
  -b, --bucket string         gs://terraform-state
  -c, --connect                (default true)
  -С, --compact                (default false)
  -x, --excludes strings      firewalls,networks
  -f, --filter strings        compute_firewall=id1:id2:id4
  -h, --help                  help for google
  -O, --output string         output format hcl or json (default "hcl")
  -o, --path-output string     (default "generated")
  -p, --path-pattern string   {output}/{provider}/ (default "{output}/{provider}/{service}/")
      --projects strings
  -z, --regions strings       europe-west1, (default [global])
  -r, --resources strings     firewall,networks or * for all services
  -s, --state string          local or bucket (default "local")
  -v, --verbose               verbose mode
  -n, --retry-number          number of retries to perform if refresh fails
  -m, --retry-sleep-ms        time in ms to sleep between retries

Use " import [provider] [command] --help" for more information about a command.

Permissions

The tool requires read-only permissions to list service resources.

Resources

You can use --resources parameter to tell resources from what service you want to import.

To import resources from all services, use --resources="*" . If you want to exclude certain services, you can combine the parameter with --excludes to exclude resources from services you don't want to import e.g. --resources="*" --excludes="iam".

Filtering

Filters are a way to choose which resources terraformer imports. It's possible to filter resources by its identifiers or attributes. Multiple filtering values are separated by :. If an identifier contains this symbol, value should be wrapped in ' e.g. --filter=resource=id1:'project:dataset_id'. Identifier based filters will be executed before Terraformer will try to refresh remote state.

Use Type when you need to filter only one of several types of resources. Multiple filters can be combined when importing different resource types. An example would be importing all AWS security groups from a specific AWS VPC:

terraformer import aws -r sg,vpc --filter Type=sg;Name=vpc_id;Value=VPC_ID --filter Type=vpc;Name=id;Value=VPC_ID

Notice how the Name is different for sg than it is for vpc.

Migration state version

For terraform >= 0.13, you can use replace-provider to migrate state from previous versions.

Example usage:

terraform state replace-provider -auto-approve "registry.terraform.io/-/aws" "hashicorp/aws"
Resource ID

Filtering is based on Terraform resource ID patterns. To find valid ID patterns for your resource, check the import part of the Terraform documentation.

Example usage:

terraformer import aws --resources=vpc,subnet --filter=vpc=myvpcid --regions=eu-west-1

Will only import the vpc with id myvpcid. This form of filters can help when it's necessary to select resources by its identifiers.

Field name only

It is possible to filter by specific field name only. It can be used e.g. when you want to retrieve resources only with a specific tag key.

Example usage:

terraformer import aws --resources=s3 --filter="Name=tags.Abc" --regions=eu-west-1

Will only import the s3 resources that have tag Abc. This form of filters can help when the field values are not important from filtering perspective.

Field with dots

It is possible to filter by a field that contains a dot.

Example usage:

terraformer import aws --resources=s3 --filter="Name=tags.Abc.def" --regions=eu-west-1

Will only import the s3 resources that have tag Abc.def.

Planning

The plan command generates a planfile that contains all the resources set to be imported. By modifying the planfile before running the import command, you can rename or filter the resources you'd like to import.

The rest of subcommands and parameters are identical to the import command.

$ terraformer plan google --resources=networks,firewall --projects=my-project --regions=europe-west1-d
(snip)

Saving planfile to generated/google/my-project/terraformer/plan.json

After reviewing/customizing the planfile, begin the import by running import plan.

$ terraformer import plan generated/google/my-project/terraformer/plan.json

Resource structure

Terraformer by default separates each resource into a file, which is put into a given service directory.

The default path for resource files is {output}/{provider}/{service}/{resource}.tf and can vary for each provider.

It's possible to adjust the generated structure by:

  1. Using --compact parameter to group resource files within a single service into one resources.tf file
  2. Adjusting the --path-pattern parameter and passing e.g. --path-pattern {output}/{provider}/ to generate resources for all services in one directory

It's possible to combine --compact --path-pattern parameters together.

Installation

Both Terraformer and a Terraform provider plugin need to be installed.

Terraformer

From a package manager

From releases This installs all providers, set PROVIDER to one of google, aws or kubernetes if you only need one.

export PROVIDER=all
curl -LO "https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-linux-amd64"
chmod +x terraformer-${PROVIDER}-linux-amd64
sudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer
export PROVIDER=all
curl -LO "https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-darwin-amd64"
chmod +x terraformer-${PROVIDER}-darwin-amd64
sudo mv terraformer-${PROVIDER}-darwin-amd64 /usr/local/bin/terraformer
  1. Install Terraform - https://www.terraform.io/downloads
  2. Download exe file for required provider from here - https://github.com/GoogleCloudPlatform/terraformer/releases
  3. Add the exe file path to path variable

From source

  1. Run git clone <terraformer repo> && cd terraformer/
  2. Run go mod download
  3. Run go build -v for all providers OR build with one provider go run build/main.go {google,aws,azure,kubernetes,etc}

Terraform Providers

Create a working folder and initialize the Terraform provider plugin. This folder will be where you run Terraformer commands.

Run terraform init against a versions.tf file to install the plugins required for your platform. For example, if you need plugins for the google provider, versions.tf should contain:

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
    }
  }
  required_version = ">= 0.13"
}

Or, copy your Terraform provider's plugin(s) from the list below to folder ~/.terraform.d/plugins/, as appropriate.

Links to download Terraform provider plugins:

Information on provider plugins: https://www.terraform.io/docs/configuration/providers.html

High-Level steps to add new provider

Contributing

If you have improvements or fixes, we would love to have your contributions. Please read CONTRIBUTING.md for more information on the process we would like contributors to follow.

Developing

Terraformer was built so you can easily add new providers of any kind.

Process for generating tf/json + tfstate files:

  1. Call GCP/AWS/other api and get list of resources.
  2. Iterate over resources and take only the ID (we don't need mapping fields!).
  3. Call to provider for readonly fields.
  4. Call to infrastructure and take tf + tfstate.

Infrastructure

  1. Call to provider using the refresh method and get all data.
  2. Convert refresh data to go struct.
  3. Generate HCL file - tf/json files.
  4. Generate tfstate files.

All mapping of resource is made by providers and Terraform. Upgrades are needed only for providers.

GCP compute resources

For GCP compute resources, use generated code from providers/gcp/gcp_compute_code_generator.

To regenerate code:

go run providers/gcp/gcp_compute_code_generator/*.go

Similar projects

terraforming

Terraformer Benefits
Comparison

Terraforming gets all attributes from cloud APIs and creates HCL and tfstate files with templating. Each attribute in the API needs to map to attribute in Terraform. Generated files from templating can be broken with illegal syntax. When a provider adds new attributes the terraforming code needs to be updated.

Terraformer instead uses Terraform provider files for mapping attributes, HCL library from Hashicorp, and Terraform code.

Look for S3 support in terraforming here and official S3 support Terraforming lacks full coverage for resources - as an example you can see that 70% of S3 options are not supported:

Stargazers over time

Stargazers over time

terraformer (GoogleCloudPlatform/terraformer)

Searching Database…

14.5K ·GitHub
archived
这是什么?Terraformer 是一个命令行工具,可以根据云上已经存在的基础设施,生成 Terraform 配置文件(tf/json 格式)和状态文件,本质上是从正在运行的资源反向生成 Terraform 代码。
它是 Terraform provider,还是一个独立的命令行工具?它是一个用 Go 编写的独立命令行二进制程序。它会调用云厂商的 API 以及对应的 Terraform provider 插件,生成 HCL/JSON 文件和一个 tfstate 文件,它本身并不是 provider。
我该怎么安装和运行它?可以通过包管理器安装(brew install terraformer、sudo port install terraformer、choco install terraformer),下载发布版二进制文件,或者用 git clone、go mod download 和 go build -v 从源码编译。
还需要单独安装 Terraform provider 吗?需要。除了 Terraformer 本身,导入前还必须安装对应的 Terraform provider 插件(例如 google、aws、kubernetes),并将其放到工作目录或 ~/.terraform.d/plugins/ 中。
这个项目还在维护吗?已不再维护。项目于 2026 年 3 月 16 日归档,目前为只读状态,不再提供更新、安全补丁或技术支持。
它支持哪些云厂商?支持的范围很广,包括 Google Cloud、AWS、Azure、AliCloud、IBM Cloud、DigitalOcean、Heroku、Linode、OpenStack、TencentCloud、Vultr、Yandex Cloud、Ionos,还有 Kubernetes、GitHub、Datadog、Keycloak、Vault 以及许多小众 provider。
它支持哪个版本的 Terraform?支持 Terraform 0.13;如果使用 Terraform 0.11,则需要改用较旧的 Terraformer v0.7.9 发布版。
我可以控制导入哪些资源吗?可以。使用 --resources 和 --excludes 选择或跳过整个服务,使用 --filter 按资源 ID、标签键或以点号分隔的字段名进行筛选。
它和类似的 ‘terraforming’ 工具有什么不同?Terraforming 只支持 AWS,并通过模板映射 API 属性,生成的 HCL 可能有问题;而 Terraformer 支持众多 provider,属性映射依赖 Terraform provider 的实际代码,因此当 provider 新增字段时会自动保持同步。
正式导入前可以预览吗?可以。plan 命令会生成一个 planfile,列出所有待导入的资源。你可以在运行 import plan 之前编辑它,重命名或筛选资源。
What are similar projects?kops, encore, pulumi, infracost, neckbeard, opentofu, forge, serverless
Size
67.6 MB
Stars
14.5K
Age
7y
Commits · 90 Days