{"id":14957718,"url":"https://github.com/googlecloudplatform/terraformer","last_synced_at":"2025-05-13T11:09:50.310Z","repository":{"id":37413046,"uuid":"184490584","full_name":"GoogleCloudPlatform/terraformer","owner":"GoogleCloudPlatform","description":"CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code","archived":false,"fork":false,"pushed_at":"2025-05-12T23:16:27.000Z","size":69590,"stargazers_count":13582,"open_issues_count":61,"forks_count":1749,"subscribers_count":153,"default_branch":"master","last_synced_at":"2025-05-13T11:09:34.215Z","etag":null,"topics":["aws","cloud","gcp","golang","google-cloud","hcl","infrastructure-as-code","kubernetes","terraform","terraform-configurations"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleCloudPlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-01T22:37:33.000Z","updated_at":"2025-05-13T10:48:33.000Z","dependencies_parsed_at":"2023-12-22T16:12:06.723Z","dependency_job_id":"e9d700c6-02ed-49d4-ab18-76e616509059","html_url":"https://github.com/GoogleCloudPlatform/terraformer","commit_stats":{"total_commits":1236,"total_committers":193,"mean_commits":6.404145077720207,"dds":0.7839805825242718,"last_synced_commit":"e5c9bd581025da9ccf3de286773f46053264d191"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fterraformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fterraformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fterraformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fterraformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleCloudPlatform","download_url":"https://codeload.github.com/GoogleCloudPlatform/terraformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253929367,"owners_count":21985802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cloud","gcp","golang","google-cloud","hcl","infrastructure-as-code","kubernetes","terraform","terraform-configurations"],"created_at":"2024-09-24T13:15:23.580Z","updated_at":"2025-05-13T11:09:48.626Z","avatar_url":"https://github.com/GoogleCloudPlatform.png","language":"Go","readme":"# Terraformer\n\n[![tests](https://github.com/GoogleCloudPlatform/terraformer/actions/workflows/test.yml/badge.svg)](https://github.com/GoogleCloudPlatform/terraformer/actions/workflows/test.yml)\n[![linter](https://github.com/GoogleCloudPlatform/terraformer/actions/workflows/linter.yml/badge.svg)](https://github.com/GoogleCloudPlatform/terraformer/actions/workflows/linter.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/GoogleCloudPlatform/terraformer)](https://goreportcard.com/report/github.com/GoogleCloudPlatform/terraformer)\n[![AUR package](https://img.shields.io/aur/version/terraformer)](https://aur.archlinux.org/packages/terraformer/)\n[![Homebrew](https://img.shields.io/badge/dynamic/json.svg?url=https://formulae.brew.sh/api/formula/terraformer.json\u0026query=$.versions.stable\u0026label=homebrew)](https://formulae.brew.sh/formula/terraformer)\n\nA CLI tool that generates `tf`/`json` and `tfstate` files based on existing infrastructure\n(reverse Terraform).\n\n*   Disclaimer: This is not an official Google product\n*   Created by: Waze SRE\n\n![Waze SRE logo](assets/waze-sre-logo.png)\n\n# Table of Contents\n- [Demo GCP](#demo-gcp)\n- [Capabilities](#capabilities)\n- [Installation](#installation)\n- [Supported Providers](/docs)\n    * Major Cloud\n        * [Google Cloud](/docs/gcp.md)\n        * [AWS](/docs/aws.md)\n        * [Azure](/docs/azure.md)\n        * [AliCloud](/docs/alicloud.md)\n        * [IBM Cloud](/docs/ibmcloud.md)\n    * Cloud\n        * [DigitalOcean](/docs/digitalocean.md)\n        * [Equinix Metal](/docs/equinixmetal.md)\n        * [Fastly](/docs/fastly.md)\n        * [Heroku](/docs/heroku.md)\n        * [LaunchDarkly](/docs/launchdarkly.md)\n        * [Linode](/docs/linode.md)\n        * [NS1](/docs/ns1.md)\n        * [OpenStack](/docs/openstack.md)\n        * [TencentCloud](/docs/tencentcloud.md)\n        * [Vultr](/docs/vultr.md)\n        * [Yandex Cloud](/docs/yandex.md)\n        * [Ionos Cloud](/docs/ionoscloud.md)\n    * Infrastructure Software\n        * [Kubernetes](/docs/kubernetes.md)\n        * [OctopusDeploy](/docs/octopus.md)\n        * [RabbitMQ](/docs/rabbitmq.md)\n    * Network\n        * [Cloudflare](/docs/cloudflare.md) (broken, see #1761)\n        * [Myrasec](/docs/myrasec.md)\n        * [PAN-OS](/docs/panos.md)\n    * VCS\n        * [Azure DevOps](/docs/azuredevops.md)\n        * [GitHub](/docs/github.md)\n        * [Gitlab](/docs/gitlab.md)\n    * Monitoring \u0026 System Management\n        * [Datadog](/docs/datadog.md)\n        * [New Relic](/docs/relic.md)\n        * [Mackerel](/docs/mackerel.md)\n        * [PagerDuty](/docs/pagerduty.md)\n        * [Opsgenie](/docs/opsgenie.md)\n        * [Honeycomb.io](/docs/honeycombio.md)\n        * [Opal](/docs/opal.md)\n    * Community\n        * [Keycloak](/docs/keycloak.md)\n        * [Logz.io](/docs/logz.md)\n        * [Commercetools](/docs/commercetools.md)\n        * [Mikrotik](/docs/mikrotik.md)\n        * [Xen Orchestra](/docs/xen.md)\n        * [GmailFilter](/docs/gmailfilter.md)\n        * [Grafana](/docs/grafana.md)\n        * [Vault](/docs/vault.md)\n    * Identity\n        * [Okta](/docs/okta.md)\n        * [Auth0](/docs/auth0.md)\n        * [AzureAD](/docs/azuread.md)\n- [Contributing](#contributing)\n- [Developing](#developing)\n- [Infrastructure](#infrastructure)\n- [Stargazers over time](#stargazers-over-time)\n\n## Demo GCP\n[![asciicast](https://asciinema.org/a/243961.svg)](https://asciinema.org/a/243961)\n\n## Capabilities\n\n1.  Generate `tf`/`json` + `tfstate` files from existing infrastructure for all\n    supported objects by resource.\n2.  Remote state can be uploaded to a GCS bucket.\n3.  Connect between resources with `terraform_remote_state` (local and bucket).\n4.  Save `tf`/`json` files using a custom folder tree pattern.\n5.  Import by resource name and type.\n6.  Support terraform 0.13 (for terraform 0.11 use v0.7.9).\n\nTerraformer uses Terraform providers and is designed to easily support newly added resources.\nTo upgrade resources with new fields, all you need to do is upgrade the relevant Terraform providers.\n```\nImport current state to Terraform configuration from a provider\n\nUsage:\n   import [provider] [flags]\n   import [provider] [command]\n\nAvailable Commands:\n  list        List supported resources for a provider\n\nFlags:\n  -b, --bucket string         gs://terraform-state\n  -c, --connect                (default true)\n  -С, --compact                (default false)\n  -x, --excludes strings      firewalls,networks\n  -f, --filter strings        compute_firewall=id1:id2:id4\n  -h, --help                  help for google\n  -O, --output string         output format hcl or json (default \"hcl\")\n  -o, --path-output string     (default \"generated\")\n  -p, --path-pattern string   {output}/{provider}/ (default \"{output}/{provider}/{service}/\")\n      --projects strings\n  -z, --regions strings       europe-west1, (default [global])\n  -r, --resources strings     firewall,networks or * for all services\n  -s, --state string          local or bucket (default \"local\")\n  -v, --verbose               verbose mode\n  -n, --retry-number          number of retries to perform if refresh fails\n  -m, --retry-sleep-ms        time in ms to sleep between retries\n\nUse \" import [provider] [command] --help\" for more information about a command.\n```\n#### Permissions\n\nThe tool requires read-only permissions to list service resources.\n\n#### Resources\n\nYou can use `--resources` parameter to tell resources from what service you want to import.\n\nTo 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\"`.\n\n#### Filtering\n\nFilters 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.\n\nUse `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:\n```\nterraformer import aws -r sg,vpc --filter Type=sg;Name=vpc_id;Value=VPC_ID --filter Type=vpc;Name=id;Value=VPC_ID\n```\nNotice how the `Name` is different for `sg` than it is for `vpc`.\n\n##### Migration state version\nFor terraform \u003e= 0.13, you can use `replace-provider` to migrate state from previous versions.\n\nExample usage:\n```\nterraform state replace-provider -auto-approve \"registry.terraform.io/-/aws\" \"hashicorp/aws\"\n```\n\n##### Resource ID\n\nFiltering is based on Terraform resource ID patterns. To find valid ID patterns for your resource, check the import part of the [Terraform documentation][terraform-providers].\n\n[terraform-providers]: https://www.terraform.io/docs/providers/\n\nExample usage:\n\n```\nterraformer import aws --resources=vpc,subnet --filter=vpc=myvpcid --regions=eu-west-1\n```\nWill only import the vpc with id `myvpcid`. This form of filters can help when it's necessary to select resources by its identifiers.\n\n##### Field name only\n\nIt 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.\n\nExample usage:\n\n```\nterraformer import aws --resources=s3 --filter=\"Name=tags.Abc\" --regions=eu-west-1\n```\nWill 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.\n\n##### Field with dots\n\nIt is possible to filter by a field that contains a dot.\n\nExample usage:\n\n```\nterraformer import aws --resources=s3 --filter=\"Name=tags.Abc.def\" --regions=eu-west-1\n```\nWill only import the s3 resources that have tag `Abc.def`.\n\n#### Planning\n\nThe `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.\n\nThe rest of subcommands and parameters are identical to the `import` command.\n\n```\n$ terraformer plan google --resources=networks,firewall --projects=my-project --regions=europe-west1-d\n(snip)\n\nSaving planfile to generated/google/my-project/terraformer/plan.json\n```\n\nAfter reviewing/customizing the planfile, begin the import by running `import plan`.\n\n```\n$ terraformer import plan generated/google/my-project/terraformer/plan.json\n```\n\n### Resource structure\n\nTerraformer by default separates each resource into a file, which is put into a given service directory.\n\nThe default path for resource files is `{output}/{provider}/{service}/{resource}.tf` and can vary for each provider.\n\nIt's possible to adjust the generated structure by:\n1. Using `--compact` parameter to group resource files within a single service into one `resources.tf` file\n2. Adjusting the `--path-pattern` parameter and passing e.g. `--path-pattern {output}/{provider}/` to generate resources for all services in one directory\n\nIt's possible to combine `--compact` `--path-pattern` parameters together.\n\n### Installation\n\nBoth Terraformer and a Terraform provider plugin need to be installed.\n\n#### Terraformer\n\n**From a package manager**\n- [Homebrew](https://brew.sh/) users can use `brew install terraformer`.\n- [MacPorts](https://www.macports.org/) users can use `sudo port install terraformer`.\n- [Chocolatey](https://chocolatey.org/) users can use `choco install terraformer`.\n\n**From releases**\nThis installs all providers, set `PROVIDER` to one of `google`, `aws` or `kubernetes` if you only need one.\n\n* Linux\n```\nexport PROVIDER=all\ncurl -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\"\nchmod +x terraformer-${PROVIDER}-linux-amd64\nsudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer\n```\n* MacOS\n```\nexport PROVIDER=all\ncurl -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\"\nchmod +x terraformer-${PROVIDER}-darwin-amd64\nsudo mv terraformer-${PROVIDER}-darwin-amd64 /usr/local/bin/terraformer\n```\n* Windows\n1. Install Terraform - https://www.terraform.io/downloads\n2. Download exe file for required provider from here - https://github.com/GoogleCloudPlatform/terraformer/releases\n3. Add the exe file path to path variable\n\n**From source**\n1.  Run `git clone \u003cterraformer repo\u003e \u0026\u0026 cd terraformer/`\n2.  Run `go mod download`\n3.  Run `go build -v` for all providers OR build with one provider\n`go run build/main.go {google,aws,azure,kubernetes,etc}`\n\n#### Terraform Providers\n\nCreate a working folder and initialize the Terraform provider plugin.  This folder will be where you run Terraformer commands.\n\nRun ```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:\n```\nterraform {\n  required_providers {\n    google = {\n      source = \"hashicorp/google\"\n    }\n  }\n  required_version = \"\u003e= 0.13\"\n}\n```\n\nOr, copy your Terraform provider's plugin(s) from the list below to folder `~/.terraform.d/plugins/`, as appropriate.\n\nLinks to download Terraform provider plugins:\n* Major Cloud\n    * Google Cloud provider \u003e2.11.0 - [here](https://releases.hashicorp.com/terraform-provider-google/)\n    * AWS provider \u003e2.25.0 - [here](https://releases.hashicorp.com/terraform-provider-aws/)\n    * Azure provider \u003e1.35.0 - [here](https://releases.hashicorp.com/terraform-provider-azurerm/)\n    * Alicloud provider \u003e1.57.1 - [here](https://releases.hashicorp.com/terraform-provider-alicloud/)\n* Cloud\n    * DigitalOcean provider \u003e1.9.1 - [here](https://releases.hashicorp.com/terraform-provider-digitalocean/)\n    * Heroku provider \u003e2.2.1 - [here](https://releases.hashicorp.com/terraform-provider-heroku/)\n    * LaunchDarkly provider \u003e=2.1.1 - [here](https://releases.hashicorp.com/terraform-provider-launchdarkly/)\n    * Linode provider \u003e1.8.0 - [here](https://releases.hashicorp.com/terraform-provider-linode/)\n    * OpenStack provider \u003e1.21.1 - [here](https://releases.hashicorp.com/terraform-provider-openstack/)\n    * TencentCloud provider \u003e1.50.0 - [here](https://releases.hashicorp.com/terraform-provider-tencentcloud/)\n    * Vultr provider \u003e1.0.5 - [here](https://releases.hashicorp.com/terraform-provider-vultr/)\n    * Yandex provider \u003e0.42.0 - [here](https://releases.hashicorp.com/terraform-provider-yandex/)\n    * Ionoscloud provider \u003e6.3.3 - [here](https://github.com/ionos-cloud/terraform-provider-ionoscloud/releases)\n* Infrastructure Software\n    * Kubernetes provider \u003e=1.9.0 - [here](https://releases.hashicorp.com/terraform-provider-kubernetes/)\n    * RabbitMQ provider \u003e=1.1.0 - [here](https://releases.hashicorp.com/terraform-provider-rabbitmq/)\n* Network\n    * Myrasec provider \u003e1.44 - [here](https://github.com/Myra-Security-GmbH/terraform-provider-myrasec)\n    * Cloudflare provider \u003e1.16 - [here](https://releases.hashicorp.com/terraform-provider-cloudflare/)\n    * Fastly provider \u003e0.16.1 - [here](https://releases.hashicorp.com/terraform-provider-fastly/)\n    * NS1 provider \u003e1.8.3 - [here](https://releases.hashicorp.com/terraform-provider-ns1/)\n    * PAN-OS provider \u003e= 1.8.3 - [here](https://github.com/PaloAltoNetworks/terraform-provider-panos)\n* VCS\n    * GitHub provider \u003e=2.2.1 - [here](https://releases.hashicorp.com/terraform-provider-github/)\n* Monitoring \u0026 System Management\n    * Datadog provider \u003e2.1.0 - [here](https://releases.hashicorp.com/terraform-provider-datadog/)\n    * New Relic provider \u003e2.0.0 - [here](https://releases.hashicorp.com/terraform-provider-newrelic/)\n    * Mackerel provider \u003e 0.0.6 - [here](https://github.com/mackerelio-labs/terraform-provider-mackerel)\n    * Pagerduty \u003e=1.9 - [here](https://releases.hashicorp.com/terraform-provider-pagerduty/)\n    * Opsgenie \u003e= 0.6.0 [here](https://releases.hashicorp.com/terraform-provider-opsgenie/)\n    * Honeycomb.io \u003e= 0.10.0 - [here](https://github.com/honeycombio/terraform-provider-honeycombio/releases)\n    * Opal \u003e= 0.0.2 - [here](https://github.com/opalsecurity/terraform-provider-opal/releases)\n* Community\n    * Keycloak provider \u003e=1.19.0 - [here](https://github.com/mrparkers/terraform-provider-keycloak/)\n    * Logz.io provider \u003e=1.1.1 - [here](https://github.com/jonboydell/logzio_terraform_provider/)\n    * Commercetools provider \u003e= 0.21.0 - [here](https://github.com/labd/terraform-provider-commercetools)\n    * Mikrotik provider \u003e= 0.2.2 - [here](https://github.com/ddelnano/terraform-provider-mikrotik)\n    * Xen Orchestra provider \u003e= 0.18.0 - [here](https://github.com/ddelnano/terraform-provider-xenorchestra)\n    * GmailFilter provider \u003e= 1.0.1 - [here](https://github.com/yamamoto-febc/terraform-provider-gmailfilter)\n    * Vault provider - [here](https://github.com/hashicorp/terraform-provider-vault)\n    * Auth0 provider - [here](https://github.com/alexkappa/terraform-provider-auth0)\n    * AzureAD provider - [here](https://github.com/hashicorp/terraform-provider-azuread)\n\nInformation on provider plugins:\nhttps://www.terraform.io/docs/configuration/providers.html\n\n\n## High-Level steps to add new provider\n * Initialize provider details in cmd/root.go and create a provider initialization file in the terraformer/cmd folder\n * Create a folder under terraformer/providers/ for your provider\n * Create two files under this folder\n   * \u003cprovide_name\u003e_provider.go\n   * \u003cprovide_name\u003e_service.go\n* Initialize all provider's supported services in \u003cprovide_name\u003e_provider.go file\n* Create script for each supported service in same folder\n\n## Contributing\n\nIf you have improvements or fixes, we would love to have your contributions.\nPlease read [CONTRIBUTING.md](./CONTRIBUTING.md) for more information on the process we would like\ncontributors to follow.\n\n## Developing\n\nTerraformer was built so you can easily add new providers of any kind.\n\nProcess for generating `tf`/`json` + `tfstate` files:\n\n1.  Call GCP/AWS/other api and get list of resources.\n2.  Iterate over resources and take only the ID (we don't need mapping fields!).\n3.  Call to provider for readonly fields.\n4.  Call to infrastructure and take tf + tfstate.\n\n## Infrastructure\n\n1.  Call to provider using the refresh method and get all data.\n2.  Convert refresh data to go struct.\n3.  Generate HCL file - `tf`/`json` files.\n4.  Generate `tfstate` files.\n\nAll mapping of resource is made by providers and Terraform. Upgrades are needed only\nfor providers.\n\n##### GCP compute resources\n\nFor GCP compute resources, use generated code from\n`providers/gcp/gcp_compute_code_generator`.\n\nTo regenerate code:\n\n```\ngo run providers/gcp/gcp_compute_code_generator/*.go\n```\n\n### Similar projects\n\n#### [terraforming](https://github.com/dtan4/terraforming)\n\n##### Terraformer Benefits\n\n* Simpler to add new providers and resources - already supports AWS, GCP, GitHub, Kubernetes, and Openstack. Terraforming supports only AWS.\n* Better support for HCL + tfstate, including updates for Terraform 0.12.\n* If a provider adds new attributes to a resource, there is no need change Terraformer code - just update the Terraform provider on your laptop.\n* Automatically supports connections between resources in HCL files.\n\n##### Comparison\n\nTerraforming 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.\n\nTerraformer instead uses Terraform provider files for mapping attributes, HCL library from Hashicorp, and Terraform code.\n\nLook for S3 support in terraforming here and official S3 support\nTerraforming lacks full coverage for resources - as an example you can see that 70% of S3 options are not supported:\n\n* terraforming - https://github.com/dtan4/terraforming/blob/master/lib/terraforming/template/tf/s3.erb\n* official S3 support - https://www.terraform.io/docs/providers/aws/r/s3_bucket\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/GoogleCloudPlatform/terraformer.svg)](https://starchart.cc/GoogleCloudPlatform/terraformer)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglecloudplatform%2Fterraformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgooglecloudplatform%2Fterraformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglecloudplatform%2Fterraformer/lists"}