Skip to content

Commit 70ef82f

Browse files
committed
feat: allow existing and no team for github
1 parent d3e4c60 commit 70ef82f

9 files changed

Lines changed: 42 additions & 31 deletions

File tree

.github/workflows/docs-fmt-test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Docs & fmt test
2+
name: fmt test
33

44
on:
55
pull_request:
@@ -13,7 +13,7 @@ concurrency:
1313

1414
jobs:
1515
docsfmttest:
16-
name: Docs & fmt test
16+
name: fmt test
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout repository
@@ -31,14 +31,10 @@ jobs:
3131
terraform_version: latest
3232
terraform_wrapper: false
3333

34-
- name: Install tools
35-
run: make tools
36-
3734
- name: Check fmt and docs
3835
run: |
3936
echo "==> Running make fmt & make docs"
4037
make fmt
41-
make docs
4238
echo "==> Testing for changes to tracked files"
4339
CHANGES=$(git status -suno)
4440
if [ "$CHANGES" ]; then

Makefile

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,14 @@ default:
44
@echo "Thing is one of:"
55
@echo "docs fmt fmtcheck tfclean tools"
66

7-
docs:
8-
@echo "==> Updating documentation..."
9-
find . | egrep "\.md" | grep -v README.md | sort | while read f; do terrafmt fmt $$f; done
10-
117
fmt:
128
@echo "==> Fixing Terraform code with terraform fmt..."
139
terraform fmt -recursive
14-
@echo "==> Fixing embedded Terraform with terrafmt..."
15-
find . | egrep "\.md|\.tf" | grep -v README.md | sort | while read f; do terrafmt fmt $$f; done
1610

1711
fmtcheck:
18-
@echo "==> Checking source code with gofmt..."
19-
@sh "$(CURDIR)/scripts/gofmtcheck.sh"
2012
@echo "==> Checking source code with terraform fmt..."
2113
terraform fmt -check -recursive
2214

23-
tfclean:
24-
@echo "==> Cleaning terraform files..."
25-
find . -type d -name '.terraform' | xargs rm -vrf
26-
find . -type f -name 'tfplan' | xargs rm -vf
27-
find . -type f -name 'terraform.tfstate*' | xargs rm -vf
28-
find . -type f -name '.terraform.lock.hcl' | xargs rm -vf
29-
30-
tools:
31-
go install github.com/katbyte/terrafmt@latest
32-
3315
# Makefile targets are files, but we aren't using it like this,
3416
# so have to declare PHONY targets
35-
.PHONY: docs fmt fmtcheck tfclean tools
17+
.PHONY: fmt fmtcheck

alz/github/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ module "github" {
9191
backend_azure_storage_account_name = local.resource_names.storage_account
9292
backend_azure_storage_account_container_name = local.resource_names.storage_container
9393
approvers = var.apply_approvers
94+
create_team = var.apply_approval_team_creation_enabled
95+
existing_team_name = var.apply_approval_existing_team_name
9496
team_name = local.resource_names.version_control_system_team
9597
runner_group_name = local.resource_names.version_control_system_runner_group
9698
use_runner_group = local.use_runner_group

alz/github/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ variable "apply_approvers" {
194194
default = []
195195
}
196196

197+
variable "apply_approval_team_creation_enabled" {
198+
description = "Controls whether to create a team for approvals."
199+
type = bool
200+
default = true
201+
}
202+
203+
variable "apply_approval_existing_team_name" {
204+
description = "The name of an existing team to use for approvals. Only required if 'apply_approval_team_creation_enabled' is 'false'. If this is left null and `apply_approval_team_creation_enabled` is `false`, the module will not set any team for approvals."
205+
type = string
206+
default = null
207+
}
208+
197209
variable "create_branch_policies" {
198210
description = "Controls whether to create branch policies for the repositories"
199211
type = bool

modules/github/environment.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ resource "github_repository_environment" "alz" {
55
repository = github_repository.alz.name
66

77
dynamic "reviewers" {
8-
for_each = each.key == local.apply_key && length(var.approvers) > 0 ? [1] : []
8+
for_each = each.key == local.apply_key && local.approver_count > 0 ? [1] : []
99
content {
1010
teams = [
11-
github_team.alz.id
11+
local.team_id
1212
]
1313
}
1414
}

modules/github/repository_module.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ resource "github_branch_protection" "alz" {
3232
required_pull_request_reviews {
3333
dismiss_stale_reviews = true
3434
restrict_dismissals = true
35-
required_approving_review_count = length(var.approvers) > 1 ? 1 : 0
35+
required_approving_review_count = local.approver_count > 1 ? 1 : 0
3636
}
3737
}

modules/github/repository_templates.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resource "github_branch_protection" "alz_templates" {
3333
required_pull_request_reviews {
3434
dismiss_stale_reviews = true
3535
restrict_dismissals = true
36-
required_approving_review_count = length(var.approvers) > 1 ? 1 : 0
36+
required_approving_review_count = local.approver_count > 1 ? 1 : 0
3737
}
3838
}
3939

modules/github/team.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ locals {
2020
invalid_approvers = setunion(local.invalid_approvers_by_email, local.invalid_approvers_by_login)
2121
}
2222

23+
locals {
24+
team_id = var.create_team ? github_team.alz[0].id : var.existing_team_name == null ? null : data.github_team.alz[0].id
25+
approver_count = var.create_team ? length(local.approvers) : var.existing_team_name == null ? 0 : (data.github_team.alz[0].members)
26+
}
27+
28+
data "github_team" "alz" {
29+
count = var.create_team ? 0 : 1
30+
slug = var.existing_team_name
31+
}
32+
2333
resource "github_team" "alz" {
34+
count = var.create_team ? 1 : 0
2435
name = var.team_name
2536
description = "Approvers for the Landing Zone Terraform Apply"
2637
privacy = "closed"
@@ -34,14 +45,14 @@ resource "github_team" "alz" {
3445
}
3546

3647
resource "github_team_membership" "alz" {
37-
for_each = { for approver in local.approvers : approver.login => approver }
48+
for_each = var.create_team ? { for approver in local.approvers : approver.login => approver } : {}
3849
team_id = github_team.alz.id
3950
username = each.value.login
4051
role = "member"
4152
}
4253

4354
resource "github_team_repository" "alz" {
44-
team_id = github_team.alz.id
55+
team_id = local.team_id
4556
repository = github_repository.alz.name
4657
permission = "push"
4758
}

modules/github/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ variable "approvers" {
5454
type = list(string)
5555
}
5656

57+
variable "create_team" {
58+
type = bool
59+
}
60+
61+
variable "existing_team_name" {
62+
type = string
63+
}
64+
5765
variable "team_name" {
5866
type = string
5967
}

0 commit comments

Comments
 (0)