Use the folders_iam module to assign IAM roles to specific Google Cloud folders. You can specify multiple folders, define standard role-to-member bindings, and apply conditional bindings (IAM Conditions) for time-based or attribute-based access control.
To use this module, provide a list of folders, a mode (either additive or authoritative), and a bindings map. You can also use conditional_bindings to add roles that are only active under specific conditions, such as an expiration timestamp.
module "folder-iam" {
source = "terraform-google-modules/iam/google//modules/folders_iam"
version = "~> 8.2"
folders = ["my-folder-name"]
mode = "additive"
bindings = {
"roles/resourcemanager.folderEditor" = [
"serviceAccount:my-sa@my-project.iam.gserviceaccount.com",
"group:my-group@my-org.com",
]
"roles/resourcemanager.folderViewer" = [
"user:my-user@my-org.com",
]
}
conditional_bindings = [
{
role = "roles/editor"
title = "expires_after_2019_12_31"
description = "Expiring at midnight of 2019-12-31"
expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")"
members = ["user:my-user@my-org.com"]
}
]
}