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

tf/json + tfstate files from existing infrastructure for all
supported objects by resource.terraform_remote_state (local and bucket).tf/json files using a custom folder tree pattern.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.
The tool requires read-only permissions to list service 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".
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.
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.
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
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:
--compact parameter to group resource files within a single service into one resources.tf file--path-pattern parameter and passing e.g. --path-pattern {output}/{provider}/ to generate resources for all services in one directoryIt's possible to combine --compact --path-pattern parameters together.
From source:
git clone <terraformer repo>go mod downloadgo build -v for all providers OR build with one provider go run build/main.go {google,aws,azure,kubernetes and etc}terraform init against an 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 alternatively
~/.terraform.d/plugins/{darwin,linux}_amd64/, as appropriate.From Releases:
export PROVIDER={all,google,aws,kubernetes}
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,google,aws,kubernetes}
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
If you want to use a package manager:
brew install terraformer.choco install terraformer.Links to download Terraform Providers:
Information on provider plugins: https://www.terraform.io/docs/configuration/providers.htmlโ
Example:
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --connect=true --regions=europe-west1,europe-west4 --projects=aaa,fff
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --filter=compute_firewall=rule1:rule2:rule3 --regions=europe-west1 --projects=aaa,fff
For google-beta provider:
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --regions=europe-west4 --projects=aaa --provider-type beta
List of supported GCP services:
addresses
google_compute_addressautoscalers
google_compute_autoscalerbackendBuckets
google_compute_backend_bucketbackendServices
google_compute_backend_servicebigQuery
google_bigquery_datasetgoogle_bigquery_tablecloudFunctions
google_cloudfunctions_functioncloudsql
google_sql_database_instancegoogle_sql_databasedataProc
google_dataproc_clusterdisks
google_compute_diskexternalVpnGateways
google_compute_external_vpn_gatewaydns
google_dns_managed_zonegoogle_dns_record_setfirewall
google_compute_firewallforwardingRules
google_compute_forwarding_rulegcs
google_storage_bucketgoogle_storage_bucket_aclgoogle_storage_default_object_aclgoogle_storage_bucket_iam_bindinggoogle_storage_bucket_iam_membergoogle_storage_bucket_iam_policygoogle_storage_notificationgke
google_container_clustergoogle_container_node_poolglobalAddresses
google_compute_global_addressglobalForwardingRules
google_compute_global_forwarding_rulehealthChecks
google_compute_health_checkhttpHealthChecks
google_compute_http_health_checkhttpsHealthChecks
google_compute_https_health_checkiam
google_project_iam_custom_rolegoogle_project_iam_membergoogle_service_accountimages
google_compute_imageinstanceGroupManagers
google_compute_instance_group_managerinstanceGroups
google_compute_instance_groupinstanceTemplates
google_compute_instance_templateinstances
google_compute_instanceinterconnectAttachments
google_compute_interconnect_attachmentkms
google_kms_key_ringgoogle_kms_crypto_keylogging
google_logging_metricmemoryStore
google_redis_instancemonitoring
google_monitoring_alert_policygoogle_monitoring_groupgoogle_monitoring_notification_channelgoogle_monitoring_uptime_check_confignetworks
google_compute_networkpacketMirrorings
google_compute_packet_mirroringnodeGroups
google_compute_node_groupnodeTemplates
google_compute_node_templateproject
google_projectpubsub
google_pubsub_subscriptiongoogle_pubsub_topicregionAutoscalers
google_compute_region_autoscalerregionBackendServices
google_compute_region_backend_serviceregionDisks
google_compute_region_diskregionHealthChecks
google_compute_region_health_checkregionInstanceGroups
google_compute_region_instance_groupregionSslCertificates
google_compute_region_ssl_certificateregionTargetHttpProxies
google_compute_region_target_http_proxyregionTargetHttpsProxies
google_compute_region_target_https_proxyregionUrlMaps
google_compute_region_url_mapreservations
google_compute_reservationresourcePolicies
google_compute_resource_policyregionInstanceGroupManagers
google_compute_region_instance_group_managerrouters
google_compute_routerroutes
google_compute_routeschedulerJobs
google_cloud_scheduler_jobsecurityPolicies
google_compute_security_policysslCertificates
google_compute_managed_ssl_certificatesslPolicies
google_compute_ssl_policysubnetworks
google_compute_subnetworktargetHttpProxies
google_compute_target_http_proxytargetHttpsProxies
google_compute_target_https_proxytargetInstances
google_compute_target_instancetargetPools
google_compute_target_pooltargetSslProxies
google_compute_target_ssl_proxytargetTcpProxies
google_compute_target_tcp_proxytargetVpnGateways
google_compute_vpn_gatewayurlMaps
google_compute_url_mapvpnTunnels
google_compute_vpn_tunnelYour tf and tfstate files are written by default to
generated/gcp/zone/service.
Example:
terraformer import aws --resources=vpc,subnet --connect=true --regions=eu-west-1 --profile=prod
terraformer import aws --resources=vpc,subnet --filter=vpc=vpc_id1:vpc_id2:vpc_id3 --regions=eu-west-1
AWS configuration including environmental variables, shared credentials file (~/.aws/credentials), and shared config file (~/.aws/config) will be loaded by the tool by default. To use a specific profile, you can use the following command:
terraformer import aws --resources=vpc,subnet --regions=eu-west-1 --profile=prod
You can also provide no regions when importing resources:
terraformer import aws --resources=cloudfront --profile=prod
In that case terraformer will not know with which region resources are associated with and will not assume any region. That scenario is useful in case of global resources (e.g. CloudFront distributions or Route 53 records) and when region is passed implicitly through environmental variables or metadata service.
accessanalyzer
aws_accessanalyzer_analyzeracm
aws_acm_certificatealb (supports ALB and NLB)
aws_lbaws_lb_listeneraws_lb_listener_ruleaws_lb_listener_certificateaws_lb_target_groupaws_lb_target_group_attachmentapi_gateway
aws_api_gateway_authorizeraws_api_gateway_documentation_partaws_api_gateway_gateway_responseaws_api_gateway_integrationaws_api_gateway_integration_responseaws_api_gateway_methodaws_api_gateway_method_responseaws_api_gateway_modelaws_api_gateway_resourceaws_api_gateway_rest_apiaws_api_gateway_stageaws_api_gateway_usage_planaws_api_gateway_vpc_linkappsync
aws_appsync_graphql_apiauto_scaling
aws_autoscaling_groupaws_launch_configurationaws_launch_templatebudgets
aws_budgets_budgetcloud9
aws_cloud9_environment_ec2cloudfront
aws_cloudfront_distributioncloudformation
aws_cloudformation_stackaws_cloudformation_stack_setaws_cloudformation_stack_set_instancecloudtrail
aws_cloudtrailcloudwatch
aws_cloudwatch_dashboardaws_cloudwatch_event_ruleaws_cloudwatch_event_targetaws_cloudwatch_metric_alarmcodebuild
aws_codebuild_projectcodecommit
aws_codecommit_repositorycodedeploy
aws_codedeploy_appcodepipeline
aws_codepipelineaws_codepipeline_webhookcognito
aws_cognito_identity_poolaws_cognito_user_poolcustomer_gateway
aws_customer_gatewayconfig
aws_config_config_ruleaws_config_configuration_recorderaws_config_delivery_channeldatapipeline
aws_datapipeline_pipelinedevicefarm
aws_devicefarm_projectdynamodb
aws_dynamodb_tableec2_instance
aws_instanceeip
aws_eipelasticache
aws_elasticache_clusteraws_elasticache_parameter_groupaws_elasticache_subnet_groupaws_elasticache_replication_groupebs
aws_ebs_volumeaws_volume_attachmentelastic_beanstalk
aws_elastic_beanstalk_applicationaws_elastic_beanstalk_environmentecs
aws_ecs_clusteraws_ecs_serviceaws_ecs_task_definitionecr
aws_ecr_lifecycle_policyaws_ecr_repositoryaws_ecr_repository_policyefs
aws_efs_access_pointaws_efs_file_systemaws_efs_file_system_policyaws_efs_mount_targeteks
aws_eks_clusterelb
aws_elbemr
aws_emr_clusteraws_emr_security_configurationeni
aws_network_interfacees
aws_elasticsearch_domainfirehose
aws_kinesis_firehose_delivery_streamglue
glue_crawleraws_glue_catalog_databaseaws_glue_catalog_tableiam
aws_iam_groupaws_iam_group_policyaws_iam_group_policy_attachmentaws_iam_instance_profileaws_iam_policyaws_iam_roleaws_iam_role_policyaws_iam_role_policy_attachmentaws_iam_useraws_iam_user_group_membershipaws_iam_user_policyaws_iam_user_policy_attachmentigw
aws_internet_gatewayiot
aws_iot_thingaws_iot_thing_typeaws_iot_topic_ruleaws_iot_role_aliaskinesis
aws_kinesis_streamkms
aws_kms_keyaws_kms_aliaslambda
aws_lambda_event_source_mappingaws_lambda_functionaws_lambda_function_event_invoke_configaws_lambda_layer_versionlogs
aws_cloudwatch_log_groupmedia_package
aws_media_package_channelmedia_store
aws_media_store_containermsk
aws_msk_clusternat
aws_nat_gatewaynacl
aws_network_aclorganization
aws_organizations_accountaws_organizations_organizationaws_organizations_organizational_unitaws_organizations_policyaws_organizations_policy_attachmentqldb
aws_qldb_ledgerrds
aws_db_instanceaws_db_parameter_groupaws_db_subnet_groupaws_db_option_groupaws_db_event_subscriptionresourcegroups
aws_resourcegroups_grouproute53
aws_route53_zoneaws_route53_recordroute_table
aws_route_tableaws_main_route_table_associationaws_route_table_associations3
aws_s3_bucketaws_s3_bucket_policysecretsmanager
aws_secretsmanager_secretsecurityhub
aws_securityhub_accountaws_securityhub_memberaws_securityhub_standards_subscriptionservicecatalog
aws_servicecatalog_portfolioses
aws_ses_configuration_setaws_ses_domain_identityaws_ses_email_identityaws_ses_receipt_ruleaws_ses_receipt_rule_setaws_ses_templatesfn
aws_sfn_activityaws_sfn_state_machinesg
aws_security_groupaws_security_group_rule (if a rule cannot be inlined)sns
aws_sns_topicaws_sns_topic_subscriptionsqs
aws_sqs_queuesubnet
aws_subnetswf
aws_swf_domaintransit_gateway
aws_ec2_transit_gateway_route_tableaws_ec2_transit_gateway_vpc_attachmentwaf
aws_waf_byte_match_setaws_waf_geo_match_setaws_waf_ipsetaws_waf_rate_based_ruleaws_waf_regex_match_setaws_waf_regex_pattern_setaws_waf_ruleaws_waf_rule_groupaws_waf_size_constraint_setaws_waf_sql_injection_match_setaws_waf_web_aclaws_waf_xss_match_setwaf_regional
aws_wafregional_byte_match_setaws_wafregional_geo_match_setaws_wafregional_ipsetaws_wafregional_rate_based_ruleaws_wafregional_regex_match_setaws_wafregional_regex_pattern_setaws_wafregional_ruleaws_wafregional_rule_groupaws_wafregional_size_constraint_setaws_wafregional_sql_injection_match_setaws_wafregional_web_aclaws_wafregional_xss_match_setvpc
aws_vpcvpc_peering
aws_vpc_peering_connectionvpn_connection
aws_vpn_connectionvpn_gateway
aws_vpn_gatewayworkspaces
aws_workspaces_directoryaws_workspaces_ip_groupaws_workspaces_workspacexray
aws_xray_sampling_ruleAWS services that are global will be imported without specified region even if several regions will be passed. It is to ensure only one representation of an AWS resource is imported.
List of global AWS services:
budgetscloudfrontiamorganizationroute53wafAttribute filters allow filtering across different resource types by its attributes.
terraformer import aws --resources=ec2_instance,ebs --filter="Name=tags.costCenter;Value=20000:'20001:1'" --regions=eu-west-1
Will only import AWS EC2 instances along with EBS volumes annotated with tag costCenter with values 20000 or 20001:1. Attribute filters are by default applicable to all resource types although it's possible to specify to what resource type a given filter should be applicable to by providing Type=<type> parameter. For example:
terraformer import aws --resources=ec2_instance,ebs --filter=Type=ec2_instance;Name=tags.costCenter;Value=20000:'20001:1' --regions=eu-west-1
Will work as same as example above with a change the filter w
Content type
Image
Digest
Size
993 MB
Last updated
over 4 years ago
docker pull bridgecrew/terraformer