terraform-provider-vultr icon indicating copy to clipboard operation
terraform-provider-vultr copied to clipboard

[BUG] - No ssh_keys when import vultr instance

Open Bager133 opened this issue 3 years ago • 18 comments

When I try to import vultr instance, ssh keys don't import. And if I do "terraform apply" then terraform force replace my service CODE зображення зображення tfstate зображення

Bager133 avatar Jan 27 '22 07:01 Bager133

@Bager133 We will look into this for you

ddymko avatar Jan 27 '22 13:01 ddymko

Thanks, I wait

Bager133 avatar Jan 27 '22 13:01 Bager133

@Bager133

Looking at what you posted it looks like you are encapsulating an array into another array

You have vultr_ssh_keys = [data.vultr_ssh_key_key.prod, data.vultr_ssh_key.main_env]

which you then pass off to ssh_key_ids = [var.vultr_ssh_keys]

This would translate to ssh_key_ids = [[data.vultr_ssh_key_key.prod, data.vultr_ssh_key.main_env]]

try just doing ssh_key_ids = var.vultr_ssh_keys

ddymko avatar Jan 27 '22 15:01 ddymko

зображення зображення

Bager133 avatar Jan 27 '22 15:01 Bager133

@Bager133

It looks like you are attempting to append the entire vultr_ssh_key data object to the list. The ssh_key_ids argument reference expects the id's of the ssh key rather than the entire object. If you adjust the code to this it should work: vultr_ssh_keys = [data.vultr_ssh_key_key.prod.id, data.vultr_ssh_key.main_env.id]

ErwinsExpertise avatar Jan 27 '22 17:01 ErwinsExpertise

Thanks for an answer. Really missed it, though...

Bager133 avatar Jan 28 '22 07:01 Bager133

зображення

Bager133 avatar Jan 28 '22 07:01 Bager133

Why did you close? I am waiting for a solution. I don't need forces replacement

Bager133 avatar Jan 28 '22 14:01 Bager133

@Bager133 Updating SSH keys on an existing instance will force a replacement. You can't add new ssh keys to existing server

ddymko avatar Jan 28 '22 14:01 ddymko

I know. That's why I ask why the existing keys are not imported when imported

Bager133 avatar Jan 28 '22 14:01 Bager133

@Bager133 Now that the structure of the value provided to ssh_key_ids is correct, please try removing the instance in question from the Terraform state, and re-importing.

Oogy avatar Jan 28 '22 15:01 Oogy

I did it :) I did it many times, tried many options, but the result is always the same - the keys are not imported

Bager133 avatar Jan 28 '22 15:01 Bager133

@Bager133 reopening I misunderstood the initial problem

ddymko avatar Jan 28 '22 16:01 ddymko

@Bager133 Thank you for bringing this to our attention, it appears the issue is that SSH Keys are not present in the get-instance Vultr API response resulting in the observed diff.

This will require further investigation. In the meantime, I believe the following workaround should prevent forced replacement:

resource "vultr_instance" "site_service" {
  # ...

  lifecycle {
    ignore_changes = [
     ssh_key_ids,
    ]
  }
}

Oogy avatar Jan 28 '22 16:01 Oogy

I also thought to do so, but as a last resort, if I can not find how to import keys. I hoped that there should be a way to import the instance in full

Bager133 avatar Jan 28 '22 16:01 Bager133

I am also experiencing this, any updates?

c12i avatar Feb 16 '22 11:02 c12i

I am also experiencing this, any updates?

I do with ignore_changes

Bager133 avatar Feb 16 '22 12:02 Bager133

@collinsmuriuki @Bager133

It's recommended to go with ignore_changes for the time being.

We will have to look at the API and see if we can return SSH keys on the instance calls.

ddymko avatar Feb 16 '22 13:02 ddymko