All Projects β†’ GoogleCloudPlatform β†’ Terraformer

GoogleCloudPlatform / Terraformer

Licence: apache-2.0
CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code

Programming Languages

go
31211 projects - #10 most used programming language
HCL
1544 projects

Projects that are alternatives of or similar to Terraformer

Terratag
Terratag is a CLI tool that enables users of Terraform to automatically create and maintain tags across their entire set of AWS, Azure, and GCP resources
Stars: ✭ 385 (-93.9%)
Mutual labels:  aws, cloud, gcp, terraform, hcl, infrastructure-as-code
Infracost
Cloud cost estimates for Terraform in pull requestsπŸ’°πŸ“‰ Love your cloud bill!
Stars: ✭ 4,505 (-28.67%)
Mutual labels:  aws, cloud, gcp, terraform, infrastructure-as-code
Airflow Toolkit
Any Airflow project day 1, you can spin up a local desktop Kubernetes Airflow environment AND one in Google Cloud Composer with tested data pipelines(DAGs) πŸ–₯ >> [ πŸš€, 🚒 ]
Stars: ✭ 51 (-99.19%)
Mutual labels:  cloud, gcp, google-cloud, terraform, hcl
Cloudblock
Cloudblock automates deployment of secure ad-blocking for all of your devices - even when mobile. Step-by-step text and video guides included! Compatible clouds include AWS, Azure, Google Cloud, and Oracle Cloud. Cloudblock deploys Wireguard VPN, Pi-Hole DNS Ad-blocking, and DNS over HTTPS in a cloud provider - or locally - using Terraform and Ansible.
Stars: ✭ 257 (-95.93%)
Mutual labels:  aws, cloud, gcp, terraform, hcl
Terracognita
Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration
Stars: ✭ 452 (-92.84%)
Mutual labels:  aws, cloud, gcp, terraform, infrastructure-as-code
Terraform Aws Gitlab Runner
Terraform module for AWS GitLab runners on ec2 (spot) instances
Stars: ✭ 292 (-95.38%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Terraform Modules
Reusable Terraform modules
Stars: ✭ 63 (-99%)
Mutual labels:  aws, cloud, terraform, hcl
Terraform
Terraform automation for Cloud
Stars: ✭ 121 (-98.08%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Iam Policy Json To Terraform
Small tool to convert an IAM Policy in JSON format into a Terraform aws_iam_policy_document
Stars: ✭ 282 (-95.54%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Infra Personal
Terraform for setting up my personal infrastructure
Stars: ✭ 45 (-99.29%)
Mutual labels:  aws, cloud, terraform, hcl
Hybrid multicloud overlay
MutiCloud_Overlay demonstrates a use case of overlay over one or more clouds such as AWS, Azure, GCP, OCI, Alibaba and a vSphere private infrastructure in Hub and spoke topology, point to point topology and in a Single cloud. Overlay protocols IPv6 and IPv4 are independent of underlying infrastructure. This solution can be integrated with encryption and additional security features.
Stars: ✭ 127 (-97.99%)
Mutual labels:  aws, gcp, terraform, hcl
My Links
Knowledge seeks no man
Stars: ✭ 311 (-95.08%)
Mutual labels:  aws, cloud, gcp, infrastructure-as-code
Terraform Aws Asg
Terraform AWS Auto Scaling Stack
Stars: ✭ 58 (-99.08%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Engine
Deploy your apps on any Cloud provider in just a few seconds
Stars: ✭ 1,132 (-82.08%)
Mutual labels:  aws, cloud, gcp, terraform
Typhoon
Minimal and free Kubernetes distribution with Terraform
Stars: ✭ 1,397 (-77.88%)
Mutual labels:  aws, google-cloud, terraform, hcl
Pulumi
Pulumi - Developer-First Infrastructure as Code. Your Cloud, Your Language, Your Way πŸš€
Stars: ✭ 10,887 (+72.37%)
Mutual labels:  aws, cloud, gcp, infrastructure-as-code
Checkov
Prevent cloud misconfigurations during build-time for Terraform, Cloudformation, Kubernetes, Serverless framework and other infrastructure-as-code-languages with Checkov by Bridgecrew.
Stars: ✭ 3,572 (-43.45%)
Mutual labels:  aws, gcp, terraform, infrastructure-as-code
Terraform Sqs Lambda Trigger Example
Example on how to create a AWS Lambda triggered by SQS in Terraform
Stars: ✭ 31 (-99.51%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Karch
A Terraform module to create and maintain Kubernetes clusters on AWS easily, relying entirely on kops
Stars: ✭ 38 (-99.4%)
Mutual labels:  aws, terraform, hcl, infrastructure-as-code
Azure arc
Automated Azure Arc environments
Stars: ✭ 224 (-96.45%)
Mutual labels:  aws, gcp, terraform, hcl

Terraformer

tests linter Go Report Card AUR package Homebrew

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

  • Disclaimer: This is not an official Google product
  • Created by: Waze SRE

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.

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

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}
  4. 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 alternatively

  • Copy your Terraform provider's plugin(s) to folder ~/.terraform.d/plugins/{darwin,linux}_amd64/, as appropriate.

From Releases:

  • Linux
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
  • MacOS
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

Using a package manager

If you want to use a package manager:

  • Homebrew users can use brew install terraformer.
  • MacPorts users can use sudo port install terraformer.
  • Chocolatey users can use choco install terraformer.

Links to download Terraform Providers:

  • Major Cloud
    • Google Cloud provider >2.11.0 - here
    • AWS provider >2.25.0 - here
    • Azure provider >1.35.0 - here
    • Alicloud provider >1.57.1 - here
  • Cloud
    • DigitalOcean provider >1.9.1 - here
    • Heroku provider >2.2.1 - here
    • LaunchDarkly provider >=2.1.1 - here
    • Linode provider >1.8.0 - here
    • OpenStack provider >1.21.1 - here
    • TencentCloud provider >1.50.0 - here
    • Vultr provider >1.0.5 - here
    • Yandex provider >0.42.0 - here
  • Infrastructure Software
    • Kubernetes provider >=1.9.0 - here
    • RabbitMQ provider >=1.1.0 - here
  • Network
    • Cloudflare provider >1.16 - here
    • Fastly provider >0.16.1 - here
    • NS1 provider >1.8.3 - here
    • PAN-OS provider >= 1.8.3 - here
  • VCS
    • GitHub provider >=2.2.1 - here
  • Monitoring & System Management
    • Datadog provider >2.1.0 - here
    • New Relic provider >2.0.0 - here
    • Mackerel provider > 0.0.6 - here
    • Pagerduty >=1.9 - here
    • Opsgenie >= 0.6.0 here
  • Community
    • Keycloak provider >=1.19.0 - here
    • Logz.io provider >=1.1.1 - here
    • Commercetools provider >= 0.21.0 - here
    • Mikrotik provider >= 0.2.2 - here
    • Xen Orchestra provider >= 0.18.0 - here
    • GmailFilter provider >= 1.0.1 - here
    • Vault provider - here

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

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
  • Simpler to add new providers and resources - already supports AWS, GCP, GitHub, Kubernetes, and Openstack. Terraforming supports only AWS.
  • Better support for HCL + tfstate, including updates for Terraform 0.12.
  • If a provider adds new attributes to a resource, there is no need change Terraformer code - just update the Terraform provider on your laptop.
  • Automatically supports connections between resources in HCL files.
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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].