Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How do I set different iam_role for prod and non-prod folders ? #44

Open
robertomoutinho opened this issue Sep 2, 2020 · 3 comments
Labels

Comments

@robertomoutinho
Copy link

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?

@brikis98
Copy link
Member

brikis98 commented Sep 3, 2020

There are a number of options, including:

  1. Have a different root prod/terragrunt.hcl and non-prod/terragrunt.hcl, each with different iam_role setting, that all the child modules include.
  2. Have a single root terragrunt.hcl that uses generate to generate a provider block with an assume_role block within. The assume_role block can set role_arn to a variable, which in prod envs you set to a different value than non-prod envs.

@nilsdebruin
Copy link

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.

@nilsdebruin
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants