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

0.12 "dynamic" blocs fail with empty iterator #21373

Closed
ghost opened this issue May 21, 2019 · 3 comments · Fixed by #21549
Closed

0.12 "dynamic" blocs fail with empty iterator #21373

ghost opened this issue May 21, 2019 · 3 comments · Fixed by #21549
Milestone

Comments

@ghost
Copy link

ghost commented May 21, 2019

Terraform Version

Terraform v0.12.0-rc1

Terraform Configuration Files

This is based on the dynamic block example from the 0.12 documentation:

variable "service_ports" {
  type = list(number)
  default = []
}

resource "aws_security_group" "example" {
  name = "example"

  dynamic "ingress" {
    for_each = var.service_ports
    content {
      from_port = ingress.value
      to_port   = ingress.value
      protocol  = "tcp"
    }
  }
}

Actual Behavior

If var.service_ports is an empty list, Terraform fail and return the following error:

Error: Unsupported block type

  on aws.tf line 9, in resource "aws_security_group" "example":
   9:   dynamic "ingress" {

Blocks of type "ingress" are not expected here.

Expected Behavior

If var.service_ports is an empty list, Terraform should not generate any ingress block in the security group and continue successfully instead of failing.

Steps to Reproduce

  1. terraform init
  2. terraform apply (This will use the default empty list for var.service_ports).
@jbardin
Copy link
Member

jbardin commented May 21, 2019

Hi @xlz-jgoutin,

Thanks filing the issue! Sorry, I initially misunderstood the issue, that syntax does work in this case, but you are correct that does fail only with the empty collection.

@jbardin jbardin added bug and removed documentation labels May 21, 2019
@jbardin jbardin added this to the v0.12.1 milestone May 21, 2019
@hasheddan
Copy link
Contributor

@jbardin @xlz-jgoutin I am interested in helping out here! Is this a change that we definitely want to make, or is it potentially a feature to fail on an empty collection?

@ghost
Copy link

ghost commented Jul 25, 2019

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.

@ghost ghost locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants