Skip to content
Open
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
73 changes: 71 additions & 2 deletions terraform/github/branches.tf
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ resource "github_branch_protection" "openstack_branch_protection_caracal" {
}

resource "github_branch_protection" "openstack_branch_protection_epoxy" {
for_each = toset(var.repositories["OpenStack"])
for_each = toset([for r in var.repositories["OpenStack"] : r if !contains(var.repositories["ZuulOnly"], r)])

@coderabbitai coderabbitai Bot Sep 15, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Add state moves for the two neutron branch protections.

neutron moves between distinct Terraform resource addresses, and no migration declaration exists. Terraform will therefore plan destruction of the old instances and creation of the new instances. The old resources allow destruction, so the new resources’ prevent_destroy setting does not block this transition.

Proposed state moves
moved {
  from = github_branch_protection.openstack_branch_protection_epoxy["neutron"]
  to   = github_branch_protection.zuulonly_branch_protection_epoxy["neutron"]
}

moved {
  from = github_branch_protection.openstack_branch_protection_gazpacho["neutron"]
  to   = github_branch_protection.zuulonly_branch_protection_gazpacho["neutron"]
}

The plan should update the existing protections without destroy actions.

🧰 Tools
🪛 Checkov (3.3.13)

[low] 525-562: Ensure GitHub branch protection rules requires signed commits

(CKV_GIT_6)


[medium] 525-562: GitHub pull requests should require at least 2 approvals

(CKV_GIT_5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot has a point. We've had issues removing branch protection in the past. You'll either want to flex your admin powers and manually tweak some things, or find some way to do it in TF config

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use setsubtract to make it a bit more readable. I think this would do the same thing but is more clear imo

Suggested change
for_each = toset([for r in var.repositories["OpenStack"] : r if !contains(var.repositories["ZuulOnly"], r)])
for_each = setsubtract(toset(var.repositories["OpenStack"]), toset(var.repositories["ZuulOnly"]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alex-Welsh, correct. setsubtract produces the same repository set and makes the exclusion operation clearer.

for_each = setsubtract(
  toset(var.repositories["OpenStack"]),
  toset(var.repositories["ZuulOnly"]),
)

The expression also preserves the set type required by for_each.

You are interacting with an AI system.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this command on a human-authored review finding. CodeRabbit findings already use the standard resolution workflow.

repository_id = data.github_repository.repositories[each.key].node_id

pattern = "stackhpc/2025.1"
Expand Down Expand Up @@ -562,7 +562,7 @@ resource "github_branch_protection" "openstack_branch_protection_epoxy" {
}

resource "github_branch_protection" "openstack_branch_protection_gazpacho" {
for_each = toset(var.repositories["OpenStack"])
for_each = toset([for r in var.repositories["OpenStack"] : r if !contains(var.repositories["ZuulOnly"], r)])
repository_id = data.github_repository.repositories[each.key].node_id

pattern = "stackhpc/2026.1"
Expand Down Expand Up @@ -637,6 +637,75 @@ resource "github_branch_protection" "openstack_branch_protection_master" {
}
}

# ZuulOnly: push_allowances contains only the Zuul GitHub App, so PRs can only be
# merged by Zuul (typically after the "gate" label enqueues the change into its gate
# pipeline). Neither the Developers team nor the owning team can merge directly.
# Only the stackhpc/2025.1 and stackhpc/2026.1 branches are gated this way for now;
# neutron's other branches keep normal OpenStack-group protection (see openstack_branch_protection_*).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd remove the reference to neutron in this comment. It's a generic branch protection rule that we can (should) apply to more repos in the future.

resource "github_branch_protection" "zuulonly_branch_protection_epoxy" {
for_each = toset(var.repositories["ZuulOnly"])
repository_id = data.github_repository.repositories[each.key].node_id

pattern = "stackhpc/2025.1"
require_conversation_resolution = true
allows_deletions = false
allows_force_pushes = false

restrict_pushes {
blocks_creations = false
push_allowances = [
local.zuul_app_node_id
]
}

required_pull_request_reviews {
dismiss_stale_reviews = true
require_code_owner_reviews = true
required_approving_review_count = 1
}

required_status_checks {
contexts = ["stackhpc/check"]
strict = false
}

lifecycle {
prevent_destroy = true
}
}

resource "github_branch_protection" "zuulonly_branch_protection_gazpacho" {
for_each = toset(var.repositories["ZuulOnly"])
repository_id = data.github_repository.repositories[each.key].node_id

pattern = "stackhpc/2026.1"
require_conversation_resolution = true
allows_deletions = false
allows_force_pushes = false

restrict_pushes {
blocks_creations = false
push_allowances = [
local.zuul_app_node_id
]
}

required_pull_request_reviews {
dismiss_stale_reviews = true
require_code_owner_reviews = true
required_approving_review_count = 1
}

required_status_checks {
contexts = ["stackhpc/check"]
strict = false
}

lifecycle {
prevent_destroy = true
}
}

resource "github_branch_protection" "platform_branch_protection" {
for_each = toset(var.repositories["Platform"])
repository_id = data.github_repository.repositories[each.key].node_id
Expand Down
3 changes: 3 additions & 0 deletions terraform/github/terraform.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
"stackhpc-inspector-plugins"
],
"Platform": [],
"ZuulOnly": [
"neutron"
],
"ReleaseTrain": [
".github",
"ARC-Installer",
Expand Down
1 change: 1 addition & 0 deletions terraform/github/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ variable "repositories" {
"Platform" = [],
"ReleaseTrain" = [],
"SMSLab" = [],
"ZuulOnly" = [],
}
}

Expand Down