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.53k stars 9.52k forks source link

Terraform import azurerm_virtual_machine_data_disk_attachment #26795

Closed iankf01 closed 3 years ago

iankf01 commented 3 years ago

Terraform Version

v0.13.5

Terraform Configuration Files


resource "azurerm_windows_virtual_machine" "azsgvmtstif01" {
  name = "azsgvmtstif01"
  resource_group_name = azurerm_resource_group.main.name
  location = azurerm_resource_group.main.location
 --rest removed---
}

resource "azurerm_managed_disk" "azsgvmtstif01_d" {
  name                 = "azsgvmtstif01_d"
  location             = azurerm_resource_group.main.location
  resource_group_name  = azurerm_resource_group.main.name
  storage_account_type = "Premium_LRS"
  create_option        = "Empty"
  disk_size_gb         = 4
  tags = {
    "environment" = "TST"
  }
}

resource "azurerm_virtual_machine_data_disk_attachment" "azsgvmtstif01_d" {
  managed_disk_id    = azurerm_managed_disk.azsgvmtstif01_d.id
  virtual_machine_id = azurerm_windows_virtual_machine.azsgvmtstif01.id
  lun                = "0"
  caching            = "None"
}

Debug Output

azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d: Importing from ID "/subscriptions/xxxx-xxxx-xxxx-xxxx-xxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D"...
azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d: Import prepared!
  Prepared azurerm_virtual_machine_data_disk_attachment for import
azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d: Refreshing state... [id=/subscriptions/xxxx-xxxx-xxxx-xxxx-xxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D]

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

panic: runtime error: invalid memory address or nil pointer dereference
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: [signal 0xc0000005 code=0x0 addr=0x8 pc=0x38a7ebd]
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: goroutine 74 [running]:
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute.resourceArmVirtualMachineDataDiskAttachmentRead(0xc000d5e9a0, 0x4468360, 0xc0000e6dc0, 0x0, 0x0)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/virtual_machine_data_disk_attachment_resource.go:220 +0x30d
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0002fc510, 0xc0010d2a00, 0x4468360, 0xc0000e6dc0, 0xc0000cab48, 0x0, 0x0)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:460 +0x120
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000187160, 0x53da9e0, 0xc00112c9c0, 0xc000e6dec0, 0xc000187160, 0xc00112c9c0, 0xc000931b78)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /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 +0x3df
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x48829a0, 0xc000187160, 0x53da9e0, 0xc00112c9c0, 
0xc000e6de60, 0x0, 0x53da9e0, 0xc00112c9c0, 0xc000e9e400, 0x1f7)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /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:3269 +0x21e
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: google.golang.org/grpc.(*Server).processUnaryRPC(0xc000707b00, 0x541ca40, 0xc000684600, 0xc000136500, 0xc0005baa50, 0x84d0770, 0x0, 0x0, 0x0) 
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1024 +0x508
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: google.golang.org/grpc.(*Server).handleStream(0xc000707b00, 0x541ca40, 0xc000684600, 0xc000136500, 0x0)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1313 +0xd44
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000928320, 0xc000707b00, 0x541ca40, 0xc000684600, 0xc000136500)
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:722 +0xa8
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-11-03T08:58:43.094Z [DEBUG] plugin.terraform-provider-azurerm_v2.34.0_x5.exe:                                                                                                                                              /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:720 +0xa8
2020/11/03 08:58:43 [ERROR] eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2020/11/03 08:58:43 [ERROR] eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2020/11/03 08:58:43 [TRACE] [walkImport] Exiting eval tree: import azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d result
2020/11/03 08:58:43 [TRACE] vertex "import azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d result": visit complete
2020/11/03 08:58:43 [TRACE] vertex "azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d (import id \"/subscriptions/xxxx-xxxx-xxxx-xxxx-xxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D\")": dynamic subgraph encountered errors
2020/11/03 08:58:43 [TRACE] vertex "azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d (import id \"/subscriptions/xxxx-xxxx-xxxx-xxxx-xxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D\")": visit complete
2020/11/03 08:58:43 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/hashicorp/azurerm\"] (close)" errored, so skipping
2020/11/03 08:58:43 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/11/03 08:58:43 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2020/11/03 08:58:43 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate
2020-11-03T08:58:43.105Z [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.34.0/windows_amd64/terraform-provider-azurerm_v2.34.0_x5.exe pid=9608 error="exit status 2"    
2020-11-03T08:58:43.105Z [DEBUG] plugin: plugin exited

Crash Output

azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d: Import prepared!
  Prepared azurerm_virtual_machine_data_disk_attachment for import
azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d: Refreshing state... [id=/subscriptions/xxxxx-xxx-xxx-xxxx-xxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D]

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

Expected Behavior

What should have happened? A successful import of the disk attachment resource

Actual Behavior

What actually happened? Crash

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:
1. `terraform init`
2. `terraform import azurerm_virtual_machine_data_disk_attachment.azsgvmtstif01_d /subscriptions/xxxx-xxxx-xxx-xxxx-xxxxx/resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/azsgvmtstif01/datadisks/azsgvmtstif01_D`

Additional Context

The disk already exists and attached, running the import after importing the disk throws the error

References

iankf01 commented 3 years ago

Case sensative on the import resourceGroups/iftest/providers/Microsoft.Compute/virtualmachines/dataDisks

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