Skip to content

Instantly share code, notes, and snippets.

@phinze
Last active June 21, 2022 04:23
Show Gist options
  • Save phinze/225b1d4bf395dd14674c1ee877d9a96a to your computer and use it in GitHub Desktop.
Save phinze/225b1d4bf395dd14674c1ee877d9a96a to your computer and use it in GitHub Desktop.
An example of how you could map teams to many workspaces using the Terraform Enterprise provider
# Start w/ a data source to get a list of all the workspaces
# See: https://www.terraform.io/docs/providers/tfe/d/workspace_ids.html
data "tfe_workspace_ids" "all-workspaces" {
names = ["*"]
organization = "my-org-name"
}
# Look up the ID of the teamn you're looking to map
# See: https://www.terraform.io/docs/providers/tfe/d/team.html
data "tfe_team" "architects" {
name = "my-architects-team"
organization = "my-org-name"
}
# Use the new resource for_each support to map out the team permissions
# See: https://www.terraform.io/docs/providers/tfe/r/team_access.html
# And: https://www.terraform.io/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings
resource "tfe_team_access" "architects-team-gets-read-permission-on-all-workspaces" {
for_each = data.tfe_workspace_ids.all-workspaces.ids
access = "read"
team_id = data.tfe_team.architects.id
workspace_id = each.value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment