'terraform get variables from a file from other repo
our organization had decided to keep the terraform configuration files as DRY as possible, by separating the variables (tfvars) into a separate repository. this gives a flexibility for the developers too, to update any changes in the application level requirements, without much looking into the tf configuration files.
I am trying to figure out, if I maintain all the application profiles in a different repository, how would I be able to use them in my configurations.
my variables repo is expected to be
repo
app_1
dev.profile
stage.profile
prod.profile
app_2
dev.profile
stage.profile
prod.profile
how would I be able to read / get file <repo_url>/app_1/DEV.profile if I have to configure app_1 in DEV environment?
Solution 1:[1]
You just check out files using Git. Whether ad-hoc or in CI you probably do something like:
# Decide which app and environment we target
APP=app1
ENVIRONMENT=DEV
# Checkout app and config repos
git checkout <$APP_repo_url> "$APP"
git checkout <config_repo_url> config
# Deploy!
cd "$APP"
terraform init
terraform apply -var-file="../config/$APP/$ENVIRONMENT.profile"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kombajn zbo?owy |
