GithubHelp home page GithubHelp logo

cn-terraform / terraform-aws-ecs-fargate-service Goto Github PK

View Code? Open in Web Editor NEW
77.0 6.0 47.0 193 KB

AWS ECS Fargate Service Terraform Module

Home Page: https://registry.terraform.io/modules/cn-terraform/ecs-fargate-service

License: Apache License 2.0

HCL 100.00%
terraform terraform-module aws amazon-web-services ecs-service ecs-fargate

terraform-aws-ecs-fargate-service's Introduction

AWS ECS Fargate Terraform Module

This Terraform module deploys an AWS ECS Fargate service.

Usage

Check valid versions on:

Other modules that you may need to use this module

The Networking module:

The ECS cluster module:

The ECS Task Definition:

The ECS ALB module:

Install pre commit hooks.

Please run this command right after cloning the repository.

    pre-commit install

For that you may need to install the following tools:

In order to run all checks at any point run the following command:

    pre-commit run --all-files

Requirements

Name Version
terraform >= 0.13
aws >= 4
local >= 2

Providers

Name Version
aws 4.48.0

Modules

Name Source Version
ecs-alb cn-terraform/ecs-alb/aws 1.0.32
ecs-autoscaling cn-terraform/ecs-service-autoscaling/aws 1.0.6

Resources

Name Type
aws_ecs_service.service resource
aws_security_group.ecs_tasks_sg resource
aws_security_group_rule.egress resource
aws_security_group_rule.ingress_through_http_and_https resource

Inputs

Name Description Type Default Required
access_logs_prefix (Optional) if access logging to an S3 bucket, this sets a prefix in the bucket beneath which this LB's logs will be organized. string null no
additional_certificates_arn_for_https_listeners (Optional) List of SSL server certificate ARNs for HTTPS listener. Use it if you need to set additional certificates besides default_certificate_arn list(any) [] no
assign_public_ip (Optional) Assign a public IP address to the ENI (Fargate launch type only). If true service will be associated with public subnets. Default false. bool false no
block_s3_bucket_public_access (Optional) If true, public access to the S3 bucket will be blocked. Ignored if log_bucket_id is provided. bool true no
container_name Name of the running container any n/a yes
custom_lb_arn ARN of the Load Balancer to use in the ECS service. If provided, this module will not create a load balancer and will use the one provided in this variable string null no
default_certificate_arn (Optional) The ARN of the default SSL server certificate. Required if var.https_ports is set. string null no
deployment_circuit_breaker_enabled (Optional) You can enable the deployment circuit breaker to cause a service deployment to transition to a failed state if tasks are persistently failing to reach RUNNING state or are failing healthcheck. bool false no
deployment_circuit_breaker_rollback (Optional) The optional rollback option causes Amazon ECS to roll back to the last completed deployment upon a deployment failure. bool false no
deployment_controller (Optional) Deployment controller list(string) [] no
deployment_maximum_percent (Optional) The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. number 200 no
deployment_minimum_healthy_percent (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. number 100 no
desired_count (Optional) The number of instances of the task definition to place and keep running. Defaults to 0. number 1 no
ecs_cluster_arn ARN of an ECS cluster any n/a yes
ecs_cluster_name (Optional) Name of the ECS cluster. Required only if autoscaling is enabled string null no
ecs_tasks_sg_allow_egress_to_anywhere (Optional) If true an egress rule will be created to allow traffic to anywhere (0.0.0.0/0). If false no egress rule will be created. Defaults to true bool true no
enable_autoscaling (Optional) If true, autoscaling alarms will be created. bool true no
enable_ecs_managed_tags (Optional) Specifies whether to enable Amazon ECS managed tags for the tasks within the service. bool false no
enable_execute_command (Optional) Specifies whether to enable Amazon ECS Exec for the tasks within the service. bool false no
enable_s3_bucket_server_side_encryption (Optional) If true, server side encryption will be applied. Ignored if log_bucket_id is provided. bool true no
enable_s3_logs (Optional) If true, all LoadBalancer logs will be send to S3. If true, and log_bucket_id is not provided, this module will create the bucket with other provided s3 bucket configuration options bool true no
force_new_deployment (Optional) 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, or immediately deploy ordered_placement_strategy and placement_constraints updates. bool false no
health_check_grace_period_seconds (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers. number 0 no
lb_deregistration_delay (Optional) The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds. number 300 no
lb_drop_invalid_header_fields (Optional) Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). The default is false. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. bool false no
lb_enable_cross_zone_load_balancing (Optional) If true, cross-zone load balancing of the load balancer will be enabled. Defaults to false. bool false no
lb_enable_deletion_protection (Optional) If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to false. bool false no
lb_enable_http2 (Optional) Indicates whether HTTP/2 is enabled in the load balancer. Defaults to true. bool true no
lb_http_ingress_cidr_blocks List of CIDR blocks to allowed to access the Load Balancer through HTTP list(string)
[
"0.0.0.0/0"
]
no
lb_http_ingress_prefix_list_ids List of prefix list IDs blocks to allowed to access the Load Balancer through HTTP list(string) [] no
lb_http_ports Map containing objects to define listeners behaviour based on type field. If type field is forward, include listener_port and the target_group_port. For redirect type, include listener port, host, path, port, protocol, query and status_code. For fixed-response, include listener_port, content_type, message_body and status_code map(any)
{
"default-http": {
"listener_port": 80,
"target_group_port": 80,
"type": "forward"
}
}
no
lb_https_ingress_cidr_blocks List of CIDR blocks to allowed to access the Load Balancer through HTTPS list(string)
[
"0.0.0.0/0"
]
no
lb_https_ingress_prefix_list_ids List of prefix list IDs blocks to allowed to access the Load Balancer through HTTPS list(string) [] no
lb_https_ports Map containing objects to define listeners behaviour based on type field. If type field is forward, include listener_port and the target_group_port. For redirect type, include listener port, host, path, port, protocol, query and status_code. For fixed-response, include listener_port, content_type, message_body and status_code map(any)
{
"default-https": {
"listener_port": 443,
"target_group_port": 443,
"type": "forward"
}
}
no
lb_idle_timeout (Optional) The time in seconds that the connection is allowed to be idle. Default: 60. number 60 no
lb_internal (Optional) If true, the LB will be internal. bool false no
lb_ip_address_type (Optional) The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. Defaults to ipv4 string "ipv4" no
lb_load_balancing_algorithm_type (Optional) Determines how the load balancer selects targets when routing requests. The value is round_robin or least_outstanding_requests. The default is round_robin. string "round_robin" no
lb_security_groups (Optional) A list of security group IDs to assign to the LB. list(string) [] no
lb_slow_start (Optional) The amount time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is 0 seconds. number 0 no
lb_stickiness (Optional) A Stickiness block. Provide three fields. type, the type of sticky sessions. The only current possible value is lb_cookie. cookie_duration, the time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds). enabled, boolean to enable / disable stickiness. Default is true.
object({
type = string
cookie_duration = string
enabled = bool
})
{
"cookie_duration": 86400,
"enabled": true,
"type": "lb_cookie"
}
no
lb_target_group_health_check_enabled (Optional) Indicates whether health checks are enabled. Defaults to true. bool true no
lb_target_group_health_check_healthy_threshold (Optional) The number of consecutive health checks successes required before considering an unhealthy target healthy. Defaults to 3. number 3 no
lb_target_group_health_check_interval (Optional) The approximate amount of time, in seconds, between health checks of an individual target. Minimum value 5 seconds, Maximum value 300 seconds. Default 30 seconds. number 30 no
lb_target_group_health_check_matcher The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, "200,202") or a range of values (for example, "200-299"). Default is 200. string "200" no
lb_target_group_health_check_path The destination for the health check request. string "/" no
lb_target_group_health_check_timeout (Optional) The amount of time, in seconds, during which no response means a failed health check. The range is 2 to 120 seconds, and the default is 5 seconds. number 5 no
lb_target_group_health_check_unhealthy_threshold (Optional) The number of consecutive health check failures required before considering the target unhealthy. Defaults to 3. number 3 no
log_bucket_id (Optional) if provided, the ID of a previously-defined S3 bucket to send LB logs to. string null no
max_cpu_evaluation_period The number of periods over which data is compared to the specified threshold for max cpu metric alarm string "3" no
max_cpu_period The period in seconds over which the specified statistic is applied for max cpu metric alarm string "60" no
max_cpu_threshold Threshold for max CPU usage string "85" no
min_cpu_evaluation_period The number of periods over which data is compared to the specified threshold for min cpu metric alarm string "3" no
min_cpu_period The period in seconds over which the specified statistic is applied for min cpu metric alarm string "60" no
min_cpu_threshold Threshold for min CPU usage string "10" no
name_prefix Name prefix for resources on AWS any n/a yes
ordered_placement_strategy (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of ordered_placement_strategy blocks is 5. This is a list of maps where each map should contain "id" and "field" list(any) [] no
placement_constraints (Optional) 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 (Optional) The platform version on which to run your service. Defaults to 1.4.0. More information about Fargate platform versions can be found in the AWS ECS User Guide. string "1.4.0" no
private_subnets The private subnets associated with the task or service. list(any) n/a yes
propagate_tags (Optional) Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. Default to SERVICE string "SERVICE" no
public_subnets The public subnets associated with the task or service. list(any) n/a yes
s3_bucket_server_side_encryption_key (Optional) The AWS KMS master key ID used for the SSE-KMS encryption. This can only be used when you set the value of sse_algorithm as aws:kms. The default aws/s3 AWS KMS master key is used if this element is absent while the sse_algorithm is aws:kms. Ignored if log_bucket_id is provided. string null no
s3_bucket_server_side_encryption_sse_algorithm (Optional) The server-side encryption algorithm to use. Valid values are AES256 and aws:kms. Ignored if log_bucket_id is provided. string "AES256" no
scale_target_max_capacity The max capacity of the scalable target number 5 no
scale_target_min_capacity The min capacity of the scalable target number 1 no
security_groups (Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used. list(any) [] no
service_registries (Optional) The service discovery registries for the service. The maximum number of service_registries blocks is 1. This is a map that should contain the following fields "registry_arn", "port", "container_port" and "container_name" map(any) {} no
ssl_policy (Optional) The name of the SSL Policy for the listener. . Required if var.https_ports is set. string null no
tags Resource tags map(string) {} no
task_definition_arn (Required) The full ARN of the task definition that you want to run in your service. any n/a yes
vpc_id ID of the VPC any n/a yes
waf_web_acl_arn ARN of a WAFV2 to associate with the ALB string "" no

Outputs

Name Description
aws_ecs_service_service_cluster The Amazon Resource Name (ARN) of cluster which the service runs on.
aws_ecs_service_service_desired_count The number of instances of the task definition
aws_ecs_service_service_id The Amazon Resource Name (ARN) that identifies the service.
aws_ecs_service_service_name The name of the service.
aws_lb_lb_arn The ARN of the load balancer (matches id).
aws_lb_lb_arn_suffix The ARN suffix for use with CloudWatch Metrics.
aws_lb_lb_dns_name The DNS name of the load balancer.
aws_lb_lb_id The ARN of the load balancer (matches arn).
aws_lb_lb_zone_id The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record).
aws_security_group_lb_access_sg_arn The ARN of the security group
aws_security_group_lb_access_sg_description The description of the security group
aws_security_group_lb_access_sg_egress The egress rules.
aws_security_group_lb_access_sg_id The ID of the security group
aws_security_group_lb_access_sg_ingress The ingress rules.
aws_security_group_lb_access_sg_name The name of the security group
aws_security_group_lb_access_sg_owner_id The owner ID.
aws_security_group_lb_access_sg_vpc_id The VPC ID.
ecs_tasks_sg_arn ${var.name_prefix} ECS Tasks Security Group - The ARN of the security group
ecs_tasks_sg_description ${var.name_prefix} ECS Tasks Security Group - The description of the security group
ecs_tasks_sg_id ${var.name_prefix} ECS Tasks Security Group - The ID of the security group
ecs_tasks_sg_name ${var.name_prefix} ECS Tasks Security Group - The name of the security group
lb_http_listeners_arns List of HTTP Listeners ARNs
lb_http_listeners_ids List of HTTP Listeners IDs
lb_http_tgs_arns List of HTTP Target Groups ARNs
lb_http_tgs_ids List of HTTP Target Groups IDs
lb_http_tgs_names List of HTTP Target Groups Names
lb_https_listeners_arns List of HTTPS Listeners ARNs
lb_https_listeners_ids List of HTTPS Listeners IDs
lb_https_tgs_arns List of HTTPS Target Groups ARNs
lb_https_tgs_ids List of HTTPS Target Groups IDs
lb_https_tgs_names List of HTTPS Target Groups Names

terraform-aws-ecs-fargate-service's People

Contributors

akaiypova-jetty avatar amontalban avatar atry avatar jareddarling avatar jcity avatar jnonino avatar mfcaro avatar mxfactorial avatar ovcharenko avatar rafilkmp3 avatar renovate[bot] avatar simowaer avatar tvaughan77 avatar verokarhu 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-ecs-fargate-service's Issues

enable_autoscaling: Issue with CloudWatch Metric alarm_actions Handling Null Values

Provider and Module Versions
AWS Provider Version: ~> 5.0
Module Version: 2.0.43

Description
I am experiencing an issue with the terraform-aws-ecs-fargate-service module, specifically with the handling of alarm_actions in CloudWatch metric alarms. The module is calling another module (cn-terraform/ecs-service-autoscaling/aws) which is responsible for setting up auto-scaling.

Every time I execute terraform apply, I see the following changes in the plan, even though no actual changes are made to the infrastructure:

# module.ecs_service_web-api.module.ecs-fargate-service.module.ecs-autoscaling[0].aws_cloudwatch_metric_alarm.api-cpu_high will be updated in-place
~ resource "aws_cloudwatch_metric_alarm" "api-cpu_high" {
    ~ alarm_actions                         = [
        + null,
          # (1 unchanged element hidden)
      ]
      id                                    = "api-cpu-high"
      tags                                  = {
          "Environment" = "dev"
          "Project"     = "example-project"
      }
      # (21 unchanged attributes hidden)
  }

Module Call
Here is how the ecs-autoscaling module is being called:

module "ecs-autoscaling" {
  count = var.enable_autoscaling ? 1 : 0

  source  = "cn-terraform/ecs-service-autoscaling/aws"
  version = "1.0.9"

  name_prefix               = var.name_prefix
  ecs_cluster_name          = var.ecs_cluster_name
  ecs_service_name          = aws_ecs_service.service.name
  max_cpu_threshold         = var.max_cpu_threshold
  min_cpu_threshold         = var.min_cpu_threshold
  max_cpu_evaluation_period = var.max_cpu_evaluation_period
  min_cpu_evaluation_period = var.min_cpu_evaluation_period
  max_cpu_period            = var.max_cpu_period
  min_cpu_period            = var.min_cpu_period
  scale_target_max_capacity = var.scale_target_max_capacity
  scale_target_min_capacity = var.scale_target_min_capacity
  tags                      = var.tags
}

Problematic Section in the ecs-autoscaling Module

The issue seems to be originating from the following part of the ecs-autoscaling module:

resource "aws_cloudwatch_metric_alarm" "cpu_low" {
  alarm_name          = "${var.name_prefix}-cpu-low"
  comparison_operator = "LessThanOrEqualToThreshold"
  evaluation_periods  = var.min_cpu_evaluation_period
  metric_name         = "CPUUtilization"
  namespace           = "AWS/ECS"
  period              = var.min_cpu_period
  statistic           = "Average"
  threshold           = var.min_cpu_threshold
  dimensions = {
    ClusterName = var.ecs_cluster_name
    ServiceName = var.ecs_service_name
  }
  alarm_actions = [
    aws_appautoscaling_policy.scale_down_policy.arn,
    var.sns_topic_arn != "" ? var.sns_topic_arn : ""
  ]
  tags = var.tags
}

Issue
The alarm_actions attribute is supposed to include the ARN of the scaling policy and optionally an SNS topic ARN if it is provided. However, it ends up including null instead of an empty string, leading to unnecessary in-place updates in the Terraform plan.

Question
Why does the conditional expression for alarm_actions end with a null value instead of an empty string? How can this be resolved to avoid unnecessary updates?

Any help or guidance on this issue would be greatly appreciated.

Health check path not available

Hello!

I ran into this issue while trying to override the health check path:

Error: Unsupported argument

  on deployment/service.tf line 184, in module "ecs-fargate-service":
 184:   health_check_path   = "/healthcheck"

An argument named "health_check_path" is not expected here.

It looks like this variable isn't available but terraform documentation shows it here: https://registry.terraform.io/modules/cn-terraform/ecs-fargate-service/aws/1.0.6. Can you look into this please for overriding the path?

Thank you so much for reviewing this request and your work on this project.

Option for enabling deployment_circuit_breaker

Can you please add an option for enabling deployment_circuit_breaker? This isn't enabled by default.

resource "aws_ecs_service" "mongo" {
  name            = "my_ecs"

  deployment_circuit_breaker {
    enable  = true
    rollback = ture
  }
}

ECS service with an NLB

Hello,
Is it possible to use this module to create an ECS service with an NLB instead of an ALB?
Alternatively, is it possible to supplier an external LB arn to attach to the service?
Thanks

Edit: Similarly, it would be useful to be able to provision a service with no defined LB.

Disable HTTPS

I use this module (and not ecs-fargate, as I could not understand the difference between the two), but I am able to successfully provision a cluster with tasks. However, I'm trying to disable HTTPS (i.s. remove listeners/target groups on 443) and have only 1 custom port (non-SSL) defined on the container that will be serving up health check responses, and I see no option to do this.

How does one disable all HTTPS with this module?

Unused KMs key

I might be mistaken but I think the following key is not used, thus created for nothing

main.tf

resource "aws_kms_key" "encryption_key" {
  description         = "${var.name_preffix} ECS Encryption Key"
  is_enabled          = true
  enable_key_rotation = true
}

enable_autoscaling argument not working as expected

When I try to set enable_autoscaling to false, I get an error:

│ Error: Unsupported argument

│ on app.tf line 378, in module "ecs_fargate_service":
│ 378: enable_autoscaling = false

│ An argument named "enable_autoscaling" is not expected here.

Add option to restrict aws_security_group.ecs_tasks_sg egress to 0.0.0.0/0

Firstly, thank you so much for maintaining and supporting this module, I'm using it right now and it's great.

I am using the module and have to comply with an audit criteria that requires that ingress and egress rules are restricted and cannot have an "allow any any" type rule (in this case allow egress to 0.0.0.0/0).

Would it be possible to add an option to the module to allow the aws_security_group_rule.egress rule be disabled?

Thanks in advance.

Error in https tg for_each

As a module user when I use https for the module I expect terraform apply to go through without errors. Instead, I receive the following:

Error: Invalid for_each argument

  on .terraform/modules/<my module>/main.tf line 15, in data "aws_lb_target_group" "lb_https_target_groups":
  15:   for_each = toset(var.lb_https_tgs_arns)

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.

service registries is not working

I'm trying to use the following but getting error no matter what I do.

Input:
service_registries = {
"registry_arn" = service_discovery_service.arn
"port" = ""
"container_port" = ""
"container_name" = ""
}

Error:
Error: Too many service_registries blocks

on line 0:
(source code not available)

No more than 1 "service_registries" blocks are allowed

Error: Unsupported attribute

on ../modules/ecs_service/main.tf line 78, in resource "aws_ecs_service" "service":
78: registry_arn = service_registries.value.registry_arn
|----------------
| service_registries.value is ""

This value does not have any attributes.

Error: Unsupported attribute

on ../modules/ecs_service/main.tf line 78, in resource "aws_ecs_service" "service":
78: registry_arn = service_registries.value.registry_arn
|----------------
| service_registries.value is ""

This value does not have any attributes.

Error: Unsupported attribute

on ../modules/ecs_service/main.tf line 78, in resource "aws_ecs_service" "service":
78: registry_arn = service_registries.value.registry_arn
|----------------
| service_registries.value is ""

This value does not have any attributes.

Error: Unsupported attribute

on ../modules/ecs_service/main.tf line 78, in resource "aws_ecs_service" "service":
78: registry_arn = service_registries.value.registry_arn
|----------------
| service_registries.value is "arn:aws:servicediscovery:us-east-2:XXXXXXXX"

This value does not have any attributes.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 79, in resource "aws_ecs_service" "service":
79: port = lookup(service_registries.value, "port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 79, in resource "aws_ecs_service" "service":
79: port = lookup(service_registries.value, "port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 79, in resource "aws_ecs_service" "service":
79: port = lookup(service_registries.value, "port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 79, in resource "aws_ecs_service" "service":
79: port = lookup(service_registries.value, "port", null)
|----------------
| service_registries.value is "arn:aws:servicediscovery:us-east-2:XXXXXXXX"

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 80, in resource "aws_ecs_service" "service":
80: container_name = lookup(service_registries.value, "container_name", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 80, in resource "aws_ecs_service" "service":
80: container_name = lookup(service_registries.value, "container_name", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 80, in resource "aws_ecs_service" "service":
80: container_name = lookup(service_registries.value, "container_name", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 80, in resource "aws_ecs_service" "service":
80: container_name = lookup(service_registries.value, "container_name", null)
|----------------
| service_registries.value is "arn:aws:servicediscovery:us-east-2:XXXXXXXX"

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 81, in resource "aws_ecs_service" "service":
81: container_port = lookup(service_registries.value, "container_port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 81, in resource "aws_ecs_service" "service":
81: container_port = lookup(service_registries.value, "container_port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 81, in resource "aws_ecs_service" "service":
81: container_port = lookup(service_registries.value, "container_port", null)
|----------------
| service_registries.value is ""

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Error: Invalid function argument

on ../modules/ecs_service/main.tf line 81, in resource "aws_ecs_service" "service":
81: container_port = lookup(service_registries.value, "container_port", null)
|----------------
| service_registries.value is "arn:aws:servicediscovery:us-east-2:XXXXXXXX"

Invalid value for "inputMap" parameter: lookup() requires a map as the first
argument.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/pipeline.yml
  • actions/checkout v4
  • actions/checkout v4
terraform
main.tf
  • cn-terraform/ecs-alb/aws 1.0.32
  • cn-terraform/ecs-service-autoscaling/aws 1.0.9
versions.tf
  • aws >= 4
  • local >= 2
  • hashicorp/terraform >= 0.13

  • Check this box to trigger a request for Renovate to run again on this repository

ECS Autoscaling Role Drift After Apply

Hey,

Something a bit odd is happening each time after creating or updating a service. Each time I apply after initially bringing it up, the autoscaling role has been changed to the AWS managed ECS autoscaling role. So I get this plan output every time:

~ resource "aws_appautoscaling_target" "scale_target" {
        id                 = "service/artspot/hello-world-service"
        max_capacity       = 5
        min_capacity       = 1
        resource_id        = "service/artspot/hello-world-service"
      ~ role_arn           = "arn:aws:iam::XXXXXXXXXXXX:role/aws-service-role/ecs.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ECSService" -> "arn:aws:iam::XXXXXXXXXXXX:role/hello-world-ecs-autoscale-role"
        scalable_dimension = "ecs:service:DesiredCount"
        service_namespace  = "ecs"
    }

Might not be anything you can do about it. Anyway, great module.

Failing to bring up resources on apply

I'm getting this error when I apply:

Error: Invalid count argument

 on .terraform/modules/ecs-fargate-service/terraform-aws-ecs-fargate-service-2.0.3/main.tf line 113, in resource "aws_security_group_rule" "ingress_through_http":
 113:   count                    = length(data.aws_lb_target_group.lb_http_target_groups)

The "count" 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 count depends on.

I can probably get around this by running apply with each lb target group data source as the target, but I think it might help to either add that to the readme or update it... Unless I'm incorrectly using the module?

Security group ingress/egress rule overwrite

Hi,

Upon trying to use the module, I get this error:

Error: [WARN] A duplicate Security Group rule was found on (sg-06b5d95a1643cbaa9). This may be
a side effect of a now-fixed Terraform issue causing two security groups with
identical attributes but different source_security_group_ids to overwrite each
other in the state. See https://github.com/hashicorp/terraform/pull/2376 for more
information and instructions for recovery. Error message: the specified rule "peer: sg-0acd84d530dea5135, TCP, from port: 443, to port: 443, ALLOW" already exists

I believe it may be linked to this commit:
923354c

and may have to do with this clause in the Terraform security group resource docs:

"NOTE on Security Groups and Security Group Rules: Terraform currently provides both a standalone Security Group Rule resource (a single ingress or egress rule), and a Security Group resource with ingress and egress rules defined in-line. At this time you cannot use a Security Group with in-line rules in conjunction with any Security Group Rule resources. Doing so will cause a conflict of rule settings and will overwrite rules."

which can be found here: https://www.terraform.io/docs/providers/aws/r/security_group.html

I think the 0.0.0.0/0 egress needs to be moved to its own rule as well, in order to fit within this structure. I can test it out and let you know/put in a PR if I have permission.

Best,
Steven

Issue when I try to share the same target group with an ALB load balancer that supports HTTP and HTTPS

Hi,

The current situation when using the terraform-aws-ecs-fargate-service module:

  • 1 ALB with 2 listeners: one for HTTP (80) and one for HTTPS (443)
  • 2 Target groups: one is used in HTTP listener and one is used for the HTTPS listener
  • 1 Fargate service that links to an ECS Cluster and Task Definition

Is it possible to point both ALB listeners (HTTP and HTTPS) to the same HTTP Target Group?
The app (Node.js) that is running in the ECS Task Definition only supports HTTP, that why I would like to point both ALB listeners to the same Target Group.

Screenshot 2020-12-23 at 15 24 54

At this moment when you define lb_http_ports and lb_https_ports the module automatically created 2 separate target groups.

Another question, what is the main reason why you moved the ALB module into the terraform-aws-ecs-fargate-service module? It would give us more flexibility when the ALB module was defined outside the Fargate Service module or could be optional.

Thanks in advance,
Jonathan

Error when disabling https

When using cn-terraform/ecs-fargate/aws version 2.0.19, if lb_enable_https = false is specified, it results in the following error:

Error: Invalid count argument

  on .terraform/modules/ecs-fargate.ecs-fargate-service/main.tf line 124, in resource "aws_security_group_rule" "ingress_through_https":
 124:   count                    = length(data.aws_lb_target_group.lb_https_target_groups)

The "count" 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 count depends on.

count = length(data.aws_lb_target_group.lb_https_target_groups)

How is custom_lb_arn being used

Hi,

I am wondering how var.custom_lb_arn is used? It seems the follow code snippet is the only place the variable is used, but I would like to use a custom load balancer in the service... how?

module "ecs-alb" {
count = var.custom_lb_arn == null ? 1 : 0

source = "cn-terraform/ecs-alb/aws"
version = "1.0.28"

Thanks,
Jason

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.