Environment Variable Substitution in Circle CI

Objective: Trying to substitute a terraform related json file with values from CircleCI enviroment.

My input json file would be below:

  "aad_login_name": "",
  "aad_login_tenant_id": "",
  "aad_login_object_id": "",
  "enable_syn_sparkpool": "",
  "enable_syn_sqlpool": "",
  "jumphost_password": "",
  "jumphost_username": "",
  "location": "",
  "prefix": "",
  "resource_group": "",
  "synadmin_password": "",
  "synadmin_username": "" ,
  "aad_login_sp_app_id": "",
  "aad_login_sp_password": ""  

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.

1 Like

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.

1 Like

I have used jq module to transform and input values to tfvars… works now.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.