As my infrastructure grows, I’m hitting some bottlenecks, particularly having to do with managing variables, outputs, and module arguments.
Scenario:
Let’s say I’m creating the following resource.
resource “azurerm_resource_group” “default” {
name = var.default_resource_group_name
location = var.default_location
}
Next I have to manually open up variables.tf and define variables{} blocks for those 2 variables. I then have to open up outputs.tf and create output blocks for those variables (if I want them output). If I want to add default values, then I have to open up yet another file, terraform.tfvars, and add this same data yet again.
Having to repeat manually entering the same data into 3 different places, well, either I’m doing it wrong or this is woefully inefficient. All the time I saved managing infrastructure, I now spend editing my 4 different files. If I add a module to the mix, I now have yet another layer of arguments and variables to manage.
Terraform is smart enough to know that if I provide that block above, validate is going to explicitly tell me that I need a variables default_location {} block. If it can do that, why can’t it just create it for me? I feel like there should be a command option like --generate-variables, --generate-outputs
etc.
As my infrastructure grows having to validate, open file, manually add missing variable, validate again… I understand why for the workflow init, validate, plan, but some resources have over 250 arguments by themselves. Doing that workflow manually is unsustainable and impossible to use in CI/CD pipelines.
Is there a better way? What automation options or tools are there that I may not be aware of, or what’s wrong with my workflow that using Terraform is now costing me more time to manage input and output files than I did before had I just edited the resource without terraform, especially when working in a team setting?