Terraform 1.1.0 alpha: `terraform add` command feedback

Terraform 1.1.0 will include a new command, terraform add , which can be used to generate resource configuration - either a blank template which you can fill in, or configuration generated from an existing resource in state.

This function is available in today’s v1.1.0-alpha20210630 release. The add command documentation is not yet published on terraform.io, but you can view it in Github.

The usual caveats apply: this is an alpha release, not supported for production use. Instead, please try out the release in isolated test environments.

We’d love to hear any feedback on this function! Feel free to leave any thoughts and ideas for terraform add here. If you come across any bugs, please open a Github issue .


Kristin Laemmert, Terraform Core


We’re really eager to see this! We see this as unlocking a bunch of very cool development workflows for us :slight_smile:

I’m sure there’s a laundry list of additional functionality y’all are thinking about adding, but I have some specific ideas.

  • It’d be very cool to have -out replace the existing resource in the destination file, if the resource already exists in the state and unambiguously resolves to a specific resource (hard to see how that intersects with modules and for_each, though). One of the main use-cases here is to have a CI mechanism that opens pull requests with the updated Terraform config after we detect changes to the true resource state.
  • It might be interesting to have scriptable hooks that can assist in augmenting properties by deriving them from other resources in the file, though perhaps an alternative solution would include some easily scriptable CLI that can alter Terraform configuration after running terraform apply.

Interesting, so this should eventually simplify terraforming existing infrastructure into configuration. I think that there should be couple of SDK methods added for this to work properly - some resources may want blobs of text as HEREDOC, others may want them in files. Adding linking of resources through IDs is relatively straightforward. There’s also a need to “discover what resources there are”. We’d need some sort of “terraform generate” command for that.

I’ve written an extension to provider - terraform-provider-databricks/exporter at master · databrickslabs/terraform-provider-databricks · GitHub - please take a look at this implementation to generate resources, would be nice to work together on getting it more widespread and standardized.

@skeggse having CI to detect and add configuration is a bit slow, because all resources have to be listed. Also imagine states with 10k+ resources. It’s also difficult for CI to know where to place the autogenerated config :man_shrugging:t2: It could be figured out for the scope of single provider, but globally it’s not that easy.