Skip to content

Commit c3df554

Browse files
committed
feat(merge queue): add merge queue based CI and address comments
1 parent be38f45 commit c3df554

File tree

9 files changed

+221
-412
lines changed

9 files changed

+221
-412
lines changed

.github/setup/aws/backend.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
backend "s3" {
33
bucket = "materialize-terraform-self-managed-state"
4-
key = "github-setup/oidc/terraform.tfstate"
4+
key = "github-setup/oidc/aws/terraform.tfstate"
55
region = "us-east-1"
66
encrypt = true
77
# profile = "" # Add your profile name here since backend block doesn't accept variables

.github/setup/azure/accessTokenLifeTime.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
#!/bin/bash
3+
4+
# Exit early on error/unset var/pipe failure
5+
set -euo pipefail
6+
17
# 1. Create a 4-hour token lifetime policy and capture the policy ID
28
POLICY_RESPONSE=$(az rest --method POST \
39
--url "https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies" \
@@ -21,4 +27,4 @@ az rest --method POST \
2127
--headers "Content-Type=application/json" \
2228
--body "{\"@odata.id\": \"https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies/${POLICY_ID}\"}"
2329

24-
echo "✅ Token lifetime policy applied successfully!"
30+
echo "✅ Token lifetime policy applied successfully!"

.github/setup/azure/main.tf

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ data "azuread_client_config" "current" {}
4949
# Get current subscription
5050
data "azurerm_client_config" "current" {}
5151

52+
# Get built-in role definitions for ABAC conditions
53+
data "azurerm_role_definition" "owner" {
54+
name = "Owner"
55+
scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
56+
}
57+
58+
data "azurerm_role_definition" "user_access_administrator" {
59+
name = "User Access Administrator"
60+
scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
61+
}
62+
63+
data "azurerm_role_definition" "rbac_administrator" {
64+
name = "Role Based Access Control Administrator"
65+
scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
66+
}
67+
5268

5369
# Principle of Least Privilege: Minimal role assignments based on fixture requirements
5470
# Refer roles from https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles to follow the principle of least privilege
@@ -155,25 +171,26 @@ resource "azurerm_role_assignment" "github_actions_rbac_admin" {
155171

156172
# ABAC condition to block assignment of high-privilege roles
157173
# Allows assignment of any role EXCEPT: Owner, User Access Administrator, RBAC Administrator
158-
# Role GUIDs: 8e3af657... (Owner), 18d7d88d... (User Access Admin), f58310d9... (RBAC Admin)
174+
# Using data sources to get role GUIDs dynamically instead of hardcoding
175+
# TODO: Test and validate this configuration, havent tested due to Perms issue.
159176
condition = <<-EOT
160177
(
161178
(!(ActionMatches{'Microsoft.Authorization/roleAssignments/write'}))
162179
OR
163180
(@Request[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAllValues:GuidNotEquals {
164-
8e3af657-a8ff-443c-a75c-2fe8c4bcb635,
165-
18d7d88d-d35e-4fb5-a5c3-7773c20a72d9,
166-
f58310d9-a9f6-439a-9e8d-f62e7b41a168
181+
${data.azurerm_role_definition.owner.id},
182+
${data.azurerm_role_definition.user_access_administrator.id},
183+
${data.azurerm_role_definition.rbac_administrator.id}
167184
})
168185
)
169186
AND
170187
(
171188
(!(ActionMatches{'Microsoft.Authorization/roleAssignments/delete'}))
172189
OR
173190
(@Resource[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAllValues:GuidNotEquals {
174-
8e3af657-a8ff-443c-a75c-2fe8c4bcb635,
175-
18d7d88d-d35e-4fb5-a5c3-7773c20a72d9,
176-
f58310d9-a9f6-439a-9e8d-f62e7b41a168
191+
${data.azurerm_role_definition.owner.id},
192+
${data.azurerm_role_definition.user_access_administrator.id},
193+
${data.azurerm_role_definition.rbac_administrator.id}
177194
})
178195
)
179196
EOT

.github/workflows/README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Infrastructure Testing Workflows
22

3-
## 🛡️ **Approval-Gated Testing**
3+
## 🛡️ **Merge Queue Integration**
44

5-
Infrastructure tests **require PR approval** to prevent accidental resource provisioning and manage costs.
5+
Infrastructure tests **integrate with GitHub's merge queue** to ensure only approved, tested code reaches `main`.
66

77
### **How It Works**
8-
1. **Create PR** → No tests run initially
9-
2. **Get approval** → Tests run automatically
10-
3. **Push changes** → Tests re-run automatically (if PR approved)
11-
4. **Manual trigger** → Use `gh workflow run test-<cloud>.yml` if needed
8+
1. **Create PR** → Request review
9+
2. **Get approval** → PR enters merge queue automatically
10+
3. **Tests run** → Only affected cloud providers tested (smart path filtering)
11+
4. **Auto-merge** → When tests pass, code merges to `main`
12+
5. **Manual trigger** → Use `gh workflow run test-<cloud>.yml` if needed
1213

1314

1415
### **What Gets Tested**
@@ -22,13 +23,19 @@ Infrastructure tests **require PR approval** to prevent accidental resource prov
2223

2324
### **Features**
2425
-**Granular path filtering** - Only tests infrastructure changes (excludes docs/README)
25-
-**Smart cloud detection** - Tests only affected clouds, or all clouds for shared changes
26-
-**Race condition prevention** - One workflow per PR
27-
-**Parallel cloud testing** - AWS/GCP/Azure run simultaneously
28-
-**Auto-retest** - New pushes trigger tests if PR approved
26+
-**Smart cloud detection** - Tests only affected clouds, or all clouds for shared changes
27+
-**Merge queue integration** - Automatic testing on approved PRs
28+
-**Conflict resolution** - Auto-retests when merge conflicts occur
29+
-**Parallel cloud testing** - AWS/GCP/Azure run simultaneously when needed
2930

3031
## **Setup Requirements**
3132

33+
**Branch Protection + Merge Queue:**
34+
- Enable merge queue for `main` branch
35+
- Require PR approvals (dismisses stale approvals)
36+
- Add required status checks: `AWS Tests`, `GCP Tests`, `Azure Tests`
37+
38+
3239
**Repository Secrets:**
3340
```
3441
MATERIALIZE_LICENSE_KEY
@@ -43,11 +50,14 @@ TF_TEST_S3_BUCKET, TF_TEST_S3_REGION, TF_TEST_S3_PREFIX
4350
GOOGLE_PROJECT, AWS_REGION
4451
```
4552

46-
## **Manual Override**
53+
## **Manual Testing**
4754

4855
```bash
49-
# Run tests without approval (requires repo access)
56+
# Run individual cloud tests manually (for debugging/testing)
5057
gh workflow run test-aws.yml --ref your-branch
5158
gh workflow run test-gcp.yml --ref your-branch
5259
gh workflow run test-azure.yml --ref your-branch
60+
61+
# Note: Manual runs bypass merge queue but still require proper authentication
62+
# Production merges should always go through the merge queue process
5363
```

.github/workflows/test-aws.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
name: AWS Tests
22

33
on:
4-
# Only run via approval workflow or manual trigger
5-
# Removed pull_request trigger to prevent duplicate runs
6-
workflow_call: # Called by test-on-approval.yml
4+
# Primary trigger: GitHub merge queue with smart path filtering
5+
merge_group:
6+
paths-ignore:
7+
# Exclude other cloud providers
8+
- "gcp/**"
9+
- "azure/**"
10+
- "test/gcp/**"
11+
- "test/azure/**"
12+
# Exclude setup files from other cloud providers
13+
- ".github/setup/gcp/**"
14+
- ".github/setup/azure/**"
15+
# Exclude examples
16+
- "aws/examples/**"
17+
# Exclude documentation and config
18+
- "**.md"
19+
- "**.env"
20+
- ".gitignore"
21+
- "LICENSE"
22+
# Exclude Azure/GCP specific workflows
23+
- ".github/workflows/test-gcp*.yml"
24+
- ".github/workflows/test-azure*.yml"
25+
- ".github/scripts/**"
26+
# Manual trigger: For testing and debugging purposes
727
workflow_dispatch:
828
inputs:
929
test_stage:
@@ -15,9 +35,9 @@ on:
1535
- network-only
1636
- full-test
1737

18-
# TODO: Add scheduled and PR triggers later
38+
# Future enhancement: Add scheduled runs for nightly testing
1939
# schedule:
20-
# - cron: '30 4 * * *' # 10 AM IST (4:30 AM UTC)
40+
# - cron: '30 4 * * *' # 10 AM IST (4:30 AM UTC) for nightly infrastructure validation
2141

2242
permissions:
2343
id-token: write # Required for OIDC
@@ -27,7 +47,8 @@ jobs:
2747
test-aws:
2848
name: AWS Infrastructure Tests
2949
runs-on: ubuntu-latest
30-
# Note: Approval-gated tests now handled by test-on-approval.yml workflow
50+
# Note: Triggered automatically when approved PRs enter GitHub's merge queue
51+
# Smart path filtering ensures tests run only when AWS infrastructure changes
3152

3253
steps:
3354
- name: Checkout code

0 commit comments

Comments
 (0)