hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.62k forks source link

Terraform import fails for azurerm_iothub_dps #5945

Closed mark-greene closed 4 years ago

mark-greene commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.12.21

Initializing provider plugins...

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_iothub_dps" "iot_dps" {
  name                = local.dps_name
  resource_group_name = local.dps_resource_group
  location            = local.dps_location

  sku {
    name     = "S1"
    capacity = "1"
  }

  linked_hub {
    connection_string = data.external.connection_string.result["connection"]
    location          = azurerm_iothub.iot.location
  }

  count = var.location == "eastus2" ? 1 : 0
}

Debug Output

Panic Output

terraform import -var stack=iot -var location=eastus2 -var-file=variables/prod.tfvars azurerm_iothub_dps.iot_dps[0] /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps azurerm_iothub_dps.iot_dps[0]: Importing from ID "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps"...

azurerm_iothub_dps.iot_dps[0]: Import prepared! Prepared azurerm_iothub_dps for import azurerm_iothub_dps.iot_dps[0]: Refreshing state... [id=/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps]

Error: rpc error: code = Unavailable desc = transport is closing

panic: runtime error: invalid memory address or nil pointer dereference 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x3212d76] 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: goroutine 79 [running]: 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub.flattenIoTHubDPSSku(...) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub/resource_arm_iothub_dps.go:361 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub.resourceArmIotHubDPSRead(0xc0005f0620, 0x39652e0, 0xc0000c86c0, 0x0, 0x0) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub/resource_arm_iothub_dps.go:250 +0x586 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Resource).RefreshWithoutUpgrade(0xc000503900, 0xc0008d8280, 0x39652e0, 0xc0000c86c0, 0xc000148b10, 0x0, 0x0) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:455 +0x119 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(GRPCProviderServer).ReadResource(0xc00000eb08, 0x46b9440, 0xc000942360, 0xc0008d80a0, 0xc00000eb08, 0xc000942360, 0xc000991bd0) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:525 +0x3d7 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x3ccf080, 0xc00000eb08, 0x46b9440, 0xc000942360, 0xc000d9a060, 0x0, 0x46b9440, 0xc000942360, 0xc000750480, 0x178) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3153 +0x23e 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: google.golang.org/grpc.(Server).processUnaryRPC(0xc0003c4580, 0x4710940, 0xc000092780, 0xc000d46100, 0xc000869e00, 0x7aa6730, 0x0, 0x0, 0x0) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:995 +0x466 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: google.golang.org/grpc.(Server).handleStream(0xc0003c4580, 0x4710940, 0xc000092780, 0xc000d46100, 0x0) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1275 +0xda6 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: google.golang.org/grpc.(Server).serveStreams.func1.1(0xc000286250, 0xc0003c4580, 0x4710940, 0xc000092780, 0xc000d46100) 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:710 +0x9f 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: created by google.golang.org/grpc.(Server).serveStreams.func1 2020-02-29T10:43:33.883-0500 [DEBUG] plugin.terraform-provider-azurerm_v1.44.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:708 +0xa1 2020-02-29T10:43:33.892-0500 [DEBUG] plugin: plugin process exited: path=/home/mark/projects/devops/devops-cloud/iot/.terraform/plugins/linux_amd64/terraform-provider-azurerm_v1.44.0_x4 pid=26889 error="exit status 2" 2020/02/29 10:43:33 [ERROR] : eval: terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing 2020/02/29 10:43:33 [ERROR] : eval: terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing 2020/02/29 10:43:33 [TRACE] [walkImport] Exiting eval tree: import azurerm_iothub_dps.iot_dps[0] result 2020/02/29 10:43:33 [TRACE] vertex "import azurerm_iothub_dps.iot_dps[0] result": visit complete 2020/02/29 10:43:33 [TRACE] vertex "azurerm_iothub_dps.iot_dps[0] (import id \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps\")": dynamic subgraph encountered errors 2020/02/29 10:43:33 [TRACE] vertex "azurerm_iothub_dps.iot_dps[0] (import id \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps\")": visit complete 2020/02/29 10:43:33 [TRACE] dag/walk: upstream of "provider.azurerm (close)" errored, so skipping 2020/02/29 10:43:33 [TRACE] dag/walk: upstream of "root" errored, so skipping 2020-02-29T10:43:34.123-0500 [DEBUG] plugin: plugin exited

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform. A crash log has been placed at "crash.log" relative to your current working directory. It would be immensely helpful if you could please report the crash with Terraform1 so that we can fix this.

When reporting bugs, please include your terraform version. That information is available on the first line of crash.log. You can also get it by running 'terraform --version' on the command line.

SECURITY WARNING: the "crash.log" file that was created may contain sensitive information that must be redacted before it is safe to share on the issue tracker.

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform import -var stack=iot -var location=eastus2 -var-file=variables/prod.tfvars azurerm_iothub_dps.iot_dps[0] /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps azurerm_iothub_dps.iot_dps[0]: Importing from ID "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Cloud.Prod.cloud-iot/providers/Microsoft.Devices/ProvisioningServices/prod-cloud-iot-dps"

Important Factoids

References

mark-greene commented 4 years ago

This seems to be related to the Data Provisioning Service Resource ID. When I provisioned DPS via the azure cli several months ago before the azure provider offered support, the Resource ID has the form "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Prod.iot/providers/Microsoft.Devices/ProvisioningServices/prod-iot-dps". Services created now have the form, /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Prod.iot/providers/Microsoft.Devices/provisioningServices/prod-iot-dps". When I manually import (edit) the state and use "ProvisioningServices" a terraform plan crashes. When I use "provisioningServices" the plan succeeds but believes it must replace the resource.

And I upgraded to 2.0 and it behaves exactly the same.

ghost commented 4 years ago

This has been released in version 2.7.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.7.0"
}
# ... other configuration ...
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!