Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions aws-ecsfargate-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,24 @@ locals {
}

data "aws_vpc" "this" {
# Use the default VPC or find the VPC by name if specified
default = var.vpc_name == "" ? true : false
tags = var.vpc_name != "" ? { Name = var.vpc_name } : {}
filter {
name = "tag:Name"
values = [var.vpc_name]
}
}

data "aws_subnet_ids" "public" {
vpc_id = data.aws_vpc.this.id
# Find the public subnets in the VPC
tags = var.vpc_name != "" ? { SubnetTier = "public" } : {}
data "aws_subnets" "public" {
filter {
name = "tag:Name"
values = var.public_subnet_names
}
}

data "aws_subnets" "private" {
filter {
name = "tag:Name"
values = var.private_subnet_names
}
}

data "aws_iam_policy_document" "assume_role_policy" {
Expand Down Expand Up @@ -177,7 +186,7 @@ resource "aws_ecs_service" "op_scim_bridge" {
}

network_configuration {
subnets = data.aws_subnet_ids.public.ids
subnets = data.aws_subnets.private.ids
assign_public_ip = true
security_groups = [aws_security_group.service.id]
}
Expand All @@ -190,7 +199,7 @@ resource "aws_ecs_service" "op_scim_bridge" {
resource "aws_alb" "op_scim_bridge" {
name = var.name_prefix == "" ? "op-scim-bridge-alb" : format("%s-%s", local.name_prefix, "alb")
load_balancer_type = "application"
subnets = data.aws_subnet_ids.public.ids
subnets = data.aws_subnets.public.ids
security_groups = [aws_security_group.alb.id]

tags = local.tags
Expand Down
10 changes: 10 additions & 0 deletions aws-ecsfargate-terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ variable "vpc_name" {
description = "The name of an existing VPC to use."
}

variable "public_subnet_names" {
type = list(string)
description = "The name of the public subnets to deploy ALB."
}

variable "private_subnet_names" {
type = list(string)
description = "The name of the private subnets to deploy ECS Fargate."
}

variable "wildcard_cert" {
type = bool
default = false
Expand Down