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.15k stars 9.47k forks source link

Terraform Crashed When Running terraform plan #22284

Closed cloudhashicorp closed 5 years ago

cloudhashicorp commented 5 years ago

Terraform Version

2019/08/01 17:07:47 [TRACE] vertex "module.vpc.aws_subnet.publicsubnets[2]": visit complete 2019/08/01 17:07:47 [WARN] Provider "aws" produced an invalid plan for module.vpc.aws_subnet.publicsubnets[0], but we are tolerating it because it is using the legacy plugin SDK. The following problems may be the cause of any confusing errors from downstream operations:

...

Terraform Configuration Files

...

Debug Output

Crash Output

Expected Behavior

Actual Behavior

Steps to Reproduce

Additional Context

References

lawliet89 commented 5 years ago

Probably the same issue.

With the following configuration:

resource "google_project_service" "workload" {
  for_each = var.api_services

  project = var.project_id
  service = each.key

  disable_on_destroy = false
}

variable "project_id" {
  description = "Project ID"
}

variable "api_services" {
  description = "List of API services to enable"

  default = [
    "compute.googleapis.com",
    "cloudbilling.googleapis.com",
    "iam.googleapis.com",
    "cloudresourcemanager.googleapis.com",
    "cloudkms.googleapis.com",
    "container.googleapis.com",
    "servicenetworking.googleapis.com",
    "dns.googleapis.com",
    "logging.googleapis.com",
    "storage-component.googleapis.com",
    "storage-api.googleapis.com",
  ]
}

Panic:

panic: not a string

goroutine 237 [running]:
github.com/zclconf/go-cty/cty.Value.AsString(...)
    /opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/go-cty@v1.0.1-0.20190708163926-19588f92a98f/cty/value_ops.go:1026
github.com/zclconf/go-cty/cty.Value.AsValueMap(0x2228cc0, 0xc000338ea0, 0x19cd420, 0xc000338ec0, 0xe)
    /opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/go-cty@v1.0.1-0.20190708163926-19588f92a98f/cty/value_ops.go:1095 +0x38a
github.com/hashicorp/terraform/terraform.evaluateResourceForEachExpressionKnown(0x2227980, 0xc00035b3e0, 0x225a540, 0xc000bfe000, 0x1f, 0xc00075e150, 0x19f0bc0, 0x0, 0x19f0bc0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval_for_each.go:84 +0x5bd
github.com/hashicorp/terraform/terraform.evaluateResourceForEachExpression(0x2227980, 0xc00035b3e0, 0x225a540, 0xc000bfe000, 0x1, 0x1, 0x0, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval_for_each.go:17 +0x5c
github.com/hashicorp/terraform/terraform.(*NodeRefreshableManagedResource).DynamicExpand(0xc000412188, 0x225a540, 0xc000bfe000, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/node_resource_refresh.go:42 +0x280
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x1ce35a0, 0xc000412188, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph.go:103 +0x8b1
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc000124d00, 0x1ce35a0, 0xc000412188, 0xc000383f40)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/dag/walk.go:392 +0x353
created by github.com/hashicorp/terraform/dag.(*Walker).Update
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/dag/walk.go:314 +0xa9b

EDIT: Fixed it by adding type = set(string) to the api_services variable.

teamterraform commented 5 years ago

Hello, to better understand this issue & make it easier to reproduce for anyone else, please could you add the following details:

Thanks.

kmoe commented 5 years ago

It looks like this may be a duplicate of #22305, which is fixed in https://github.com/hashicorp/terraform/pull/22279.

If you see the same behaviour in Terraform v0.12.7 or later, please open a new issue including all the details specified by @teamterraform above.

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.