Skip to content

Commit e0152b0

Browse files
author
rahul-infra
committed
feat!: Add multi account support for dns and kong modules
BREAKING CHANGE: Kong module now requires explicit provider aliases for cross-account DNS records.
1 parent 75b6c73 commit e0152b0

26 files changed

+490
-42
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Release Preview
2+
3+
on:
4+
workflow_call:
5+
6+
env:
7+
SEMANTIC_RELEASE_VERSION: '24.2.0'
8+
NODE_VERSION: '20.11.0'
9+
10+
jobs:
11+
preview:
12+
name: Preview Release
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
ref: ${{ github.event.pull_request.head.ref }}
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: ${{ env.NODE_VERSION }}
29+
30+
- name: Run semantic-release (dry-run)
31+
id: semantic
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GIT_COMMITTER_NAME: "github-actions[bot]"
35+
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
36+
GIT_AUTHOR_NAME: "github-actions[bot]"
37+
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
38+
run: |
39+
# Unset GitHub Actions environment variables that interfere with semantic-release
40+
unset GITHUB_REF
41+
unset GITHUB_REF_NAME
42+
unset GITHUB_HEAD_REF
43+
unset GITHUB_BASE_REF
44+
45+
# Set them to what we want
46+
export GITHUB_REF="refs/heads/${{ github.event.pull_request.head.ref }}"
47+
export GITHUB_REF_NAME="${{ github.event.pull_request.head.ref }}"
48+
49+
# Run semantic-release with inline configuration using CLI options
50+
OUTPUT=$(npx --package semantic-release@${{ env.SEMANTIC_RELEASE_VERSION }} \
51+
--package @semantic-release/exec \
52+
--package conventional-changelog-conventionalcommits \
53+
semantic-release \
54+
--dry-run \
55+
--no-ci \
56+
--debug \
57+
--branches ${{ github.event.pull_request.head.ref }} 2>&1 || true)
58+
echo "$OUTPUT"
59+
60+
# Extract version information
61+
NEW_VERSION=$(echo "$OUTPUT" | grep -Eo "The next release version is [0-9]+\.[0-9]+\.[0-9]+" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" || echo "")
62+
RELEASE_TYPE=$(echo "$OUTPUT" | grep -Eo "Analysis of [0-9]+ commits complete: [a-z]+ release" | grep -Eo "(major|minor|patch) release" | sed 's/ release//' || echo "")
63+
64+
# Extract release notes (everything after "Release note for version")
65+
RELEASE_NOTES=$(echo "$OUTPUT" | sed -n '/Release note for version/,$p' | tail -n +2 || echo "")
66+
67+
# Save to outputs
68+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
69+
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
70+
71+
# Save release notes for comment
72+
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
73+
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
74+
echo "EOF" >> $GITHUB_OUTPUT
75+
76+
- name: Display Preview
77+
run: |
78+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
79+
echo " RELEASE PREVIEW"
80+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
81+
echo ""
82+
if [ -n "${{ steps.semantic.outputs.new_version }}" ]; then
83+
echo "Version: v${{ steps.semantic.outputs.new_version }}"
84+
echo "Release Type: ${{ steps.semantic.outputs.release_type }}"
85+
echo "Status: Release will be published"
86+
else
87+
echo "Status: No release will be published"
88+
echo "Reason: No relevant changes detected"
89+
fi
90+
echo ""
91+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
92+
93+
- name: Comment on PR
94+
if: github.event_name == 'pull_request'
95+
uses: mshick/add-pr-comment@v2
96+
with:
97+
message-id: release-preview
98+
message: |
99+
## Release Preview
100+
101+
${{ steps.semantic.outputs.new_version && format('**Version:** `v{0}`
102+
**Release Type:** `{1}`
103+
**Status:** Release will be published when merged to main
104+
105+
---
106+
107+
### Release Notes
108+
109+
{2}
110+
111+
---
112+
113+
*This preview is generated by semantic-release dry-run mode*', steps.semantic.outputs.new_version, steps.semantic.outputs.release_type, steps.semantic.outputs.release_notes) || '**Status:** No release will be published
114+
**Reason:** No relevant changes detected
115+
116+
---
117+
118+
*This preview is generated by semantic-release dry-run mode*' }}

.github/workflows/terraform.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' }}
2525
uses: ./.github/workflows/pr-title.yaml
2626

27+
releasePreview:
28+
name: Release Preview
29+
uses: ./.github/workflows/release-preview.yaml
30+
permissions:
31+
contents: write
32+
pull-requests: write
33+
2734
preCommitCheck:
2835
name: Terraform Checks
2936
uses: ./.github/workflows/terraform-checks.yaml

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ repos:
2020
- '--args=--only=terraform_workspace_remote'
2121
- '--args=--only=terraform_unused_required_providers'
2222
- id: terraform_validate
23+
args:
24+
- --hook-config=--retry-once-with-cleanup=true
25+
files: ^examples/
2326
- repo: https://github.com/pre-commit/pre-commit-hooks
2427
rev: v6.0.0
2528
hooks:

examples/complete/.header.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ cpu_for_kong_task = 512
4040
memory_for_kong_task = 1024
4141
desired_count_for_kong_service = 2
4242
force_new_deployment = true
43+
postgres_engine_version = 16.3
44+
postgres_major_engine_version = 16
45+
route53_assume_role_arn = arn:aws:iam::aws-account-id:role/role-name
46+
region = us-east-1
4347
```
4448

4549
Place this `terraform.tfvars` file in the same directory as your Terraform configuration to automatically load these values. Adjust the values as needed to fit your specific environment and requirements.

examples/complete/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ cpu_for_kong_task = 512
4141
memory_for_kong_task = 1024
4242
desired_count_for_kong_service = 2
4343
force_new_deployment = true
44+
postgres_engine_version = 16.3
45+
postgres_major_engine_version = 16
46+
route53_assume_role_arn = arn:aws:iam::aws-account-id:role/role-name
47+
region = us-east-1
4448
```
4549

4650
Place this `terraform.tfvars` file in the same directory as your Terraform configuration to automatically load these values. Adjust the values as needed to fit your specific environment and requirements.
@@ -50,6 +54,7 @@ Place this `terraform.tfvars` file in the same directory as your Terraform confi
5054
| Name | Version |
5155
|------|---------|
5256
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.13.0 |
57+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
5358

5459
## Providers
5560

@@ -94,6 +99,8 @@ No resources.
9499
| <a name="input_public_subnet_ids"></a> [public\_subnet\_ids](#input\_public\_subnet\_ids) | List of public subnet IDs | `list(string)` | n/a | yes |
95100
| <a name="input_rds_db_tags"></a> [rds\_db\_tags](#input\_rds\_db\_tags) | List of tags | `map(string)` | n/a | yes |
96101
| <a name="input_rds_instance_class"></a> [rds\_instance\_class](#input\_rds\_instance\_class) | The instance class to use | `string` | n/a | yes |
102+
| <a name="input_region"></a> [region](#input\_region) | The AWS region | `string` | n/a | yes |
103+
| <a name="input_route53_assume_role_arn"></a> [route53\_assume\_role\_arn](#input\_route53\_assume\_role\_arn) | IAM role ARN for cross-account Route53 access. | `string` | n/a | yes |
97104
| <a name="input_ssl_policy"></a> [ssl\_policy](#input\_ssl\_policy) | (Optional) Name of the SSL Policy for the listener. | `string` | n/a | yes |
98105
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC | `string` | n/a | yes |
99106

examples/complete/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
provider "aws" {
6+
alias = "cross_account_provider"
7+
region = var.region
8+
assume_role {
9+
role_arn = var.route53_assume_role_arn
10+
}
11+
}
12+
13+
114
module "kong" {
215
source = "../../"
316

17+
providers = {
18+
aws = aws
19+
aws.cross_account_provider = aws.cross_account_provider
20+
}
21+
422
vpc_id = var.vpc_id
523
public_subnet_ids = var.public_subnet_ids
624
private_subnet_ids = var.private_subnet_ids
@@ -30,4 +48,5 @@ module "kong" {
3048
force_new_deployment = var.force_new_deployment
3149
postgres_engine_version = var.postgres_engine_version
3250
postgres_major_engine_version = var.postgres_major_engine_version
51+
route53_assume_role_arn = var.route53_assume_role_arn
3352
}

examples/complete/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ variable "postgres_major_engine_version" {
132132
description = "The major version of the Postgres engine"
133133
type = number
134134
}
135+
136+
variable "route53_assume_role_arn" {
137+
description = "IAM role ARN for cross-account Route53 access."
138+
type = string
139+
}
140+
141+
variable "region" {
142+
description = "The AWS region"
143+
type = string
144+
}

examples/complete/versions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
terraform {
22
required_version = ">= 1.13.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 6.0"
8+
}
9+
}
310
}

examples/cross-account/.header.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### Example Variable Values
2+
3+
Here is an example of how to define the variable values in your `terraform.tfvars` file:
4+
5+
```hcl
6+
vpc_id = "vpc-12345678"
7+
public_subnet_ids = ["subnet-abcdef01", "subnet-abcdef02"]
8+
private_subnet_ids = ["subnet-abcdef03", "subnet-abcdef04"]
9+
kong_public_domain_name = "api.example.com"
10+
kong_admin_domain_name = "admin-api.example.com"
11+
region = "us-east-1"
12+
route53_assume_role_arn = "arn:aws:iam::account-id:role/role-id"
13+
```
14+
15+
Place this `terraform.tfvars` file in the same directory as your Terraform configuration to automatically load these values. Adjust the values as needed to fit your specific environment and requirements.

examples/cross-account/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
### Example Variable Values
3+
4+
Here is an example of how to define the variable values in your `terraform.tfvars` file:
5+
6+
```hcl
7+
vpc_id = "vpc-12345678"
8+
public_subnet_ids = ["subnet-abcdef01", "subnet-abcdef02"]
9+
private_subnet_ids = ["subnet-abcdef03", "subnet-abcdef04"]
10+
kong_public_domain_name = "api.example.com"
11+
kong_admin_domain_name = "admin-api.example.com"
12+
region = "us-east-1"
13+
route53_assume_role_arn = "arn:aws:iam::account-id:role/role-id"
14+
```
15+
16+
Place this `terraform.tfvars` file in the same directory as your Terraform configuration to automatically load these values. Adjust the values as needed to fit your specific environment and requirements.
17+
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.13.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
24+
25+
## Providers
26+
27+
No providers.
28+
29+
## Modules
30+
31+
| Name | Source | Version |
32+
|------|--------|---------|
33+
| <a name="module_kong"></a> [kong](#module\_kong) | ../../ | n/a |
34+
35+
## Resources
36+
37+
No resources.
38+
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|------|---------|:--------:|
43+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the cluster | `string` | n/a | yes |
44+
| <a name="input_kong_admin_domain_name"></a> [kong\_admin\_domain\_name](#input\_kong\_admin\_domain\_name) | The admin domain name for Kong | `string` | n/a | yes |
45+
| <a name="input_kong_public_domain_name"></a> [kong\_public\_domain\_name](#input\_kong\_public\_domain\_name) | The public domain name for Kong | `string` | n/a | yes |
46+
| <a name="input_postgres_engine_version"></a> [postgres\_engine\_version](#input\_postgres\_engine\_version) | The version of the Postgres engine | `number` | n/a | yes |
47+
| <a name="input_postgres_major_engine_version"></a> [postgres\_major\_engine\_version](#input\_postgres\_major\_engine\_version) | The major version of the Postgres engine | `number` | n/a | yes |
48+
| <a name="input_private_subnet_ids"></a> [private\_subnet\_ids](#input\_private\_subnet\_ids) | List of private subnet IDs | `list(string)` | n/a | yes |
49+
| <a name="input_public_subnet_ids"></a> [public\_subnet\_ids](#input\_public\_subnet\_ids) | List of public subnet IDs | `list(string)` | n/a | yes |
50+
| <a name="input_region"></a> [region](#input\_region) | The AWS region | `string` | n/a | yes |
51+
| <a name="input_route53_assume_role_arn"></a> [route53\_assume\_role\_arn](#input\_route53\_assume\_role\_arn) | The ARN of the DNS role | `string` | `null` | no |
52+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC | `string` | n/a | yes |
53+
54+
## Outputs
55+
56+
No outputs.
57+
<!-- END_TF_DOCS -->

0 commit comments

Comments
 (0)