Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Example For github_team_repository #676

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://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"
}
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
}