hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.43k stars 9.51k forks source link

"inconsistent list element types" with security group ingress rule #21314

Closed demisx closed 5 years ago

demisx commented 5 years ago

Version: v0.12-rc1

The log is attached: crash.log

demisx commented 5 years ago

Looks like it's caused by security_groups=[] line in this block of code:

resource "aws_security_group" "baseline" {
  vpc_id = "${var.vpc_id}"
  description = "Instance base security group"
  name = "baseline"
  lifecycle {
    create_before_destroy = true
  }

  ingress {
    from_port       = 0
    to_port         = 0
    protocol        = "-1"
    security_groups = [] # <-- Removing this line eliminates crashing
    self            = true
  }

  ingress {
    from_port       = 63158
    to_port         = 63158
    protocol        = "tcp"
    cidr_blocks     = ["0.0.0.0/0"]
  }

  ingress {
    from_port = 8
    to_port = 0
    protocol = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port       = 0
    to_port         = 0
    protocol        = "-1"
    cidr_blocks     = ["0.0.0.0/0"]
  }
}
jbardin commented 5 years ago

Hi @demisx, thanks for reporting the issue.

There seems to be an issue wit the literal list not correctly being converted to a set internally.

The error and stack trace for reference:

panic: inconsistent list element types 
    cty.Object(map[string]cty.Type{"cidr_blocks":cty.List(cty.String), "description":cty.String, "from_port":cty.Number, "ipv6_cidr_blocks":cty.List(cty.String), "prefix_list_ids":cty.List(cty.String), "protocol":cty.String, "security_groups":cty.List(cty.String), "self":cty.Bool, "to_port":cty.Number}) then 
    cty.Object(map[string]cty.Type{"cidr_blocks":cty.List(cty.String), "description":cty.String, "from_port":cty.Number, "ipv6_cidr_blocks":cty.List(cty.String), "prefix_list_ids":cty.List(cty.String), "protocol":cty.String, "security_groups":cty.Set(cty.String), "self":cty.Bool, "to_port":cty.Number})

goroutine 66 [running]:
github.com/zclconf/go-cty/cty.ListVal(0xc0000cbda0, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0)
    /Users/jbardin/go/pkg/mod/github.com/zclconf/go-cty@v0.0.0-20190430221426-d36a6f0dbffd/cty/value_init.go:166 +0x4bf
github.com/hashicorp/terraform/lang/blocktoattr.(*fixupBlocksExpr).Value(0xc0008c6cc0, 0xc0001e7ea0, 0xc0005ad1e8, 0x7, 0xc0008c8170, 0xc0000dc301, 0x2bebaa0, 0xc0000dc380, 0x2456f20)
    /Users/jbardin/go/src/github.com/hashicorp/terraform/lang/blocktoattr/fixup.go:166 +0x68f
github.com/hashicorp/hcl2/hcldec.(*AttrSpec).decode(0xc00084d140, 0xc0000cbb60, 0x0, 0x0, 0x0, 0xc0001e7ea0, 0x0, 0x0, 0x2456f20, 0xc0009babc0, ...)
    /Users/jbardin/go/pkg/mod/github.com/hashicorp/hcl2@v0.0.0-20190514214226-6a61d80ae3d0/hcldec/spec.go:196 +0xa5
github.com/hashicorp/hcl2/hcldec.ObjectSpec.decode(0xc00084cf90, 0xc0000cbb60, 0x0, 0x0, 0x0, 0xc0001e7ea0, 0xc0003d5428, 0xc0008c6270, 0x20, 0x20, ...)
    /Users/jbardin/go/pkg/mod/github.com/hashicorp/hcl2@v0.0.0-20190514214226-6a61d80ae3d0/hcldec/spec.go:78 +0x239
github.com/hashicorp/hcl2/hcldec.decode(0x2beae20, 0xc0001e7ec0, 0x0, 0x0, 0x0, 0xc0001e7ea0, 0x2beb820, 0xc00084cf90, 0x0, 0x0, ...)
    /Users/jbardin/go/pkg/mod/github.com/hashicorp/hcl2@v0.0.0-20190514214226-6a61d80ae3d0/hcldec/decode.go:21 +0x118
github.com/hashicorp/hcl2/hcldec.Decode(...)
    /Users/jbardin/go/pkg/mod/github.com/hashicorp/hcl2@v0.0.0-20190514214226-6a61d80ae3d0/hcldec/public.go:15
github.com/hashicorp/terraform/lang.(*Scope).EvalBlock(0xc0001e4e10, 0x2bea6a0, 0xc00084cf60, 0xc0009ba4b0, 0x1, 0x1, 0x0, 0x0, 0x0, 0xc000070690, ...)
    /Users/jbardin/go/src/github.com/hashicorp/terraform/lang/eval.go:68 +0x2aa
github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).EvaluateBlock(0xc00092ed00, 0x2bea6a0, 0xc00084cf60, 0xc0009ba4b0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /Users/jbardin/go/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:277 +0x2b6
github.com/hashicorp/terraform/terraform.(*EvalValidateResource).Eval(0xc0001e4dc0, 0x2c18580, 0xc00092ed00, 0x2, 0x2, 0x0, 0x0)
    /Users/jbardin/go/src/github.com/hashicorp/terraform/terraform/eval_validate.go:413 +0x5a7
ghost commented 5 years 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.