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.42k stars 9.5k forks source link

Terraform crashes when azurerm_subnet is provided with an empty list for service_endpoints #20016

Closed gitmaximd closed 5 years ago

gitmaximd commented 5 years ago

Terraform Version

Terraform v0.11.11
+ provider.azurerm v1.20.0
+ provider.random v2.0.0

Terraform Configuration Files

resource "azurerm_subnet" "main" {
  count                = "${length(var.az_subnets)}"
  name                 = "${var.project_name}-${var.environment_type}-${element(var.az_subnets, count.index)}-SUBNET"
  address_prefix       = "${cidrsubnet(var.az_vnet_cidr[0], 8, count.index)}"
  virtual_network_name = "${var.az_vnet_name}"
  resource_group_name  = "${var.az_resource_group_name}"
  network_security_group_id = "${var.az_nsg_id}"

  service_endpoints = "${var.service_endpoints}"
}

Debug Output

panic: interface conversion: interface {} is nil, not string 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: goroutine 471 [running]: 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: github.com/terraform-providers/terraform-provider-azurerm/azurerm.expandAzureRmServiceEndpoints(0xc0007a6e70, 0xc001bec060, 0xe, 0x2aa4640, 0x30a3130, 0x0) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/resource_arm_subnet.go:269 +0x2a8 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: github.com/terraform-providers/terraform-provider-azurerm/azurerm.resourceArmSubnetCreate(0xc0007a6e70, 0x2db7260, 0xc001ba0000, 0x0, 0x0) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/resource_arm_subnet.go:125 +0x436 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema.(Resource).Apply(0xc000dcad20, 0xc000098640, 0xc001a5d100, 0x2db7260, 0xc001ba0000, 0x100b601, 0xc001039b80, 0x10be43c) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:225 +0x351 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema.(Provider).Apply(0xc00042e770, 0xc0000985f0, 0xc000098640, 0xc001a5d100, 0xc000058800, 0xc00022e460, 0x53006c0) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0x9c 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/plugin.(ResourceProviderServer).Apply(0xc000f696e0, 0xc001a5ccc0, 0xc000eb22a0, 0x0, 0x0) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: reflect.Value.call(0xc00013c8a0, 0xc00014c270, 0x13, 0x2dee34b, 0x4, 0xc001039f18, 0x3, 0x3, 0xc001b961c0, 0xc0004e4a80, ...) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/goenv/versions/1.11.1/src/reflect/value.go:447 +0x449 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: reflect.Value.Call(0xc00013c8a0, 0xc00014c270, 0x13, 0xc00052af18, 0x3, 0x3, 0x0, 0x0, 0xc00052afc0) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/goenv/versions/1.11.1/src/reflect/value.go:308 +0xa4 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: net/rpc.(service).call(0xc0005a8000, 0xc000dea550, 0xc000ad0060, 0xc000ad0070, 0xc000a6c080, 0xc0003e43c0, 0x2a51220, 0xc001a5ccc0, 0x16, 0x2a51260, ...) 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/goenv/versions/1.11.1/src/net/rpc/server.go:384 +0x14e 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: created by net/rpc.(Server).ServeCodec 2019-01-16T00:34:17.355+0200 [DEBUG] plugin.terraform-provider-azurerm_v1.20.0_x4: /opt/goenv/versions/1.11.1/src/net/rpc/server.go:481 +0x47e 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalWriteState 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalApplyProvisioners 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalIf 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalWriteState 2019/01/16 00:34:17 [TRACE] root.nsg: eval: terraform.EvalWriteState 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalWriteState 2019/01/16 00:34:17 [TRACE] root.nsg: eval: terraform.EvalApplyPost 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalApplyProvisioners 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalIf 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalWriteState 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalWriteDiff 2019/01/16 00:34:17 [TRACE] root.subnet: eval: terraform.EvalApplyPost 2019/01/16 00:34:17 [ERROR] root.nsg: eval: terraform.EvalApplyPost, err: 1 error(s) occurred:

Crash Output

Expected Behavior

terraform plan should generate a meaningful error/warning

Actual Behavior

terraform plan successfully generates the plan but terraform apply crashes

Steps to Reproduce

  1. Set an empty list variable

    variable "service_endpoints" {
    type = "list"
    default = []
    }
  2. Set the azurerm_subnet resource to use the variable in service_endpoints parameter

  3. Run terraform plan. The following result is expected:

    + module.subnet.azurerm_subnet.main[1]
      id:                        <computed>
      address_prefix:            "192.168.1.0/24"
      ip_configurations.#:       <computed>
      name:                      "SUBNET"
      network_security_group_id: "/subscriptions/xxxxxxx/resourceGroups/RG/providers/Microsoft.Network/networkSecurityGroups/NSG"
      resource_group_name:       "RG"
      service_endpoints.#:       "1"
      virtual_network_name:      "VNET"
  4. Run terraform apply

Additional Context

References

ghost commented 5 years ago

This issue has been automatically migrated to terraform-providers/terraform-provider-azurerm#2682 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to terraform-providers/terraform-provider-azurerm#2682.

ghost commented 4 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.