From a1f5e18c0c8992b511a6442a36485a833400ca58 Mon Sep 17 00:00:00 2001 From: Rak Siva Date: Thu, 2 Oct 2025 13:39:10 -0600 Subject: [PATCH] fix: ensure unique names for infrastructure resources resources updated - fargate, lambda, loadbalancer, vpc, cloudfront, security group relies on - https://github.com/nitrictech/suga/pull/103 which injects the stack_id --- cloudfront/module/main.tf | 2 +- fargate/module/main.tf | 2 +- lambda/module/main.tf | 2 +- loadbalancer/module/main.tf | 2 +- loadbalancer/module/variables.tf | 12 +++++++++--- sgrule/module/variables.tf | 6 ++++++ vpc/module/main.tf | 2 +- vpc/module/variables.tf | 7 +++++++ 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cloudfront/module/main.tf b/cloudfront/module/main.tf index 333f8c7..15850dd 100644 --- a/cloudfront/module/main.tf +++ b/cloudfront/module/main.tf @@ -332,7 +332,7 @@ resource "aws_acm_certificate" "cloudfront_cert" { resource "aws_cloudfront_cache_policy" "default_cache_policy" { count = var.default_cache_policy_id == null ? 1 : 0 - name = "SugaDefaultCachePolicy" + name = "${var.suga.stack_id}-SugaDefaultCachePolicy" comment = "Default cache policy for CloudFront distribution for Suga Applications" # Set TTL defaults to respect cache control headers diff --git a/fargate/module/main.tf b/fargate/module/main.tf index dbfcfcb..60b1342 100644 --- a/fargate/module/main.tf +++ b/fargate/module/main.tf @@ -1,6 +1,6 @@ # Create an ECR repository resource "aws_ecr_repository" "repo" { - name = var.suga.name + name = "${var.suga.stack_id}-${var.suga.name}" } data "aws_ecr_authorization_token" "ecr_auth" { diff --git a/lambda/module/main.tf b/lambda/module/main.tf index f181910..a43d21f 100644 --- a/lambda/module/main.tf +++ b/lambda/module/main.tf @@ -29,7 +29,7 @@ locals { # Create an ECR repository resource "aws_ecr_repository" "repo" { - name = var.suga.name + name = "${var.suga.stack_id}-${var.suga.name}" image_scanning_configuration { scan_on_push = var.image_scan_on_push } diff --git a/loadbalancer/module/main.tf b/loadbalancer/module/main.tf index 104554c..c6ba582 100644 --- a/loadbalancer/module/main.tf +++ b/loadbalancer/module/main.tf @@ -1,5 +1,5 @@ resource "aws_lb" "lb" { - name = var.name + name = "${var.suga.stack_id}-${var.name}" internal = var.internal load_balancer_type = var.load_balancer_type security_groups = var.security_groups diff --git a/loadbalancer/module/variables.tf b/loadbalancer/module/variables.tf index 48a4ead..1515914 100644 --- a/loadbalancer/module/variables.tf +++ b/loadbalancer/module/variables.tf @@ -1,12 +1,18 @@ -variable "load_balancer_type" { - type = string - default = "application" +variable "suga" { + type = object({ + stack_id = string + }) } variable "name" { type = string } +variable "load_balancer_type" { + type = string + default = "application" +} + variable "listener_port" { type = number default = 80 diff --git a/sgrule/module/variables.tf b/sgrule/module/variables.tf index 60eab11..7f7a31e 100644 --- a/sgrule/module/variables.tf +++ b/sgrule/module/variables.tf @@ -1,3 +1,9 @@ +variable "suga" { + type = object({ + stack_id = string + }) +} + variable "security_group_ids" { type = list(string) description = "List of security group IDs to which the rule will be applied" diff --git a/vpc/module/main.tf b/vpc/module/main.tf index 39fd568..44bd3e1 100644 --- a/vpc/module/main.tf +++ b/vpc/module/main.tf @@ -10,7 +10,7 @@ locals { module "vpc" { source = "terraform-aws-modules/vpc/aws" - name = var.name + name = "${var.suga.stack_id}-${var.name}" cidr = var.networking.cidr_block azs = local.azs diff --git a/vpc/module/variables.tf b/vpc/module/variables.tf index 169f847..9395e97 100644 --- a/vpc/module/variables.tf +++ b/vpc/module/variables.tf @@ -1,7 +1,14 @@ +variable "suga" { + type = object({ + stack_id = string + }) +} + variable "name" { type = string description = "The name of the VPC" } + variable "networking" { type = object({ cidr_block = string