Skip to content

Commit 2e78792

Browse files
rahul-infrarahul-infragithub-actions[bot]
authored
feat!: Add multi account support for dns and kong modules
* feat!: Add multi account support for dns and kong modules BREAKING CHANGE: Kong module now requires explicit provider aliases for cross-account DNS records. * terraform-docs: automated action * ci: added statuses permission for pr title check in terraform yaml. --------- Co-authored-by: rahul-infra <rahul.sayam@infraspec.dev> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 75b6c73 commit 2e78792

27 files changed

+498
-46
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ permissions:
1717
contents: write
1818
pull-requests: write
1919
actions: read
20+
statuses: write
2021

2122
jobs:
2223
prTitlecheck:
2324
name: PR title check
2425
if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' }}
2526
uses: ./.github/workflows/pr-title.yaml
2627

28+
releasePreview:
29+
name: Release Preview
30+
uses: ./.github/workflows/release-preview.yaml
31+
permissions:
32+
contents: write
33+
pull-requests: write
34+
2735
preCommitCheck:
2836
name: Terraform Checks
2937
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:

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,26 @@ aws ssm put-parameter --name "/rds/POSTGRES_DB_NAME" --value "value" --type "Sec
2929
| Name | Version |
3030
|------|---------|
3131
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.13.0 |
32-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.5.0 |
32+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
3333

3434
## Providers
3535

3636
| Name | Version |
3737
|------|---------|
38-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.5.0 |
38+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
3939

4040
## Modules
4141

4242
| Name | Source | Version |
4343
|------|--------|---------|
44-
| <a name="module_ecs_kong"></a> [ecs\_kong](#module\_ecs\_kong) | infraspecdev/ecs-deployment/aws | ~> 4.3.4 |
44+
| <a name="module_ecs_kong"></a> [ecs\_kong](#module\_ecs\_kong) | infraspecdev/ecs-deployment/aws | ~> 5.0.0 |
4545
| <a name="module_ecs_task_security_group"></a> [ecs\_task\_security\_group](#module\_ecs\_task\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.3.0 |
46-
| <a name="module_internal_alb_kong"></a> [internal\_alb\_kong](#module\_internal\_alb\_kong) | infraspecdev/ecs-deployment/aws//modules/alb | ~> 4.3.4 |
46+
| <a name="module_internal_alb_kong"></a> [internal\_alb\_kong](#module\_internal\_alb\_kong) | infraspecdev/ecs-deployment/aws//modules/alb | ~> 5.0.0 |
4747
| <a name="module_internal_alb_security_group"></a> [internal\_alb\_security\_group](#module\_internal\_alb\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.3.0 |
4848
| <a name="module_kong_internal_dns_record"></a> [kong\_internal\_dns\_record](#module\_kong\_internal\_dns\_record) | ./modules/route-53-record | n/a |
49+
| <a name="module_kong_internal_dns_record_same_account"></a> [kong\_internal\_dns\_record\_same\_account](#module\_kong\_internal\_dns\_record\_same\_account) | ./modules/route-53-record | n/a |
4950
| <a name="module_kong_public_dns_record"></a> [kong\_public\_dns\_record](#module\_kong\_public\_dns\_record) | ./modules/route-53-record | n/a |
51+
| <a name="module_kong_public_dns_record_same_account"></a> [kong\_public\_dns\_record\_same\_account](#module\_kong\_public\_dns\_record\_same\_account) | ./modules/route-53-record | n/a |
5052
| <a name="module_kong_rds"></a> [kong\_rds](#module\_kong\_rds) | terraform-aws-modules/rds/aws | ~> 6.13.0 |
5153
| <a name="module_postgres_security_group"></a> [postgres\_security\_group](#module\_postgres\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.3.0 |
5254
| <a name="module_public_alb_security_group"></a> [public\_alb\_security\_group](#module\_public\_alb\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.3.0 |
@@ -92,6 +94,7 @@ aws ssm put-parameter --name "/rds/POSTGRES_DB_NAME" --value "value" --type "Sec
9294
| <a name="input_public_subnet_ids"></a> [public\_subnet\_ids](#input\_public\_subnet\_ids) | List of public subnet IDs for public-facing load balancers | `list(string)` | n/a | yes |
9395
| <a name="input_rds_db_tags"></a> [rds\_db\_tags](#input\_rds\_db\_tags) | List of tags | `map(string)` | `{}` | no |
9496
| <a name="input_rds_instance_class"></a> [rds\_instance\_class](#input\_rds\_instance\_class) | The RDS instance class for Kong database (e.g., db.t3.micro, db.r5.large) | `string` | `"db.t3.micro"` | no |
97+
| <a name="input_route53_assume_role_arn"></a> [route53\_assume\_role\_arn](#input\_route53\_assume\_role\_arn) | ARN of the IAM role to assume in the hosted-zone account (should be null for same-account). | `string` | `null` | no |
9598
| <a name="input_ssl_policy"></a> [ssl\_policy](#input\_ssl\_policy) | Name of the SSL Policy for the listener. | `string` | `"ELBSecurityPolicy-2016-08"` | no |
9699
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC where Kong infrastructure will be deployed | `string` | n/a | yes |
97100

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.

0 commit comments

Comments
 (0)