Giter Club home page Giter Club logo

terraform-aws-ecs-fargate's Introduction

GitHub release (latest by date)

Terraform AWS ECS Fargate

Terraform module to create AWS ECS FARGATE services. Module supports both FARGATE and FARGATE-SPOT capacity provider settings.

Terraform versions

Terraform 1.0.11. Pin module version to ~> v6.0. Submit pull-requests to master branch.

Usage

ECS Fargate Service

resource "aws_ecs_cluster" "cluster" {
  name = "example-ecs-cluster"

  setting {
    name  = "containerInsights"
    value = "disabled"
  }
}

resource "aws_ecs_cluster_capacity_providers" "cluster" {
  cluster_name = aws_ecs_cluster.cluster.name

  capacity_providers = ["FARGATE_SPOT", "FARGATE"]

  default_capacity_provider_strategy {
    capacity_provider = "FARGATE_SPOT"
  }
}

module "ecs-fargate" {
  source = "umotif-public/ecs-fargate/aws"
  version = "~> 6.1.0"

  name_prefix        = "ecs-fargate-example"
  vpc_id             = "vpc-abasdasd132"
  private_subnet_ids = ["subnet-abasdasd132123", "subnet-abasdasd132123132"]

  cluster_id         = aws_ecs_cluster.cluster.id

  task_container_image   = "marcincuber/2048-game:latest"
  task_definition_cpu    = 256
  task_definition_memory = 512

  task_container_port             = 80
  task_container_assign_public_ip = true

  target_groups = [
    {
      target_group_name = "tg-fargate-example"
      container_port    = 80
    }
  ]

  health_check = {
    port = "traffic-port"
    path = "/"
  }

  tags = {
    Environment = "test"
    Project = "Test"
  }
}

Examples

Authors

Module managed by uMotif.

Requirements

Name Version
terraform >= 1.0.11
aws >= 4.6.0

Providers

Name Version
aws >= 4.6.0

Modules

No modules.

Resources

Name Type
aws_cloudwatch_log_group.main resource
aws_ecs_service.service resource
aws_ecs_task_definition.task resource
aws_iam_role.execution resource
aws_iam_role.task resource
aws_iam_role_policy.ecs_exec_inline_policy resource
aws_iam_role_policy.get_environment_files resource
aws_iam_role_policy.log_agent resource
aws_iam_role_policy.read_repository_credentials resource
aws_iam_role_policy.task_execution resource
aws_lb_target_group.task resource
aws_security_group.ecs_service resource
aws_security_group_rule.egress_service resource
aws_ecs_task_definition.task data source
aws_iam_policy_document.get_environment_files data source
aws_iam_policy_document.read_repository_credentials data source
aws_iam_policy_document.task_assume data source
aws_iam_policy_document.task_ecs_exec_policy data source
aws_iam_policy_document.task_execution_permissions data source
aws_iam_policy_document.task_permissions data source
aws_kms_key.secretsmanager_key data source
aws_region.current data source

Inputs

Name Description Type Default Required
capacity_provider_strategy (Optional) The capacity_provider_strategy configuration block. This is a list of maps, where each map should contain "capacity_provider ", "weight" and "base" list(any) [] no
cluster_id The Amazon Resource Name (ARN) that identifies the cluster. string n/a yes
container_definitions A string containing json encoded array of container definitions for Task Definition string null no
container_name Optional name for the container to be used instead of name_prefix. string "" no
cpu_architecture cpu architecture for the task string "X86_64" no
create_repository_credentials_iam_policy Set to true if you are specifying repository_credentials variable, it will attach IAM policy with necessary permissions to task role. bool false no
deny_egress_to_anywhere When this parameter is true, no default egress rule will be created bool false no
deployment_controller_type Type of deployment controller. Valid values: CODE_DEPLOY, ECS, EXTERNAL. Default: ECS. string "ECS" no
deployment_maximum_percent The upper limit of the number of running tasks that can be running in a service during a deployment number 200 no
deployment_minimum_healthy_percent The lower limit of the number of running tasks that must remain running and healthy in a service during a deployment number 50 no
desired_count The number of instances of the task definitions to place and keep running. number 1 no
enable_deployment_circuit_breaker Whether to enable the deployment circuit breaker logic for the service. bool "false" no
enable_deployment_circuit_breaker_rollback Whether to enable Amazon ECS to roll back the service if a service deployment fails. If rollback is enabled, when a service deployment fails, the service is rolled back to the last deployment that completed successfully. bool "false" no
enable_ecs_managed_tags Specifies whether to enable Amazon ECS managed tags for the tasks within the service bool true no
enable_execute_command Specifies whether to enable Amazon ECS Exec for the tasks within the service. bool true no
enable_logs Turn cloudwatch logging optional bool true no
force_new_deployment Enable to force a new task deployment of the service. This can be used to update tasks to use a newer Docker image with same image/tag combination (e.g. myimage:latest), roll Fargate tasks onto a newer platform version. bool false no
health_check A health block containing health check settings for the target group. Overrides the defaults. map(string) {} no
health_check_grace_period_seconds Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers. number 300 no
load_balanced Whether the task should be loadbalanced. bool true no
log_groups_arn List of CloudWatch Group ARNs to use when enable_logs is set to false list(string) [] no
log_retention_in_days Number of days the logs will be retained in CloudWatch. number 30 no
logs_kms_key The KMS key ARN to use to encrypt container logs. string "" no
name_prefix A prefix used for naming resources. string n/a yes
operating_system_family The operating system family for the task. string "LINUX" no
placement_constraints (Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain "type" and "expression" list(any) [] no
platform_version The platform version on which to run your service. Only applicable for launch_type set to FARGATE. string "LATEST" no
private_subnet_ids A list of private subnets inside the VPC list(string) n/a yes
propagate_tags Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. string "TASK_DEFINITION" no
proxy_configuration (Optional) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain "container_name", "properties" and "type" list(any) [] no
readonlyRootFilesystem When this parameter is true, the container is given read-only access to its root file system bool false no
repository_credentials name or ARN of a secrets manager secret (arn:aws:secretsmanager:region:aws_account_id:secret:secret_name) string "" no
repository_credentials_kms_key key id, key ARN, alias name or alias ARN of the key that encrypted the repository credentials string "alias/aws/secretsmanager" no
service_registry_arn ARN of aws_service_discovery_service resource string "" no
sg_name_prefix A prefix used for Security group name. string "" no
tags A map of tags (key-value pairs) passed to resources. map(string) {} no
target_groups The name of the target groups to associate with ecs service any [] no
task_container_assign_public_ip Assigned public IP to the container. bool false no
task_container_command The command that is passed to the container. list(string) [] no
task_container_cpu Amount of CPU to reserve for the container. number null no
task_container_entrypoint The entrypoint that is passed to the container. list(string) [] no
task_container_environment The environment variables to pass to a container. map(string) {} no
task_container_environment_files The environment variable files (s3 object arns) to pass to a container. Files must use .env file extension. list(string) [] no
task_container_image The image used to start a container. string "marcincuber/2048-game:latest" no
task_container_memory The hard limit (in MiB) of memory for the container. number null no
task_container_memory_reservation The soft limit (in MiB) of memory to reserve for the container. number null no
task_container_port The port number on the container that is bound to the user-specified or automatically assigned host port number 80 no
task_container_protocol Protocol that the container exposes. string "HTTP" no
task_container_secrets The secrets variables to pass to a container. list(map(string)) null no
task_container_working_directory The working directory to run commands inside the container. string "" no
task_definition_cpu Amount of CPU to reserve for the task. number 256 no
task_definition_ephemeral_storage The total amount, in GiB, of ephemeral storage to set for the task. number 0 no
task_definition_memory The soft limit (in MiB) of memory to reserve for the task. number 512 no
task_health_check An optional healthcheck definition for the task map(number) null no
task_health_command A string array representing the command that the container runs to determine if it is healthy. list(string) null no
task_host_port The port number on the container instance to reserve for your container. number 80 no
task_mount_points The mount points for data volumes in your container. Each object inside the list requires "sourceVolume", "containerPath" and "readOnly". For more information see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html list(object({ sourceVolume = string, containerPath = string, readOnly = bool })) null no
task_pseudo_terminal Allocate TTY in the container bool null no
task_start_timeout Time duration (in seconds) to wait before giving up on resolving dependencies for a container. If this parameter is not specified, the default value of 3 minutes is used (fargate). number null no
task_stop_timeout Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own. The max stop timeout value is 120 seconds and if the parameter is not specified, the default value of 30 seconds is used. number null no
volume (Optional) A set of volume blocks that containers in your task may use. This is a list of maps, where each map should contain "name", "host_path", "docker_volume_configuration" and "efs_volume_configuration". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html list(any) [] no
vpc_id The VPC ID. string n/a yes
wait_for_steady_state If true, Terraform will wait for the service to reach a steady state (like aws ecs wait services-stable) before continuing. bool false no

Outputs

Name Description
execution_role_arn The Amazon Resource Name (ARN) specifying the ECS execution role.
execution_role_name The name of the ECS execution role.
log_group_name The name of the Cloudwatch log group for the task.
service_arn The Amazon Resource Name (ARN) that identifies the ECS service.
service_name The name of the service.
service_sg_id The Amazon Resource Name (ARN) that identifies the service security group.
target_group_arn The ARN of the Target Group used by Load Balancer.
target_group_name The Name of the Target Group used by Load Balancer.
task_definition_arn The Amazon Resource Name (ARN) of the task definition created
task_definition_container_definitions A list of container definitions
task_definition_name The name of the task definition created
task_role_arn The Amazon Resource Name (ARN) specifying the ECS service role.
task_role_name The name of the Fargate task service role.

License

See LICENSE for full details.

Pre-commit hooks

Install dependencies

MacOS

brew install pre-commit terraform-docs tflint

brew tap git-chglog/git-chglog
brew install git-chglog

terraform-aws-ecs-fargate's People

Contributors

ericduvic avatar fdgonzalez avatar ghaddow avatar mandrean avatar maordavidov avatar marcincuber avatar mrhassanmurtaza avatar networkprogrammer avatar ohid25 avatar pabloandres13 avatar paulopontesm avatar rafaljanicki avatar sherdycoder avatar stackexpress-tanmaya avatar vladdy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terraform-aws-ecs-fargate's Issues

Secret support does not work with Fargate 1.4.0

What is the current behavior?

Tasks cannot start due to this error:

ResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve secrets from ssm: service call has been retried 5 time(s): RequestCanceled: request context canceled caused by: context deadli...

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

  • I created a VPN, load balancer, and SSM secret
  • I configured a minimal instance of this module including task_container_secrets
  • I attached an existing working policy to the IAM roles to allow access SSM secrets

I discovered this stackoverflow post, which suggests the issue may be due to a change in network interface configuration as of Fargate 1.4.0.

I attemted to debug the issue based on information in that thread with no luck.

What is the expected behavior?

Fargate tasks able to access SSM secrets

Software versions?

Module version: 6.4.1

➜ terraform --version
Terraform v1.0.10
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.70.0

Add support for sidecar containers

What is the current behavior?

Currently, this Terraform module only supports one single container to be added to the container_definitions
https://github.com/umotif-public/terraform-aws-ecs-fargate/blob/6.7.0/main.tf#L184

What is the expected behavior?

It would be useful being able to specify sidecars.

Some references:

Custom security groups for Service

Is it possible with the current version of code to pass custom security group(s) for ECS Fargate service ? If not could you take this as a feature request.

Support multiple container ports

What is the current behavior?
The portMapping list of the task definition only lists 1 port as defined in task_container_port. Since target-group lists container_port, that value should be used to populate portMapping

Terraform fails when trying to map TG container port to a non-existent portMapping

 Error: failed creating ECS service (ecs-fargate-example): InvalidParameterException: The container ecs-fargate-example did not have a container port 5672 defined.
│ 
│   with module.fargate.aws_ecs_service.service,
│   on .terraform/modules/fargate/main.tf line 295, in resource "aws_ecs_service" "service":
│  295: resource "aws_ecs_service" "service" {

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Example code
https://gist.github.com/networkprogrammer/3c64d16d379098260309fea2e8aa7af4

What is the expected behavior?
Ideally, the container port should be picked from the tg's container port. That way AWS does not complain about port mapping not existing

Details
I have an nginx container listening on multiple ports. With task_container_port being used to populate port-mapping, I have to run multiple instances of the same container with task_container_port set to different ports, although they do the same thing.

Software versions?
Terraform v1.1.6
on linux_amd64

  • provider registry.terraform.io/hashicorp/aws v4.5.0
  • provider registry.terraform.io/hashicorp/random v3.1.1

umotif-public/ecs-fargate/aws: 6.4.2
umotif-public/alb/aws: 2.X

ELB is not getting created in Terraform 0.14 and 1.0.1

My Terraform Template:

# Configure the AWS Provider
provider "aws" {
  region = "us-east-2"
}

variable "subnets" {
  type    = list(string)
  default = ["subnet-00xxxxxxxxx", "subnet-0xxxxxxxxxx"]
}

variable "sg" {
  type    = string
  default = "sg-0xxxxxxxxxxxxx"
}

resource "aws_ecs_cluster" "cluster" {
  name = "example-ecs-cluster"

  capacity_providers = ["FARGATE_SPOT", "FARGATE"]

  default_capacity_provider_strategy {
    capacity_provider = "FARGATE_SPOT"
  }

  setting {
    name  = "containerInsights"
    value = "disabled"
  }
}


module "ecs-fargate" {
  source = "umotif-public/ecs-fargate/aws"
  version = "6.2.0"

  name_prefix        = "ecs-fargate-example"
  vpc_id             = "vpc-0exxxxxxxxx"
  private_subnet_ids = var.subnets

  cluster_id         = aws_ecs_cluster.cluster.id

  task_container_image   = "marcincuber/2048-game:latest"
  task_definition_cpu    = 256
  task_definition_memory = 512

  task_container_port             = 80
  task_container_assign_public_ip = true

  target_groups = [
    {
      target_group_name = "tg-fargate-example"
      container_port    = 80
    }
  ]

  health_check = {
    port = "traffic-port"
    path = "/"
  }

  tags = {
    Environment = "test"
    Project = "Test"
  }
}

The Error I get after terraform apply.

Error: error creating ecs-fargate-example service: InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-2:213128371923:targetgroup/tg-fargate-example/bxxxxxxxxdb does not have an associated load balancer.

  on .terraform/modules/ecs-fargate/main.tf line 284, in resource "aws_ecs_service" "service":
 284: resource "aws_ecs_service" "service" {

Tried on Terraform 0.14 and 1.0.1.

AWS fargate deployment failing with ALB resource, Does this module depend on ALB to be created?

This is a bug tracker, not a support system. For usage questions, please use Stack Overflow where there are a lot more people ready to help you out.
I have followed through the example in the https://github.com/umotif-public/terraform-aws-ecs-fargate and updated the VPCid, subnets and getting the following error regarding the ALB. Does this module depend on ALB? any suggestions how to fix this error. thx
Error: error creating ECS service (ecs-fargate-example): InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:227073609655:targetgroup/tg-fargate-example/164c8cb0a9a46e4d does not have an associated load balancer.

│ with module.ecs-fargate.aws_ecs_service.service,
│ on .terraform\modules\ecs-fargate\main.tf line 279, in resource "aws_ecs_service" "service":
│ 279: resource "aws_ecs_service" "service" {

Error upgrading to v6.x

What is the current behavior?
I followed the instructions in the release notes for v6.0.0 to upgrade from 5.1.0 → 6.2.0 and ran into an issue. See below:

│ Error: Invalid index
│
│   on .terraform/modules/fargate/fargate/main.tf line 156, in resource "aws_lb_listener" "alb_listener":
│  156:     target_group_arn = module.fargate.target_group_arn[0]
│     ├────────────────
│     │ module.fargate.target_group_arn is empty tuple
│
│ The given key does not identify an element in this collection value.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

  • Removed lb_arn
  • Updated target_group_arn = module.fargate.target_group_arn[0]

Terraform reported this as if it was a static failure, so I wasn't really able to debug it much further.

What is the expected behavior?
Expected following the upgrade guide would succeed.

Software versions?

$ terraform -v
Terraform v0.15.5
on darwin_arm64

Using variables in target-group name terraform asks to use -target based plan

What is the current behavior?
When terraform tries to plan/apply, it errors out saying for_each needs to know the number of instances needed. See error below

Error: Invalid for_each argument
│ 
│   on .terraform/modules/fargate.fargate5672/main.tf line 96, in resource "aws_lb_target_group" "task":
│   96:   for_each = var.load_balanced ? { for tg in var.target_groups : tg.target_group_name => tg } : {}
│     ├────────────────
│     │ var.load_balanced is true
│     │ var.target_groups is tuple with 1 element
│ 
│ The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to
│ first apply only the resources that the for_each depends on.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
This module will work


module "fargate80" {
  source  = "umotif-public/ecs-fargate/aws"
  version = "6.4.2"
  name_prefix = "${var.name}-80"
  desired_count = 2
  # sg_name_prefix     = "my-security-group-name" # uncomment if you want to name security group with specific name

  vpc_id             = var.vpc_id
  private_subnet_ids = var.private_subnet_ids
  cluster_id         = aws_ecs_cluster.cluster.id
#   task_container_assign_public_ip = true

  target_groups = [
    {
      target_group_name = "mgmt"
      container_port    = 80
      protocol = "TCP"
    }
  ]
  task_container_protocol = "TCP"
  wait_for_steady_state = true

  task_container_image   = "nginx:latest"
  task_definition_cpu    = 256
  task_definition_memory = 512

  task_container_port             = 80
  health_check = {
    port = 80
    path = "/"
  }

  task_stop_timeout = 90
  depends_on = [
    module.nlb
  ]
}

This does not


module "fargate5672" {
  source  = "umotif-public/ecs-fargate/aws"
  version = "6.4.2"
  name_prefix = "${var.name}-5672"
  desired_count = var.desired_count
  # sg_name_prefix     = "my-security-group-name" # uncomment if you want to name security group with specific name

  vpc_id             = var.vpc_id
  private_subnet_ids = var.private_subnet_ids
  cluster_id         = aws_ecs_cluster.cluster.id
#   task_container_assign_public_ip = true

  target_groups = [
    {
      target_group_name = var.rabbit_tg_name
      container_port    = 5672
      protocol = "TCP"
    }
  ]
  task_container_protocol = "TCP"
  wait_for_steady_state = true

  task_container_image   = "nginx:latest"
  task_definition_cpu    = 256
  task_definition_memory = 512

  task_container_port             = 5672
  health_check = {
    protocol = "TCP"
  }

  task_stop_timeout = 90

  depends_on = [
    module.nlb
  ]
}

What is the expected behavior?

When using a variable for target_group_name the module should be able to use the interpolated name or not re-tag Name in the tags here -

Name = lookup(each.value, "target_group_name")

I can then try using the Name tag as part of the name to change the Name of the tg. Today, I call the module from another module of mine.
Deploying multiple instances would create target-groups with the same name causing errors.

Software versions?

6.4.2

add pre-defined target group

the module only allow to use target group that the module creates.
how can I add a pre-defined target group that I already created with terraform?

thanks!

Secrets support

What is the current behavior?
There's no variable for declaring secrets in the task definition

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
I guess this is more of a feature request?

What is the expected behavior?
A secrets variable is available that replicates functionality in the task definition parameter as provided by https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html

Software versions?
Latest versions of terraform and umotif-public/terraform-aws-ecs-fargate

Success codes support

Is it possible to add the field "success codes" in the health check map? It can be found under advanced settings in the AWS console:
Screenshot 2021-09-06 at 13 56 27

blue/green deployments

What is the current behavior?
When you add multiple target groups to the module, it also adds these target groups to the load_balancer block in aws_ecs_server under the dynamic "load_balancer" section. When you want to do a blue/green deployments via CodeDeploy, only one target group should be assigned to the ecs service at any given time. CodeDeploy is swapping these target groups out during the deployment.

What happens now is that the ecs service has multiple target groups assigned, each task's private IP address is added to each target group. When the codedeploy deployment happens, it gets stuck during the install phase, since it can't register the new replacement task in either target group.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
/

What is the expected behavior?
Although this may be out of scope for this module and not the intended usage, it would maybe be nice to mention this behavior somewhere in the documentation.

My current workaround is:

  • Let the module only create one target group, for you blue deployments
  • Outside the module create another target group resource for green deployments, and attach it to a different listener with a different port than your main listener, such as 8080
  • In your codedeploy you can now pass both listeners (production listener for example on port 80 and test listener on 8080) and both target groups (blue and green target groups)

The problem will be that after the deployment has gone through, the target groups will have been switched out (codedeploy is doing this), so your infra state will not match your terraform any longer.

When you do a terraform apply after the first deployment, it will want to revert those changes. The module does not provide lifecycle ignore_changes on the load_balancer block, and so applying those changes will possibly break the load balancer routing to your ecs service.

The only workaround I've found for that is to clone the repo and to add lifecycle block with ignore_changes on load_balancer in the aws_ecs_server resource.

Software versions?
6.4.1

error creating ecs-fargate-example service: InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:xxxxxxxx:targetgroup/tg-fargate-example/97c07ffe67daf38f does not have an associated load balancer.

I keep getting the following error and not sure how to fix it.

 Error: error creating ecs-fargate-example service: InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:549567774903:targetgroup/tg-fargate-example/97c07ffe67daf38f does not have an associated load balancer.
│ 
│   with module.ecs-fargate.aws_ecs_service.service,
│   on .terraform/modules/ecs-fargate/main.tf line 279, in resource "aws_ecs_service" "service":
│  279: resource "aws_ecs_service" "service" {

Here's main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.27"
    }
  }

  required_version = ">= 0.14.9"
}


provider "aws" {
  profile = "xxx"
  region  = "us-east-1"
}


resource "aws_ecs_cluster" "cluster" {
  name = "example-ecs-cluster"

  capacity_providers = ["FARGATE_SPOT", "FARGATE"]

  default_capacity_provider_strategy {
    capacity_provider = "FARGATE_SPOT"
  }

  setting {
    name  = "containerInsights"
    value = "disabled"
  }
}

module "ecs-fargate" {
  source = "umotif-public/ecs-fargate/aws"
  version = "~> 6.1.0"

  name_prefix        = "ecs-fargate-example"
  vpc_id             = "xxxx"
  private_subnet_ids = ["xxxx", "xxx"]

  cluster_id         = aws_ecs_cluster.cluster.id

  task_container_image   = "marcincuber/2048-game:latest"
  task_definition_cpu    = 256
  task_definition_memory = 512

  task_container_port             = 80
  task_container_assign_public_ip = false

  target_groups = [
    {
      target_group_name = "tg-fargate-example"
      container_port    = 80
    }
  ]

  health_check = {
    port = "traffic-port"
    path = "/"
  }

  tags = {
    Environment = "test"
    Project = "Test"
  }
}

Software versions?
Terraform v1.0.5
on linux_amd64

  • provider registry.terraform.io/hashicorp/aws v3.56.0

Error: InvalidParameterException: The values specified for serviceRegistries do not require a value for 'containerPort'. Remove the value and retry.

What is the current behavior?
Attempting to set up private DNS service discovery for the fargate service created by this module, I get the error message
Error: InvalidParameterException: The values specified for serviceRegistries do not require a value for 'containerPort'. Remove the value and retry. followed by the registry ARN and name.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
In my instantiation of the Umotif Fargate module I added this parameter:
service_registry_arn = aws_service_discovery_service.service.arn which references a Service Discovery Service resource.

What is the expected behavior?
Everything provisions successfully and the Fargate service updates the Service Discovery service as required.

Software versions?

  • Terraform v0.13.5
  • terraform-aws-ecs-fargate v4.0.3

Misleading output ordering for `target_group_name` and `target_group_arn`

Suppose we have the following setup:

resource "aws_lb_listener" "alb_80" {
  load_balancer_arn = module.alb.arn
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type             = "forward"
    target_group_arn = module.fargate.target_group_arn[0]
  }
}

resource "aws_lb_listener" "alb_81" {
  load_balancer_arn = module.alb.arn
  port              = "81"
  protocol          = "HTTP"

  default_action {
    type             = "forward"
    target_group_arn = module.fargate.target_group_arn[1]
  }
}

module "fargate" {
  source = "../../"

  name_prefix = "ecs-fargate-example"
  ...

  target_groups = [
    {
      target_group_name = "B"
      container_port    = 80
    },
    {
      target_group_name = "A"
      container_port    = 81
    }
  ]

  ...
}

The above code reads as though:

  • aws_lb_listener.alb_80 will map to target_group_name = "B"
  • aws_lb_listener.alb_81 will map to target_group_name = "A"

However, I think the opposite actually happens. The module uses the following code for outputs:

output "target_group_arn" {
  description = "The ARN of the Target Group used by Load Balancer."
  value       = [for tg_arn in aws_lb_target_group.task : tg_arn.arn]
}

The for expression can modify the ordering of the input target_groups list. From terraform's documentation:

Because for expressions can convert from unordered types (maps, objects, sets) to ordered types (lists, tuples), Terraform must > choose an implied ordering for the elements of an unordered collection.

For maps and objects, Terraform sorts the elements by key or attribute name, using lexical sorting.

Can you confirm whether my understanding of the problem is correct?

ResourceNotReady: exceeded wait attempts

What is the current behavior?

Error: error waiting for ECS service (arn:aws:ecs:us-east-11234567890:service/ecs-cluster/ecs-fargate) to become ready: ResourceNotReady: exceeded wait attempts
│
│   with module.fargate.aws_ecs_service.service,
│   on ..\..\main.tf line 295, in resource "aws_ecs_service" "service":
│  295: resource "aws_ecs_service" "service" {

For some reason, terraform exits with the above error. But I could see the resources on the console. Not sure if there is any timeout value we could add until the resources get created.

Fargate module tries to reuse existing TaskDefinition instead of using the latest task definition

What is the current behavior?

I have both a Fargate Terraform module and a GitHub Action deploying Fargate. GitHub Action knows to updates the latest TaskDefinition. The Fargate Terraform module continues to update the old version that it created.

aws-actions/amazon-ecs-render-task-definition@v1
aws-actions/amazon-ecs-deploy-task-definition@v1

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

I don't have a great way to show the repo. We have a big, private repo. I'm guessing this will be pretty easy to confirm by someone that knows this code. I'm guessing this is working as implemented.

What is the expected behavior?

I'd expect this module to either reuse the latest TaskDefinition or create a new TaskDefinition.

Software versions?

6.1.0

Error: InvalidParameterException: The target group with targetGroupArn XXX does not have an associated load balancer. XXX

What is the current behavior?
Following the README I cannot deploy an ECS service.

module.ecs-fargate.aws_ecs_service.service: Creating...
module.ecs-fargate.aws_ecs_service.service: Still creating... [10s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [20s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [30s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [40s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [50s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m0s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m10s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m20s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m30s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m40s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [1m50s elapsed]
module.ecs-fargate.aws_ecs_service.service: Still creating... [2m0s elapsed]

Error: InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:REGION:ACCOUNTID:targetgroup/ecs-fargate-example-target-80/ANOTHERID does not have an associated load balancer. "ecs-fargate-example"

The target group seems to be created, but without being attached to ALB

module.ecs-fargate.aws_lb_target_group.task[0]: Creating...
module.ecs-fargate.aws_lb_target_group.task[0]: Creation complete after 1s [id=arn:aws:elasticloadbalancing:ap-southeast-1:465259923894:targetgroup/ecs-fargate-example-target-80/1e5ca7e82f23a419]

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

Software versions?

Terraform v0.14.6
+ provider registry.terraform.io/hashicorp/aws v3.27.0

Make "aws_security_group_rule" "egress_service" rule configurable

Hello,

Currently we would like to restrict the outgoing traffic for our fargate service. After looking at the source code in "https://github.com/umotif-public/terraform-aws-ecs-fargate/blob/master/main.tf" I just found out that there is a default security rule created which allow all outgoing traffic.
This represent an issue for us, since our security guidelines force us to limit outgoing traffic only to what it is necessary.

Would be possible to add an a feature toggle or input variable like 'deny_egress_to_anywhere' which if set to true then no egress rule will be created?

Something like

`module "ecs-fargate" {
source = "umotif-public/ecs-fargate/aws"
version = "6.5.0"
vpc_id = var.vpc_id
private_subnet_ids = var.private_subnets_ids

cluster_id = aws_ecs_cluster.cluster.id
deny_egress_to_anywhere = true
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.