Some context: I am working on a tool to benchmark the refresh performance of each resource type in a Terraform workspace. To do this I create a temp dir, copy the state file over with just the resources I want to measure. Also I copy over the provider, variable and terraform.required_providers configuration. Then measure the time to run terraform refresh
, Terraform will only refresh those resources I put into the state file. Finally I rank the results and generate a nice report so you can see what resources are slowing down the refresh time the most.
The issue is when someone defines their provider configuration with a value from another resource/data_source, e.g:
provider "aviatrix" {
username = data.aws_ssm_parameter.avx_uname.value
password = data.aws_ssm_parameter.avx_pword.value
controller_ip = data.aws_ssm_parameter.avx_ctrl_ip.value
}
Then my technique breaks down because Terraform will complain that the data/resource is not defined in the root module. If I do copy over the data/resource configuration into the temp tf configuration, then the refresh times are no longer accurate because terraform refresh
will try to refresh the data sources as well instead of just the resources in the state file. This is not the end of the world since it still allows me to make an apples to apples comparison of refresh times, but the numbers are not absolutely accurate.
My question then is: Can I “render” the terraform configuration and then copy over the provider configuration with hard-coded values instead of the data source interpolation expressions. Basically going from the provider configuration above to:
provider "aviatrix" {
username = "uname"
password = "pword"
controller_ip = "1.2.3.4"
}
Paging TF wizard @apparentlymart as this may be an interesting question for you.