Skip to content

Commit

Permalink
Add Example For github_team_repository (integrations#676)
Browse files Browse the repository at this point in the history
* Add Example For `github_team_repository`

also documents a limitation with `for_each` in this scenario

* fixup! add newline
  • Loading branch information
Jeremy Udit authored Jan 27, 2021
1 parent 75c8a04 commit 2c7be5c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/repository_team/README.md
Original file line number Diff line number Diff line change
@@ -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}"
```
41 changes: 41 additions & 0 deletions examples/repository_team/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# NOTE: There are errors when using the following syntax. See links for details.
# /cc https:/hashicorp/terraform/issues/23529
# /cc https:/hashicorp/terraform/issues/4149
# /cc https:/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"
}
Empty file.
4 changes: 4 additions & 0 deletions examples/repository_team/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "github" {
owner = var.owner
token = var.github_token
}
9 changes: 9 additions & 0 deletions examples/repository_team/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2c7be5c

Please sign in to comment.