opentelekomcloud / terraform-provider-opentelekomcloud

Terraform OpenTelekomCloud provider
https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest
Mozilla Public License 2.0
87 stars 78 forks source link

device information wrong in opentelekomcloud_compute_volume_attach_v2.device #374

Closed ssteine2 closed 4 years ago

ssteine2 commented 5 years ago

Terraform Version

$ terraform -v
Terraform v0.12.9
$ ls -al .terraform/plugins/linux_amd64/
...
-rwxr-xr-x. 1 linux linux 32574144 Aug 21 17:47 terraform-provider-opentelekomcloud_v1.11.0_x4
...

Affected Resource(s)

Terraform Configuration Files

Manually simplified excerpt (hopefully without typos ;) ):

...
resource "opentelekomcloud_blockstorage_volume_v2" "disk1" {
  name              = "instance1-disk1"
  size              = 10
}
resource "opentelekomcloud_blockstorage_volume_v2" "disk2" {
  name              = "instance1-disk2"
  size              = 10
}
...
resource "opentelekomcloud_compute_volume_attach_v2" "disk1_attach" {
  instance_id = instance1.id
  volume_id   = opentelekomcloud_blockstorage_volume_v2.disk1.id
}
resource "opentelekomcloud_compute_volume_attach_v2" "disk2_attach" {
  instance_id = instance1.id
  volume_id   = opentelekomcloud_blockstorage_volume_v2.disk2.id
}
...

Actual Behavior

I create multiple blockstorage volumes ("disks") for each instance. The disks are then attached to the instance. This works well on the first run, creating a proper terraform state.

$ terraform state show instance1.opentelekomcloud_compute_volume_attach_v2.disk1_attach
# instance1.opentelekomcloud_compute_volume_attach_v2.disk1_attach:
resource "opentelekomcloud_compute_volume_attach_v2" "disk1_attach" {
    device      = "/dev/vdc"
    id          = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22/218e42a1-c8ac-4777-a71c-27b7c9a62789"
    instance_id = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22"
    region      = "eu-ch"
    volume_id   = "218e42a1-c8ac-4777-a71c-27b7c9a62789"
}
$ terraform state show instance1.opentelekomcloud_compute_volume_attach_v2.disk2_attach
# instance1.opentelekomcloud_compute_volume_attach_v2.disk2_attach:
resource "opentelekomcloud_compute_volume_attach_v2" "disk2_attach" {
    device      = "/dev/vdd"
    id          = "e45fdr68-1fbc-4637-8c96-0b64f8ab2d22/218e42a1-c8ac-4777-a71c-27b7c9a62789"
    instance_id = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22"
    region      = "eu-ch"
    volume_id   = "34fe42a1-c8ac-4777-a71c-27b7c9a62789"
}

[user@instance1 ~]$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda             253:0    0   50G  0 disk 
└─vda1          253:1    0   50G  0 part /
vdc             253:160  0   10G  0 disk 
vdd             253:176  0   10G  0 disk 

That is, the device property in the terraform statefile is equal to the device name on the ecs instance.

The problem starts when I rebuild the instance by recycling the root volume and then re-attaching the existing disks to it. The device property will then in some cases (exact conditions unknown) no longer match with the naming found on the instance.

$ terraform state show instance1.opentelekomcloud_compute_volume_attach_v2.disk1_attach
# instance1.opentelekomcloud_compute_volume_attach_v2.disk1_attach:
resource "opentelekomcloud_compute_volume_attach_v2" "disk1_attach" {
    device      = "/dev/vdc"
    id          = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22/218e42a1-c8ac-4777-a71c-27b7c9a62789"
    instance_id = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22"
    region      = "eu-ch"
    volume_id   = "218e42a1-c8ac-4777-a71c-27b7c9a62789"
}
$ terraform state show instance1.opentelekomcloud_compute_volume_attach_v2.disk2_attach
# instance1.opentelekomcloud_compute_volume_attach_v2.disk2_attach:
resource "opentelekomcloud_compute_volume_attach_v2" "disk2_attach" {
    device      = "/dev/vdd"
    id          = "e45fdr68-1fbc-4637-8c96-0b64f8ab2d22/218e42a1-c8ac-4777-a71c-27b7c9a62789"
    instance_id = "d6fe8168-1fbc-4637-8c96-0b64f8ab2d22"
    region      = "eu-ch"
    volume_id   = "34fe42a1-c8ac-4777-a71c-27b7c9a62789"
}

[user@instance1 ~]$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda             253:0    0   50G  0 disk 
└─vda1          253:1    0   50G  0 part /
vde             253:160  0   10G  0 disk 
vdf             253:176  0   10G  0 disk 

That is, the terraform state still reports the device as "/dev/vdc", "/dev/vdd" while in fact it's named "/dev/vde", "/dev/vdf" on the OS. Rerunning terraform apply again does not change this invalid state.

My automation code is thus not able to properly mount the volumes because it retrieves the wrong device names from the terraform state.

Expected Behavior

The device property of opentelekomcloud_compute_volume_attach_v2 should always correctly reflect the device name as used on the ecs.

Steps to Reproduce

  1. terraform apply a project which contains an ecs instance with multiple (non-ephemeral) disks attached
  2. Recreate the ecs instance e.g. by tainting the root disk while not recreating the other disks ("disk1", "disk2").

As mentioned above this does not always happen and I was not able to pinpoint the exact circumstances under which this shows up. Maybe a certain degree of parallelism is required (say e.g. 10 instances with 10 attached non-ephemeral disks each)

niuzhenguo commented 5 years ago

@ssteine2 Thanks for raising this, this is a known issue on Cloud side, it cannot ensure the device name correct. As a workaround, you can make the compute_volume_attach_v2 resource depend on the previous compute_volume_atatch_v2 to keep the device order.

outcatcher commented 4 years ago

Seems not to be an issue of the provider @ssteine2 Please comment if you still need the issue