diff --git a/examples/repository_team/README.md b/examples/repository_team/README.md new file mode 100644 index 0000000000..e81708d4bb --- /dev/null +++ b/examples/repository_team/README.md @@ -0,0 +1,18 @@ +# Repository Team Example + +This demos populating a repository with a team. + +This example will create a repositories in the specified `owner` organization. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. + +Alternatively, you may use variables passed via command line: + +```console +export GITHUB_OWNER= +export GITHUB_TOKEN= +``` + +```console +terraform apply \ + -var "owner=${GITHUB_OWNER}" \ + -var "github_token=${GITHUB_TOKEN}" +``` diff --git a/examples/repository_team/main.tf b/examples/repository_team/main.tf new file mode 100644 index 0000000000..dfbe6d8d42 --- /dev/null +++ b/examples/repository_team/main.tf @@ -0,0 +1,41 @@ +# NOTE: There are errors when using the following syntax. See links for details. +# /cc https://github.com/hashicorp/terraform/issues/23529 +# /cc https://github.com/hashicorp/terraform/issues/4149 +# /cc https://github.com/integrations/terraform-provider-github/issues/500 +# +# data "github_team" "writers" { +# slug = "writer-team" +# } +# +# resource "github_team_repository" "writers" { +# for_each = data.github_team.writers.id +# # or for multiple teams something like: +# # for_each = { for obj in [data.github_team.writers] : obj.id => obj.id } +# team_id = each.value +# repository = "repo" +# permission = "push" +# } + +data "github_team" "writers" { + slug = "writers" +} + +data "github_team" "editors" { + slug = "editors" +} + +locals { + teams = [data.github_team.writers.id, data.github_team.editors.id] +} + +resource "github_repository" "writers" { + name = "writers" + auto_init = true +} + +resource "github_team_repository" "writers" { + count = length(local.teams) + team_id = local.teams[count.index] + repository = github_repository.writers.name + permission = "push" +} diff --git a/examples/repository_team/outputs.tf b/examples/repository_team/outputs.tf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/repository_team/providers.tf b/examples/repository_team/providers.tf new file mode 100644 index 0000000000..07836b6b1a --- /dev/null +++ b/examples/repository_team/providers.tf @@ -0,0 +1,4 @@ +provider "github" { + owner = var.owner + token = var.github_token +} diff --git a/examples/repository_team/variables.tf b/examples/repository_team/variables.tf new file mode 100644 index 0000000000..aafb16bf9f --- /dev/null +++ b/examples/repository_team/variables.tf @@ -0,0 +1,9 @@ +variable "owner" { + description = "GitHub owner used to configure the provider" + type = string +} + +variable "github_token" { + description = "GitHub access token used to configure the provider" + type = string +}