Skip to content

Commit

Permalink
feat(aws-ecs): use tags to find subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-acosta committed Feb 28, 2024
1 parent f117ecd commit 57c3c8e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion create-an-aws-ecs-byoc-app/components/ecs-service/alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module "ingress" {

name = var.service_name
vpc_id = var.vpc_id
subnets = local.public_subnet_id_list
subnets = data.aws_subnets.public.ids
enable_deletion_protection = false

security_group_ingress_rules = {
Expand Down
13 changes: 13 additions & 0 deletions create-an-aws-ecs-byoc-app/components/ecs-service/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data "aws_subnets" "private" {
filter {
name = "visibility"
values = ["private"]
}
}

data "aws_subnets" "public" {
filter {
name = "visibility"
values = ["public"]
}
}
4 changes: 2 additions & 2 deletions create-an-aws-ecs-byoc-app/components/ecs-service/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "private_subnet_ids" {
value = local.private_subnet_id_list
value = data.aws_subnets.private.ids
}

output "public_subnet_ids" {
value = local.public_subnet_id_list
value = data.aws_subnets.public.ids
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module "service" {
}
}

subnet_ids = local.private_subnet_id_list
subnet_ids = data.aws_subnets.private.ids
security_group_rules = {
ingress_http = {
type = "ingress"
Expand Down
13 changes: 0 additions & 13 deletions create-an-aws-ecs-byoc-app/components/ecs-service/variables.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
locals {
private_subnet_id_list = split(" ", trim(var.private_subnet_ids, "[]"))
public_subnet_id_list = split(" ", trim(var.public_subnet_ids, "[]"))
}

# Service config

variable "service_name" {
Expand Down Expand Up @@ -39,14 +34,6 @@ variable "vpc_id" {
type = string
}

variable "private_subnet_ids" {
type = string
}

variable "public_subnet_ids" {
type = string
}

variable "domain_name" {
type = string
}
Expand Down

0 comments on commit 57c3c8e

Please sign in to comment.