hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.16k forks source link

aws_ecs_service empty dynamic service_registries block throws error #19392

Closed cixelsyd closed 1 year ago

cixelsyd commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.28
+ provider.aws v3.34.0

Affected Resource(s)

Terraform Configuration Files

  + resource "aws_ecs_service" "service" {
      + cluster                            = "cluster-name"
      + deployment_maximum_percent         = 200
      + deployment_minimum_healthy_percent = 100
      + desired_count                      = 1
      + enable_ecs_managed_tags            = false
      + enable_execute_command             = false
      + iam_role                           = (known after apply)
      + id                                 = (known after apply)
      + launch_type                        = "FARGATE"
      + name                               = "service-name"
      + platform_version                   = "1.4.0"
      + scheduling_strategy                = "REPLICA"
      + task_definition                    = "arn:aws:ecs:us-east-1:999999999999:task-definition/service-name:1"
      + wait_for_steady_state              = false

      + deployment_controller {
          + type = "CODE_DEPLOY"
        }

      + load_balancer {
          + container_name   = "service-name"
          + container_port   = 8080
          + target_group_arn = "arn:aws:elasticloadbalancing:us-east-1:999999999999:targetgroup/service-name-tg1/1111111111111111"
        }

      + network_configuration {
          + assign_public_ip = false
          + security_groups  = [
              + "sg-11111111111111111",
            ]
          + subnets          = [
              + "subnet-11111111111111111"
            ]
        }

      + service_registries {}
    }

Debug Output

Panic Output

Expected Behavior

I would expect terraform to ignore this empty service registry block:

service_registries {}

Actual Behavior

terraform threw an RPC error:

Error: rpc error: code = Canceled desc = context canceled

Steps to Reproduce

  1. terraform apply

Important Factoids

I render these dynamic blocks inside a module by passing map objects in via tfvars files, like this:

  // this SHOULD work (we use this construction in other places)
  // but it does not. it renders this into the planout:
  // + service_registries {}
  // and that terraform convergence throws the following error:
  // Error: rpc error: code = Canceled desc = context canceled
  dynamic "service_registries" {
    for_each = length(regexall(".*", lookup(each.value.ecs-config, "registry_arn", ""))) > 0 ? [1] : []

    content {
      registry_arn = each.value.ecs-config.registry_arn
    }
  }

I use the ternary operator with the regex/length construction throughout multiple modules to render blocks based on if a particular setting is provided inside tfvars. I have not had issues in other places with this method.

References

github-actions[bot] commented 1 year ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

github-actions[bot] commented 11 months ago

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.