Skip to content
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
8 changes: 2 additions & 6 deletions .github/workflows/docs-fmt-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Docs & fmt test
name: fmt test

on:
pull_request:
Expand All @@ -13,36 +13,32 @@

jobs:
docsfmttest:
name: Docs & fmt test
name: fmt test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup go
uses: actions/setup-go@19bb51245e9c80abacb2e91cc42b33fa478b8639 # v4.2.1
with:
go-version: '1.20.x'
cache-dependency-path: tests/go.sum

- name: Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: latest
terraform_wrapper: false

- name: Install tools
run: make tools

- name: Check fmt and docs
run: |
echo "==> Running make fmt & make docs"
make fmt
make docs
echo "==> Testing for changes to tracked files"
CHANGES=$(git status -suno)
if [ "$CHANGES" ]; then
echo "Repository formatting or documentation is not correct."
echo "Run 'make fmt && make docs' locally and commit the changes to fix."
exit 1
fi

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
20 changes: 1 addition & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,14 @@ default:
@echo "Thing is one of:"
@echo "docs fmt fmtcheck tfclean tools"

docs:
@echo "==> Updating documentation..."
find . | egrep "\.md" | grep -v README.md | sort | while read f; do terrafmt fmt $$f; done

fmt:
@echo "==> Fixing Terraform code with terraform fmt..."
terraform fmt -recursive
@echo "==> Fixing embedded Terraform with terrafmt..."
find . | egrep "\.md|\.tf" | grep -v README.md | sort | while read f; do terrafmt fmt $$f; done

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

tfclean:
@echo "==> Cleaning terraform files..."
find . -type d -name '.terraform' | xargs rm -vrf
find . -type f -name 'tfplan' | xargs rm -vf
find . -type f -name 'terraform.tfstate*' | xargs rm -vf
find . -type f -name '.terraform.lock.hcl' | xargs rm -vf

tools:
go install github.com/katbyte/terrafmt@latest

# Makefile targets are files, but we aren't using it like this,
# so have to declare PHONY targets
.PHONY: docs fmt fmtcheck tfclean tools
.PHONY: fmt fmtcheck
2 changes: 2 additions & 0 deletions alz/github/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ module "github" {
backend_azure_storage_account_name = local.resource_names.storage_account
backend_azure_storage_account_container_name = local.resource_names.storage_container
approvers = var.apply_approvers
create_team = var.apply_approval_team_creation_enabled
existing_team_name = var.apply_approval_existing_team_name
team_name = local.resource_names.version_control_system_team
runner_group_name = local.resource_names.version_control_system_runner_group
use_runner_group = local.use_runner_group
Expand Down
12 changes: 12 additions & 0 deletions alz/github/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ variable "apply_approvers" {
default = []
}

variable "apply_approval_team_creation_enabled" {
description = "Controls whether to create a team for approvals."
type = bool
default = true
}

variable "apply_approval_existing_team_name" {
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."
type = string
default = null
}

variable "create_branch_policies" {
description = "Controls whether to create branch policies for the repositories"
type = bool
Expand Down
4 changes: 2 additions & 2 deletions modules/github/environment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ resource "github_repository_environment" "alz" {
repository = github_repository.alz.name

dynamic "reviewers" {
for_each = each.key == local.apply_key && length(var.approvers) > 0 ? [1] : []
for_each = each.key == local.apply_key && local.approver_count > 0 ? [1] : []
content {
teams = [
github_team.alz.id
local.team_id
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/github/repository_module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ resource "github_branch_protection" "alz" {
required_pull_request_reviews {
dismiss_stale_reviews = true
restrict_dismissals = true
required_approving_review_count = length(var.approvers) > 1 ? 1 : 0
required_approving_review_count = local.approver_count > 1 ? 1 : 0
}
}
2 changes: 1 addition & 1 deletion modules/github/repository_templates.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "github_branch_protection" "alz_templates" {
required_pull_request_reviews {
dismiss_stale_reviews = true
restrict_dismissals = true
required_approving_review_count = length(var.approvers) > 1 ? 1 : 0
required_approving_review_count = local.approver_count > 1 ? 1 : 0
}
}

Expand Down
17 changes: 14 additions & 3 deletions modules/github/team.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ locals {
invalid_approvers = setunion(local.invalid_approvers_by_email, local.invalid_approvers_by_login)
}

locals {
team_id = var.create_team ? github_team.alz[0].id : var.existing_team_name == null ? null : data.github_team.alz[0].id
approver_count = var.create_team ? length(local.approvers) : var.existing_team_name == null ? 0 : (data.github_team.alz[0].members)
}

data "github_team" "alz" {
Comment thread
jaredfholgate marked this conversation as resolved.
count = var.create_team ? 0 : 1
slug = var.existing_team_name
}

resource "github_team" "alz" {
count = var.create_team ? 1 : 0
name = var.team_name
description = "Approvers for the Landing Zone Terraform Apply"
privacy = "closed"
Expand All @@ -34,14 +45,14 @@ resource "github_team" "alz" {
}

resource "github_team_membership" "alz" {
for_each = { for approver in local.approvers : approver.login => approver }
team_id = github_team.alz.id
for_each = var.create_team ? { for approver in local.approvers : approver.login => approver } : {}
team_id = local.team_id
username = each.value.login
role = "member"
}

resource "github_team_repository" "alz" {
team_id = github_team.alz.id
team_id = local.team_id
repository = github_repository.alz.name
permission = "push"
}
8 changes: 8 additions & 0 deletions modules/github/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ variable "approvers" {
type = list(string)
}

variable "create_team" {
type = bool
}

variable "existing_team_name" {
type = string
}

variable "team_name" {
type = string
}
Expand Down
Loading