Objective: Trying to substitute a terraform related json file with values from CircleCI enviroment.
My input json file would be below:
"synadmin_username": "" ,
Now I need to transform/Substitute variables defined my CircleCI environment on above file. Is that possible ?
so before I create infrastructure on any cloud, I need to populate this json file with values from circleci environment variables then execute my terraform work flow? any ideas?
It will depend on where you consider CircleCI fits within your workflow.
The normal model for a CI system is that it drives the whole process and so the config.yml ends up driving the building of the infrastructure before the build/tests are started - if so the creation of the json file is a simple shell script run as a step within the config.yml file. This just creates the file or uses shell commands to do the substitution.
If you instead have a process that builds up the infrastructure first and then starts a job within circleci you are going to more likely need an external location for all these values that can be used to populate not just your json file, but also the CircleCI project. I use a third-party tool for this called Doppler, which is basically a centralized env value store with a range of integration tools.
Terraform also reads tfvars from the environment with the format
TF_<variable-name> so you could set those on the job or step and likely not need to generate the json file unless you are generating it to use outside of CircleCI.
I have used jq module to transform and input values to tfvars… works now.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.