Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump AWS provider and update examples to include ECS Service Connect config #238

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ Available targets:
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.59 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.49 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.59 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.49 |

## Modules

Expand Down
4 changes: 2 additions & 2 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.59 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.49 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.59 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.49 |

## Modules

Expand Down
4 changes: 4 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ container_environment = [

container_port_mappings = [
{
name = "http"
containerPort = 80
hostPort = 80
protocol = "tcp"
},
{
name = "https"
containerPort = 443
hostPort = 443
protocol = "udp"
Expand All @@ -80,3 +82,5 @@ container_port_mappings = [

force_new_deployment = true
redeploy_on_apply = true

service_connect_enabled = true
27 changes: 25 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module "container_definition" {
count = local.enabled ? 1 : 0

source = "cloudposse/ecs-container-definition/aws"
version = "0.58.2"
version = "0.61.1"

container_name = var.container_name
container_image = var.container_image
Expand Down Expand Up @@ -76,6 +76,12 @@ module "test_policy" {
context = module.this.context
}

resource "aws_service_discovery_http_namespace" "default" {
count = local.enabled && var.service_connect_enabled ? 1 : 0
name = module.this.id
tags = module.this.tags
}

module "ecs_alb_service_task" {
source = "../.."
alb_security_group = module.vpc.vpc_default_security_group_id
Expand All @@ -101,5 +107,22 @@ module "ecs_alb_service_task" {
task_policy_arns = [module.test_policy.policy_arn]
task_exec_policy_arns_map = { test = module.test_policy.policy_arn }

service_connect_configurations = [
{
enabled = local.enabled && var.service_connect_enabled
namespace = join("", aws_service_discovery_http_namespace.default[*].arn)
service = [{
client_alias = [{
dns_name = module.this.name
port = 80
}
]
discovery_name = module.this.name
port_name = var.container_port_mappings[0].name
}
]
}
]

context = module.this.context
}
}
11 changes: 11 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ variable "container_port_mappings" {
containerPort = number
hostPort = number
protocol = string
name = optional(string)
appProtocol = optional(string)
}))

description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort"
Expand Down Expand Up @@ -137,4 +139,13 @@ variable "redeploy_on_apply" {
type = bool
description = "Updates the service to the latest task definition on each apply"
default = false
}

variable "service_connect_enabled" {
type = bool
description = <<EOT
Enable ECS Service Connect, which allows this service to discover and connect to services,
and be discovered by, and connected from, other services within a namespace.
EOT
default = false
}
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.40"
version = ">= 5.49"
}
}
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1005,4 +1005,4 @@ resource "aws_ecs_service" "default" {
# See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service
depends_on = [aws_iam_role.ecs_service, aws_iam_role_policy.ecs_service]

}
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.59"
version = ">= 5.49"
}
}
}