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

Allow additive IAM grants by robots name #1160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ module "project" {
# tftest modules=1 resources=2
```

### Using shortcodes for Service Identities in additive IAM
Most Service Identities contains project number in their e-mail address and this prevents additive IAM to work, as these values are not known at moment of execution of `terraform plan` (its not an issue for authoritative IAM). To refer current project Service Identities you may use shortcodes for Service Identities similarly as for `service_identity_iam` when configuring Shared VPC.

```hcl
module "project" {
source = "./fabric/modules/project"
name = "project-example"

services = [
"run.googleapis.com",
"container.googleapis.com",
]

iam_additive = {
"roles/editor" = ["cloudservices"]
"roles/vpcaccess.user" = ["cloudrun"]
"roles/container.hostServiceAgentUser" = ["container-engine"]
}
}
# tftest modules=1 resources=6
```


### Service identities requiring manual IAM grants

The module will create service identities at project creation instead of creating of them at the time of first use. This allows granting these service identities roles in other projects, something which is usually necessary in a Shared VPC context.
Expand Down
13 changes: 12 additions & 1 deletion modules/project/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ locals {
}
iam_additive = {
for pair in concat(local._iam_additive_pairs, local._iam_additive_member_pairs) :
"${pair.role}-${pair.member}" => pair
"${pair.role}-${pair.member}" => {
role = pair.role
member = (
pair.member == "cloudservices"
? "serviceAccount:${local.service_account_cloud_services}"
: pair.member == "default-compute"
? "serviceAccount:${local.service_accounts_default.compute}"
: pair.member == "default-gae"
? "serviceAccount:${local.service_accounts_default.gae}"
: try("serviceAccount:${local.service_accounts_robots[pair.member]}", pair.member)
)
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions tests/modules/project/examples/iam-additive-members.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ values:
project_id: project-example
module.project.google_project_iam_member.additive["roles/editor-user:[email protected]"]:
condition: []
member: user:[email protected]
project: project-example
role: roles/editor
module.project.google_project_iam_member.additive["roles/owner-user:[email protected]"]:
condition: []
member: user:[email protected]
project: project-example
role: roles/owner
module.project.google_project_iam_member.additive["roles/owner-user:[email protected]"]:
condition: []
member: user:[email protected]
project: project-example
role: roles/owner

Expand Down
4 changes: 0 additions & 4 deletions tests/modules/project/examples/iam-additive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ values:
module.project.google_project.project[0]: {}
module.project.google_project_iam_member.additive["roles/owner-group:[email protected]"]:
condition: []
member: group:[email protected]
project: project-example
role: roles/owner
module.project.google_project_iam_member.additive["roles/storage.objectAdmin-group:[email protected]"]:
condition: []
member: group:[email protected]
project: project-example
role: roles/storage.objectAdmin
module.project.google_project_iam_member.additive["roles/viewer-group:[email protected]"]:
condition: []
member: group:[email protected]
project: project-example
role: roles/viewer
module.project.google_project_iam_member.additive["roles/viewer-group:[email protected]"]:
condition: []
member: group:[email protected]
project: project-example
role: roles/viewer

Expand Down