tfvar icon indicating copy to clipboard operation
tfvar copied to clipboard

Creating vars.tf entries automatically

Open mjbright opened this issue 2 years ago • 1 comments
trafficstars

It would be great if this tool allowed to avoid the painful process (ok, I'm lazy) of adding variable block definitions each time a new variable is referenced in a config.

e.g. if we have a file main.tf in the config like:

resource aws_instance example { ami = var.ami ... }

Would check to see if a variable definition exists already for ami and if not add this to a tfvar_vars.tf file.

Options:

  • append to existing vars.tf (specify file on command-line)
  • recurse into sub-directories aka modules
  • generate current outputs such as env vars, cli flags, terraform.tfvars

mjbright avatar Aug 10 '23 07:08 mjbright

Thank you for the suggestion. Currently, this tool looks for variable blocks and extracts the information. If we'd implement something like the above, we'd need to do it "in reverse"? It'd be like asking an editor to perform autocompletion on a variable declaration based on its usage. It does seem very interesting, and I am happy to accept PR for this feature.

shihanng avatar Aug 12 '23 01:08 shihanng