Skip to content

Instantly share code, notes, and snippets.

@Laxman-SM
Forked from phinze/teams-to-workspaces.tf
Created June 21, 2022 04:23
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 Laxman-SM/950ed3991f964044f90547b00a2d0f7a to your computer and use it in GitHub Desktop.
Save Laxman-SM/950ed3991f964044f90547b00a2d0f7a 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