Skip to content

Instantly share code, notes, and snippets.

@sergsoares
Created July 13, 2022 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergsoares/dde1c7614fbfc8c985483af030f5c03f to your computer and use it in GitHub Desktop.
Save sergsoares/dde1c7614fbfc8c985483af030f5c03f to your computer and use it in GitHub Desktop.
Demonstração de ideia para criação de policies dinâmicas com attach em múltiplos users e roles.
# terraform.tfvars
policies = [
{
policy_name = "policy-alpha",
roles_to_attach = []
users_to_attach = ["user1", "user2"]
content = {}
},
{
policy_name = "policy-beta",
roles_to_attach = []
users_to_attach = ["user1", "user2"]
content = {}
}
]
# Resultado que eu gostaria de gerar atrávés de resources com count e usando local para pré-processar.
resource "aws_iam_policy" "policy" {
name = value["policy_alpha"]
policy = value["policy_alpha"].content
}
resource "aws_iam_policy" "policy" {
name = value["policy_beta"]
policy = value["policy_beta"].content
}
resource "aws_iam_user_policy_attachment" "attach_users" {
user = "policy_alpha"
policy_arn = "user1"
}
resource "aws_iam_user_policy_attachment" "attach_users" {
user = "policy_alpha"
policy_arn = "user2"
}
resource "aws_iam_user_policy_attachment" "attach_users" {
user = "policy_beta"
policy_arn = "user1"
}
resource "aws_iam_user_policy_attachment" "attach_users" {
user = "policy_beta"
policy_arn = "user2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment