From 96201b1e17fe117c6f51f6f77de846e81495e0d4 Mon Sep 17 00:00:00 2001 From: AgusPk Date: Thu, 12 Oct 2023 11:36:31 -0300 Subject: [PATCH 1/4] added vpc endpoint to access secrets manager --- live/core/vpc.tf | 1 + modules/vpc/endpoints.tf | 8 ++++++++ modules/vpc/variables.tf | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 modules/vpc/endpoints.tf diff --git a/live/core/vpc.tf b/live/core/vpc.tf index ae45af9..8ebefaa 100644 --- a/live/core/vpc.tf +++ b/live/core/vpc.tf @@ -11,6 +11,7 @@ module "vpc" { tags = module.label.tags enable_nat_gateway = true single_nat_gateway = true + region = var.region } output "ssm_parameter_vpc_id" { diff --git a/modules/vpc/endpoints.tf b/modules/vpc/endpoints.tf new file mode 100644 index 0000000..144821f --- /dev/null +++ b/modules/vpc/endpoints.tf @@ -0,0 +1,8 @@ +resource "aws_vpc_endpoint" "secrets_manager" { + vpc_id = module.vpc.vpc_id + + service_name = "com.amazonaws.${var.region}.secretsmanager" + + security_group_ids = [module.app_security_group.security_group_id] # You can specify security groups if needed + subnet_ids = module.vpc.private_subnets # Associate with private subnets +} diff --git a/modules/vpc/variables.tf b/modules/vpc/variables.tf index 13496b0..05bb2dc 100644 --- a/modules/vpc/variables.tf +++ b/modules/vpc/variables.tf @@ -33,3 +33,9 @@ variable "tags" { type = map(any) default = {} } + +variable "region" { + description = "AWS region" + type = string + default = "us-west-2" +} From 2bd772aa886691313a878cafe9d18dff3f7565d0 Mon Sep 17 00:00:00 2001 From: AgusPk Date: Thu, 12 Oct 2023 11:43:33 -0300 Subject: [PATCH 2/4] fix linting --- live/core/vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live/core/vpc.tf b/live/core/vpc.tf index 8ebefaa..57a57b3 100644 --- a/live/core/vpc.tf +++ b/live/core/vpc.tf @@ -11,7 +11,7 @@ module "vpc" { tags = module.label.tags enable_nat_gateway = true single_nat_gateway = true - region = var.region + region = var.region } output "ssm_parameter_vpc_id" { From 8ffd97fc0ff87573cb0a0c9159d378e13652c7e1 Mon Sep 17 00:00:00 2001 From: AgusPk Date: Thu, 12 Oct 2023 12:39:34 -0300 Subject: [PATCH 3/4] changed region usage --- live/core/vpc.tf | 1 - modules/vpc/endpoints.tf | 4 +++- modules/vpc/variables.tf | 6 ------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/live/core/vpc.tf b/live/core/vpc.tf index 57a57b3..ae45af9 100644 --- a/live/core/vpc.tf +++ b/live/core/vpc.tf @@ -11,7 +11,6 @@ module "vpc" { tags = module.label.tags enable_nat_gateway = true single_nat_gateway = true - region = var.region } output "ssm_parameter_vpc_id" { diff --git a/modules/vpc/endpoints.tf b/modules/vpc/endpoints.tf index 144821f..b48d980 100644 --- a/modules/vpc/endpoints.tf +++ b/modules/vpc/endpoints.tf @@ -1,7 +1,9 @@ +data "aws_region" "current" {} + resource "aws_vpc_endpoint" "secrets_manager" { vpc_id = module.vpc.vpc_id - service_name = "com.amazonaws.${var.region}.secretsmanager" + service_name = "com.amazonaws.${data.aws_region.current.name}.secretsmanager" security_group_ids = [module.app_security_group.security_group_id] # You can specify security groups if needed subnet_ids = module.vpc.private_subnets # Associate with private subnets diff --git a/modules/vpc/variables.tf b/modules/vpc/variables.tf index 05bb2dc..13496b0 100644 --- a/modules/vpc/variables.tf +++ b/modules/vpc/variables.tf @@ -33,9 +33,3 @@ variable "tags" { type = map(any) default = {} } - -variable "region" { - description = "AWS region" - type = string - default = "us-west-2" -} From ee8855512bdb33206db48019b57bf26849dea0b0 Mon Sep 17 00:00:00 2001 From: AgusPk Date: Thu, 12 Oct 2023 13:24:52 -0300 Subject: [PATCH 4/4] fix lint --- modules/vpc/endpoints.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/vpc/endpoints.tf b/modules/vpc/endpoints.tf index b48d980..7c394a9 100644 --- a/modules/vpc/endpoints.tf +++ b/modules/vpc/endpoints.tf @@ -5,6 +5,6 @@ resource "aws_vpc_endpoint" "secrets_manager" { service_name = "com.amazonaws.${data.aws_region.current.name}.secretsmanager" - security_group_ids = [module.app_security_group.security_group_id] # You can specify security groups if needed - subnet_ids = module.vpc.private_subnets # Associate with private subnets + security_group_ids = [module.app_security_group.security_group_id] # You can specify security groups if needed + subnet_ids = module.vpc.private_subnets # Associate with private subnets }