Target group needs something to point to (target_id), this isn't the case for ECS containers
mdimarino opened this issue · 3 comments
mdimarino commented
Hello, at 9.0.0 version an error occurs when trying to create a TG pointing to nothing. This is the case when you are building an ECS infrastrucuture.
For example:
provider "aws" {
region = local.region
default_tags {
tags = {
Billing = "infrastructure"
Provisioner = "Terraform"
ResourceGroup = local.name
}
}
}
locals {
name = basename(path.cwd)
region = "us-east-1"
vpc_id = "vpc-02066510918290900"
# dependendo se o load balancer for externo ou
# interno serão usadas subnets púbicas ou privadas
# respectivamente
alb_subnets = [
"subnet-02a5421fa2f6026ba",
"subnet-0c9772340bbb346f8",
"subnet-030c27cffd79ef730"
]
tags = {
Example = local.name
GithubRepo = "terraform-aws-alb"
GithubOrg = "terraform-aws-modules"
HashiCorpRegistry = "https://registry.terraform.io/modules/terraform-aws-modules/alb/aws/9.0.0"
}
}
resource "aws_resourcegroups_group" "resource_group" {
name = local.name
description = "Grupo de recursos ${local.name}"
resource_query {
query = <<JSON
{
"ResourceTypeFilters": [
"AWS::AllSupported"
],
"TagFilters": [
{
"Key": "ResourceGroup",
"Values": ["${local.name}"]
}
]
}
JSON
}
tags = {
Name = "${local.name}"
}
}
##################################################################
# Application Load Balancer
##################################################################
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = ">= 9.0.0"
name = local.name
load_balancer_type = "application"
enable_cross_zone_load_balancing = true
vpc_id = local.vpc_id
subnets = local.alb_subnets
enable_deletion_protection = false
listeners = {
http-listerner = {
port = 80
protocol = "HTTP"
# this is the default rule
action_type = "fixed-response"
fixed_response = {
content_type = "text/plain"
message_body = "Nothing to see here... Move along!"
status_code = "200"
}
rules = {
root_call = {
priority = 1
actions = [
{
type = "forward"
target_group_key = "tg-teste1-web"
stickiness = {
enabled = true
duration = 600
target_group_index = 0
}
}
]
conditions = [
{
path_patterns = ["/"]
}
]
}
}
}
}
target_groups = {
tg-teste1-web = {
backend_protocol = "HTTP"
backend_port = 80
target_type = "ip"
deregistration_delay = 5
load_balancing_cross_zone_enabled = true
health_check = {
enabled = true
healthy_threshold = 5
interval = 30
matcher = "200"
path = "/"
port = "traffic-port"
protocol = "HTTP"
timeout = 5
unhealthy_threshold = 2
}
protocol_version = "HTTP1"
}
}
security_groups = ["sg-0e95b85e4d32c0b4f"]
create_security_group = false
tags = {
Environment = "Test"
}
}
Running terraform plan shows:
module.alb.data.aws_partition.current: Reading...
module.alb.data.aws_partition.current: Read complete after 0s [id=aws]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform planned the following actions, but then encountered a problem:
# aws_resourcegroups_group.resource_group will be created
+ resource "aws_resourcegroups_group" "resource_group" {
+ arn = (known after apply)
+ description = "Grupo de recursos alb-teste1"
+ id = (known after apply)
+ name = "alb-teste1"
+ tags = {
+ "Name" = "alb-teste1"
}
+ tags_all = {
+ "Billing" = "infrastructure"
+ "Name" = "alb-teste1"
+ "Provisioner" = "Terraform"
+ "ResourceGroup" = "alb-teste1"
}
+ resource_query {
+ query = jsonencode(
{
+ ResourceTypeFilters = [
+ "AWS::AllSupported",
]
+ TagFilters = [
+ {
+ Key = "ResourceGroup"
+ Values = [
+ "alb-teste1",
]
},
]
}
)
+ type = "TAG_FILTERS_1_0"
}
}
# module.alb.aws_lb.this[0] will be created
+ resource "aws_lb" "this" {
+ arn = (known after apply)
+ arn_suffix = (known after apply)
+ desync_mitigation_mode = "defensive"
+ dns_name = (known after apply)
+ drop_invalid_header_fields = true
+ enable_deletion_protection = false
+ enable_http2 = true
+ enable_tls_version_and_cipher_suite_headers = false
+ enable_waf_fail_open = false
+ enable_xff_client_port = false
+ id = (known after apply)
+ idle_timeout = 60
+ internal = (known after apply)
+ ip_address_type = (known after apply)
+ load_balancer_type = "application"
+ name = "alb-teste1"
+ name_prefix = (known after apply)
+ preserve_host_header = false
+ security_groups = [
+ "sg-0e95b85e4d32c0b4f",
]
+ subnets = [
+ "subnet-02a5421fa2f6026ba",
+ "subnet-030c27cffd79ef730",
+ "subnet-0c9772340bbb346f8",
]
+ tags = {
+ "Environment" = "Test"
+ "terraform-aws-modules" = "alb"
}
+ tags_all = {
+ "Billing" = "infrastructure"
+ "Environment" = "Test"
+ "Provisioner" = "Terraform"
+ "ResourceGroup" = "alb-teste1"
+ "terraform-aws-modules" = "alb"
}
+ vpc_id = (known after apply)
+ xff_header_processing_mode = "append"
+ zone_id = (known after apply)
+ timeouts {}
}
# module.alb.aws_lb_listener.this["http-listerner"] will be created
+ resource "aws_lb_listener" "this" {
+ arn = (known after apply)
+ id = (known after apply)
+ load_balancer_arn = (known after apply)
+ port = 80
+ protocol = "HTTP"
+ ssl_policy = (known after apply)
+ tags = {
+ "Environment" = "Test"
+ "terraform-aws-modules" = "alb"
}
+ tags_all = {
+ "Billing" = "infrastructure"
+ "Environment" = "Test"
+ "Provisioner" = "Terraform"
+ "ResourceGroup" = "alb-teste1"
+ "terraform-aws-modules" = "alb"
}
+ default_action {
+ order = (known after apply)
+ type = "fixed-response"
+ fixed_response {
+ content_type = "text/plain"
+ message_body = "Nothing to see here... Move along!"
+ status_code = "200"
}
}
}
# module.alb.aws_lb_listener_rule.this["http-listerner/root_call"] will be created
+ resource "aws_lb_listener_rule" "this" {
+ arn = (known after apply)
+ id = (known after apply)
+ listener_arn = (known after apply)
+ priority = 1
+ tags = {
+ "Environment" = "Test"
+ "terraform-aws-modules" = "alb"
}
+ tags_all = {
+ "Billing" = "infrastructure"
+ "Environment" = "Test"
+ "Provisioner" = "Terraform"
+ "ResourceGroup" = "alb-teste1"
+ "terraform-aws-modules" = "alb"
}
+ action {
+ order = (known after apply)
+ target_group_arn = (known after apply)
+ type = "forward"
}
+ condition {}
}
# module.alb.aws_lb_target_group.this["tg-teste1-web"] will be created
+ resource "aws_lb_target_group" "this" {
+ arn = (known after apply)
+ arn_suffix = (known after apply)
+ connection_termination = (known after apply)
+ deregistration_delay = "5"
+ id = (known after apply)
+ ip_address_type = (known after apply)
+ lambda_multi_value_headers_enabled = false
+ load_balancing_algorithm_type = (known after apply)
+ load_balancing_cross_zone_enabled = "true"
+ name = (known after apply)
+ name_prefix = (known after apply)
+ port = 80
+ preserve_client_ip = (known after apply)
+ protocol = "HTTP"
+ protocol_version = "HTTP1"
+ proxy_protocol_v2 = false
+ slow_start = 0
+ tags = {
+ "Environment" = "Test"
+ "terraform-aws-modules" = "alb"
}
+ tags_all = {
+ "Billing" = "infrastructure"
+ "Environment" = "Test"
+ "Provisioner" = "Terraform"
+ "ResourceGroup" = "alb-teste1"
+ "terraform-aws-modules" = "alb"
}
+ target_type = "ip"
+ vpc_id = "vpc-02066510918290900"
+ health_check {
+ enabled = true
+ healthy_threshold = 5
+ interval = 30
+ matcher = "200"
+ path = "/"
+ port = "traffic-port"
+ protocol = "HTTP"
+ timeout = 5
+ unhealthy_threshold = 2
}
}
Plan: 5 to add, 0 to change, 0 to destroy.
╷
│ Error: Unsupported attribute
│
│ on .terraform/modules/alb/main.tf line 503, in resource "aws_lb_target_group_attachment" "this":
│ 503: target_id = each.value.target_id
│ ├────────────────
│ │ each.value is object with 7 attributes
│
│ This object does not have an attribute named "target_id".
bryantbiggs commented
in your target group set create_attachment = false
bryantbiggs commented
github-actions commented
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.