Skip to content

Commit 6ab55b3

Browse files
vjdhamaclaude
andcommitted
feat: apply Terraform best practices improvements
- Fix output naming to follow {name}_{type}_{attribute} pattern - Use 'this' for generic data sources (aws_vpc, aws_ecs_cluster) - Improve variable descriptions with more context and specificity - Add nullable = false for required variables (vpc_id, subnet_ids) - Add validation rules for rds_instance_class and db_allocated_storage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 33ab039 commit 6ab55b3

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
data "aws_vpc" "vpc" {
1+
data "aws_vpc" "this" {
22
id = var.vpc_id
33
}
44

@@ -25,7 +25,7 @@ module "postgres_security_group" {
2525
from_port = 0
2626
to_port = local.rds.port
2727
protocol = "tcp"
28-
cidr_blocks = data.aws_vpc.vpc.cidr_block
28+
cidr_blocks = data.aws_vpc.this.cidr_block
2929
},
3030
]
3131
egress_with_cidr_blocks = [{
@@ -94,7 +94,7 @@ module "internal_alb_security_group" {
9494
from_port = 0
9595
to_port = 0
9696
protocol = "-1"
97-
cidr_blocks = data.aws_vpc.vpc.cidr_block
97+
cidr_blocks = data.aws_vpc.this.cidr_block
9898
}]
9999
egress_with_cidr_blocks = [{
100100
from_port = 0
@@ -152,7 +152,7 @@ module "ecs_task_security_group" {
152152
from_port = 0
153153
to_port = 0
154154
protocol = "-1"
155-
cidr_blocks = data.aws_vpc.vpc.cidr_block
155+
cidr_blocks = data.aws_vpc.this.cidr_block
156156
},
157157
]
158158
egress_with_cidr_blocks = [{
@@ -198,7 +198,7 @@ resource "aws_iam_role_policy_attachment" "ecs_exec" {
198198
# ECS Kong
199199
################################################################################
200200

201-
data "aws_ecs_cluster" "default" {
201+
data "aws_ecs_cluster" "this" {
202202
cluster_name = var.cluster_name
203203
}
204204

@@ -207,7 +207,7 @@ module "ecs_kong" {
207207
version = "~> 4.3.4"
208208

209209
vpc_id = var.vpc_id
210-
cluster_name = data.aws_ecs_cluster.default.cluster_name
210+
cluster_name = data.aws_ecs_cluster.this.cluster_name
211211

212212
service = {
213213
name = local.kong.service_name

outputs.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
output "rds_instance_endpoint" {
2-
description = "Endpoint of RDS instance"
1+
output "kong_rds_instance_endpoint" {
2+
description = "Endpoint of Kong RDS instance"
33
value = module.kong_rds.db_instance_endpoint
44
}
55

6-
output "ecs_service_arn" {
7-
description = "ARN of kong ECS service"
6+
output "kong_ecs_service_arn" {
7+
description = "ARN of Kong ECS service"
88
value = module.ecs_kong.ecs_service_arn
99
}
1010

11-
output "public_alb_dns" {
12-
description = "DNS name of public ALB"
11+
output "kong_public_alb_dns_name" {
12+
description = "DNS name of Kong public ALB"
1313
value = module.ecs_kong.alb_dns_name
1414
}
1515

16-
output "internal_alb_dns" {
17-
description = "DNS name of internal ALB"
16+
output "kong_internal_alb_dns_name" {
17+
description = "DNS name of Kong internal ALB"
1818
value = module.internal_alb_kong.arn
1919
}

variables.tf

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
variable "private_subnet_ids" {
2-
description = "List of private subnet id"
2+
description = "List of private subnet IDs for database and Kong ECS deployment"
33
type = list(string)
4+
nullable = false
45
}
56

67
variable "public_subnet_ids" {
7-
description = "List of public subnet id"
8+
description = "List of public subnet IDs for public-facing load balancers"
89
type = list(string)
10+
nullable = false
911
}
1012

1113
variable "vpc_id" {
12-
description = "The ID of the VPC"
14+
description = "The ID of the VPC where Kong infrastructure will be deployed"
1315
type = string
16+
nullable = false
1417
}
1518

1619
variable "rds_instance_class" {
17-
description = "The instance class to use"
20+
description = "The RDS instance class for Kong database (e.g., db.t3.micro, db.r5.large)"
1821
type = string
1922
default = "db.t3.micro"
23+
24+
validation {
25+
condition = can(regex("^db\\.", var.rds_instance_class))
26+
error_message = "RDS instance class must start with 'db.' (e.g., db.t3.micro, db.r5.large)."
27+
}
2028
}
2129

2230
variable "db_allocated_storage" {
23-
description = "The amount of allocated storage in GBs"
31+
description = "Initial allocated storage for Kong RDS instance in GBs"
2432
type = number
2533
default = 20
34+
35+
validation {
36+
condition = var.db_allocated_storage >= 20
37+
error_message = "Allocated storage must be at least 20 GBs for RDS instances."
38+
}
2639
}
2740

2841
variable "db_max_allocated_storage" {
@@ -50,7 +63,7 @@ variable "deletion_protection" {
5063
}
5164

5265
variable "create_db_subnet_group" {
53-
description = "Whether to create a DB subnet group"
66+
description = "Whether to create a DB subnet group for Kong RDS instance"
5467
type = bool
5568
default = true
5669
}
@@ -92,7 +105,7 @@ variable "maintenance_window" {
92105
}
93106

94107
variable "cluster_name" {
95-
description = "Name of the cluster"
108+
description = "Name of the ECS cluster where Kong will be deployed"
96109
type = string
97110
default = "default"
98111
}

0 commit comments

Comments
 (0)