New to Terraform, I'm trying to render a template but I don't want to initialize the state or anything. I want to be able to download the template file from source control and then plug in the variable values and get a rendered template. I have tried using terraform console
but because the template depends on some values in a locals { ... }
block it's saying that I need to run terraform apply
to be able to render the template. Is there not a clever way I can still get the values from this locals { ... }
block without having to run terraform apply
?
If I do have to run apply, is there a way to make sure everything happens locally and there is no back-end interactions (trying to prevent mishaps)?
CodePudding user response:
The way I ended up getting the job done was as follows:
- pull the
locals
block contents into a file in the current working directory - copy any
*.tfvars
files to current working directory and rename*.auto.tfvars
- Create a data resource with the template and vars passed in:
data "template_file" "rendered_template" { template = "${file("/path/to/your.template")}" vars = { my_var = "hello" } }
- Run
terraform refresh
in current working directory - Run
terraform state show data.template_file.rendered_template