Skip to content

Commit 017e500

Browse files
author
rahul-infra
committed
feat: Introduce cross-account provider configuration allowing Route53 records to be managed in a separate AWS account from the Kong deployment.
1 parent 75b6c73 commit 017e500

25 files changed

+471
-42
lines changed

.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Terraform Module to setup Kong(OSS) in ECS with self managed EC2 instances.
99

1010
# Assumptions
1111

12-
This setup assumes that the `ECS cluster` that has `Auto Scaling Group (ASG)` exist with the name `default`. If you are using different name, you can provide those in the variables section of your Terraform configuration.
12+
This setup assumes that the `ECS cluster` that has `Auto Scaling Group (ASG)` exist with the name `default`. If you are using different name, you can provide those in the variables section of your Terraform configuration.This module also have a provision that your hosted zone can be in same amazon account where your resources are going to create or in a different amazon account. So, if you are having hosted zone in a different account you need to pass IAM role ARN for cross-account Route53 access.
1313

1414
## Adding Parameters to AWS Systems Manager Parameter Store
1515

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
<!-- BEGIN_TF_DOCS -->
2+
# Complete Example
3+
4+
This example demonstrates a **production-ready Kong deployment** with all configurable options, including RDS settings, ECS task configuration, monitoring, and cross-account Route53 support.
5+
6+
## Use Case
7+
8+
Use this example when you need:
9+
- Full control over RDS database configuration (instance class, storage, backup retention, multi-AZ, etc.)
10+
- Custom ECS task settings (CPU, memory, logging)
11+
- Performance insights and monitoring
12+
- Production-grade setup with deletion protection and backups
13+
- Flexible Route53 DNS configuration (same-account or cross-account)
14+
15+
## Key Features
16+
17+
- Comprehensive RDS PostgreSQL configuration with performance insights
18+
- Multi-AZ deployment support for high availability
19+
- Customizable ECS task resources and logging
20+
- SSL/TLS configuration with custom SSL policies
21+
- Cross-account Route53 support via assume role
22+
- Production backup and maintenance windows
23+
24+
## Usage
25+
226
### Example Variable Values
327

428
Here is an example of how to define the variable values in your `terraform.tfvars` file:

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-accout/.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-accout/README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
# Cross-Account Example
3+
4+
This example demonstrates Kong deployment with **Route53 hosted zone in a different AWS account** using cross-account IAM role assumption.
5+
6+
## Use Case
7+
8+
Use this example when:
9+
- Your Route53 hosted zone is managed in a separate AWS account (common in enterprise setups)
10+
- You have a centralized DNS management account
11+
- You need to manage DNS records across AWS accounts
12+
- You follow security best practices with separate accounts for different concerns
13+
14+
## Key Features
15+
16+
- Cross-account Route53 DNS record management
17+
- IAM role assumption for secure cross-account access
18+
- Separate provider configuration for DNS operations
19+
- Minimal configuration with module defaults for other resources
20+
- Secure cross-account permissions model
21+
22+
## Provider Configuration
23+
24+
This example uses two providers:
25+
1. **Default provider** - For Kong infrastructure (VPC, ECS, RDS, ALB)
26+
2. **Cross-account provider** - For Route53 DNS records in a different account
27+
28+
```hcl
29+
provider "aws" {
30+
alias = "cross_account_provider"
31+
region = var.region
32+
assume_role {
33+
role_arn = var.route53_assume_role_arn # IAM role in DNS account
34+
}
35+
}
36+
```
37+
38+
## Prerequisites
39+
40+
1. An IAM role must exist in the Route53 account that allows the Kong account to assume it
41+
2. The role should have permissions to manage Route53 records
42+
3. Example trust policy for the IAM role in the DNS account:
43+
44+
```json
45+
{
46+
"Version": "2012-10-17",
47+
"Statement": [
48+
{
49+
"Effect": "Allow",
50+
"Principal": {
51+
"AWS": "arn:aws:iam::KONG_ACCOUNT_ID:root"
52+
},
53+
"Action": "sts:AssumeRole"
54+
}
55+
]
56+
}
57+
```
58+
59+
## Usage
60+
61+
### Example Variable Values
62+
63+
Here is an example of how to define the variable values in your `terraform.tfvars` file:
64+
65+
```hcl
66+
vpc_id = "vpc-12345678"
67+
public_subnet_ids = ["subnet-abcdef01", "subnet-abcdef02"]
68+
private_subnet_ids = ["subnet-abcdef03", "subnet-abcdef04"]
69+
kong_public_domain_name = "api.example.com"
70+
kong_admin_domain_name = "admin-api.example.com"
71+
72+
# Cross-account Route53 IAM role (in the DNS account)
73+
route53_assume_role_arn = "arn:aws:iam::DNS_ACCOUNT_ID:role/route53-cross-account-role"
74+
75+
region = "ap-south-1"
76+
cluster_name = "default"
77+
```
78+
79+
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.
80+
81+
## Requirements
82+
83+
| Name | Version |
84+
|------|---------|
85+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.13.0 |
86+
87+
## Providers
88+
89+
No providers.
90+
91+
## Modules
92+
93+
| Name | Source | Version |
94+
|------|--------|---------|
95+
| <a name="module_kong"></a> [kong](#module\_kong) | ../../ | n/a |
96+
97+
## Resources
98+
99+
No resources.
100+
101+
## Inputs
102+
103+
| Name | Description | Type | Default | Required |
104+
|------|-------------|------|---------|:--------:|
105+
| <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 |
106+
| <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 |
107+
| <a name="input_private_subnet_ids"></a> [private\_subnet\_ids](#input\_private\_subnet\_ids) | List of private subnet IDs | `list(string)` | n/a | yes |
108+
| <a name="input_public_subnet_ids"></a> [public\_subnet\_ids](#input\_public\_subnet\_ids) | List of public subnet IDs | `list(string)` | n/a | yes |
109+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC | `string` | n/a | yes |
110+
111+
## Outputs
112+
113+
No outputs.
114+
<!-- END_TF_DOCS -->

examples/cross-accout/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
14+
module "kong" {
15+
source = "../../"
16+
17+
providers = {
18+
aws = aws
19+
aws.cross_account_provider = aws.cross_account_provider
20+
}
21+
22+
vpc_id = var.vpc_id
23+
public_subnet_ids = var.public_subnet_ids
24+
private_subnet_ids = var.private_subnet_ids
25+
kong_public_domain_name = var.kong_public_domain_name
26+
kong_admin_domain_name = var.kong_admin_domain_name
27+
cluster_name = var.cluster_name
28+
postgres_engine_version = var.postgres_engine_version
29+
postgres_major_engine_version = var.postgres_major_engine_version
30+
route53_assume_role_arn = var.route53_assume_role_arn
31+
}

0 commit comments

Comments
 (0)