terragrunt-infrastructure-live-example
terragrunt-infrastructure-live-example copied to clipboard
[Question] How do I set different iam_role for prod and non-prod folders ?
How do I set different iam_role for prod and non-prod folders?
considering this PR from 2018 => https://github.com/gruntwork-io/terragrunt/pull/599/files#diff-04c6e90faac2675aa89e2176d2eec7d8 it seems that I can configure a specific iam_role to be used by terragrunt (and terraform).
My goal is to have a CI/CD (Atlantis) to assume roles when executing the terragrunt command.
How can I set up one role for non-prod folder and a different one for the prod folder?
There are a number of options, including:
- Have a different root
prod/terragrunt.hcl
andnon-prod/terragrunt.hcl
, each with differentiam_role
setting, that all the child modulesinclude
. - Have a single root
terragrunt.hcl
that usesgenerate
to generate aprovider
block with anassume_role
block within. Theassume_role
block can setrole_arn
to a variable, which in prod envs you set to a different value than non-prod envs.
To add another option:
I am making use of direnv (https://direnv.net) for which I create .envrc files in the different account folders. This is what I include:
export TERRAGRUNT_IAM_ROLE=arn:aws:iam::ACCOUNTID:role/ROLE
and other env variables as needed.
I am then able to go into the directory with the right role assumed and then being able to run Terragrunt.
Based on the input of @brikis98, I have created an example for option 2, see:
https://github.com/nilsdebruin/terragrunt-infrastructure-live-example/tree/assumed-role-example
If it is interesting enough, I could create a pull request for it.