What is Terraformer?
master.tf or .json) and tfstate files based on your existing, already-deployed infrastructure. This allows you to import existing resources into Terraform management.repository·master·Indexed 12 days ago
https://github.com/googlecloudplatform/terraformerA CLI tool for 'reverse Terraform' that generates Terraform configuration files (.tf or .json) and tfstate files from existing cloud and infrastructure resources. It supports providers such as Google Cloud, AWS, and Kubernetes. Note: Terraformer was deprecated and archived as of March 16, 2026.
.tf or .json) and tfstate files based on your existing, already-deployed infrastructure. This allows you to import existing resources into Terraform management.Terraformer follows a specific workflow to transform cloud resources into Terraform configuration and state files:
.tf/.json and .tfstate files.By default, Terraformer writes the generated .tf and .tfstate files to the following directory structure:
generated/gcp/[zone]/[service]
When importing azurerm_virtual_network, Terraformer imports the configuration with subnet information stripped to prevent circular dependencies.
Requirement: To successfully import subnet information, you must explicitly import the azurerm_subnet resource type as well.
The infrastructure layer converts raw provider data into Terraform files using these steps:
refresh method to retrieve all necessary data..tf or .json)..tfstate files.Note: Resource mapping is handled by the providers and Terraform itself. When a Terraform provider adds new attributes to a resource, Terraformer does not require code changes; you only need to update the Terraform provider on your local machine.
Terraformer can import resources from Xen Orchestra using the terraform-provider-xenorchestra. To perform an import, use the import xenorchestra command and specify the resource type with the -r flag.
Do not pass credentials directly as command-line arguments, as they may be stored in your bash history. Instead, export them as environment variables before running the command.
XOA_URL: The URL for your Xen Orchestra instance (e.g., ws://your-xenorchestra-domain).XOA_USER: Your Xen Orchestra username.XOA_PASSWORD: Your Xen Orchestra password.xenorchestra_aclxenorchestra_resource_set# Set credentials safely via environment variables
export XOA_URL=ws://your-xenorchestra-domain
export XOA_USER=username
export XOA_PASSWORD=password
# Import a specific resource type (e.g., acl)
terraformer import xenorchestra -r=aclTerraformer uses the terraform-provider-heroku to import Heroku resources. Because Heroku is organized by apps, the importer is designed to capture complete apps along with dependent resources like addons and domains.
Important: Use App IDs (UUIDs) Apps must be identified by their UUID, not their name. To retrieve an app's ID, use the Heroku CLI:
heroku apps:info --json --app=<NAME>Handling Config Vars
Imported apps include settable configuration variables (excluding those from add-ons) as config_vars in the Terraform configuration. Since these may contain secrets, you should manually split them into sensitive_config_vars before running terraform plan or apply to ensure security.
export HEROKU_API_KEY=<token>
# Import all apps for a specific team
./terraformer import heroku --resources=app --team=<TEAM_NAME>
# Import specific apps using their UUIDs
./terraformer import heroku --resources=app --filter=app=<UUID1>
./terraformer import heroku --resources=app --filter=app=<UUID1>:<UUID2>
# Import with a custom output directory pattern
./terraformer import heroku --resources=app --filter=app=<ID> --path-pattern='{output}/{provider}/<DIRECTORY_NAME>'
# Import all enabled account features
./terraformer import heroku --resources=account_featureTo import resources from Opal into Terraform, set your authentication token and run the import command.
Environment Variables:
OPAL_AUTH_TOKEN: Your token from https://app.opal.dev/settings#api.OPAL_BASE_URL: Required if running an on-prem installation (obtain from https://my.opal.com).Command Flags:
--resources: Specify which resource types to import. Use --resources=* for all or specific types like --resources=owner.--path-pattern: Defines the output directory structure using {output}/{provider}.Note: The --filter flag is currently not supported for the Opal provider.
export OPAL_AUTH_TOKEN=Your_token_from_https://app.opal.dev/settings#api
# For on-prem:
# export OPAL_BASE_URL=Your_url_from_https://my.opal.com
./terraformer import opal --resources=* --path-pattern {output}/{provider}After running terraformer, your files will be in a generated/ subdirectory.
If you are using Terraform version >= 0.13, you must perform a state migration to map the provider correctly before you can use the files:
cd generated/opal/.$ cd generated/opal/
$ terraform state replace-provider -auto-approve "registry.terraform.io/-/opal" "opalsecurity/opal"
$ terraform init
$ terraform planBefore running terraformer for Commercetools, you must export the required authentication credentials. You can also override the default API and Token URLs if your environment uses non-standard endpoints.
# Required variables
export CTP_PROJECT_KEY=key
export CTP_CLIENT_ID=foo
export CTP_CLIENT_SECRET=bar
export CTP_CLIENT_SCOPE=scope
# Optional variables (overrides defaults)
export CTP_BASE_URL=base_url # default: https://api.sphere.io
export CTP_TOKEN_URL=token_url # default: https://auth.sphere.ioUse the plan command to preview changes or the import command to generate Terraform configuration files for existing Commercetools resources. Use the -r flag to specify the resource type.
# Only planning
./terraformer plan commercetools -r=types
# Import commercetools types
./terraformer import commercetools -r=typesYou can use Terraformer to import existing Kubernetes resources into Terraform configuration files. Use the import command with the kubernetes provider name. You can specify multiple resource types using the --resources flag and narrow down the scope of the import using the --filter flag with the syntax resource_type=name1:name2:name3.
# Import specific Kubernetes resource types
terraformer import kubernetes --resources=deployments,services,storageclasses
# Import specific resources using filters (e.g., specific deployment names)
terraformer import kubernetes --resources=deployments,services,storageclasses --filter=deployment=name1:name2:name3