From 2b5e0bfdd95641059a48ea063622cca16fc67ff4 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 26 Jan 2021 18:43:33 -0500 Subject: [PATCH 1/2] Add Example For `github_team_repository` also documents a limitation with `for_each` in this scenario --- examples/repository_team/README.md | 18 ++++++++++++ examples/repository_team/main.tf | 41 +++++++++++++++++++++++++++ examples/repository_team/outputs.tf | 0 examples/repository_team/providers.tf | 4 +++ examples/repository_team/variables.tf | 9 ++++++ 5 files changed, 72 insertions(+) create mode 100644 examples/repository_team/README.md create mode 100644 examples/repository_team/main.tf create mode 100644 examples/repository_team/outputs.tf create mode 100644 examples/repository_team/providers.tf create mode 100644 examples/repository_team/variables.tf 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..1918b7ea02 --- /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" +} \ No newline at end of file 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 +} From b668dd774fa062f70cc9b8a124195b607355f7ea Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 26 Jan 2021 18:45:37 -0500 Subject: [PATCH 2/2] fixup! add newline --- examples/repository_team/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/repository_team/main.tf b/examples/repository_team/main.tf index 1918b7ea02..dfbe6d8d42 100644 --- a/examples/repository_team/main.tf +++ b/examples/repository_team/main.tf @@ -38,4 +38,4 @@ resource "github_team_repository" "writers" { team_id = local.teams[count.index] repository = github_repository.writers.name permission = "push" -} \ No newline at end of file +}