Reversed Terraform – generate tf from existing resources.

Within day of a typical DevOps engineer it might come a time when you need to do some reverse work from what normally you would expect to do with Terraform. And that is to create TF code for resources that already exist ( for any given reason ).

If you find yourself in that situation check out https://github.com/GoogleCloudPlatform/terraformer. Its a nifty tool which can help you to achieve that goal and save many hours of manual labour.

Installation is as easy as running brew install terraformer

It supports multiple providers as well as filtering of resources you may be interested in.

Import current state to Terraform configuration from a provider

   import [provider] [flags]
   import [provider] [command]

Available Commands:
  list        List supported resources for a provider

  -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.


Leave a Reply

Your email address will not be published. Required fields are marked *