terraform-provider-vultr
terraform-provider-vultr copied to clipboard
[BUG] - No ssh_keys when import vultr instance
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 We will look into this for you
Thanks, I wait
@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

@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]
Thanks for an answer. Really missed it, though...

Why did you close? I am waiting for a solution. I don't need forces replacement
@Bager133 Updating SSH keys on an existing instance will force a replacement. You can't add new ssh keys to existing server
I know. That's why I ask why the existing keys are not imported when imported
@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.
I did it :) I did it many times, tried many options, but the result is always the same - the keys are not imported
@Bager133 reopening I misunderstood the initial problem
@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,
]
}
}
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
I am also experiencing this, any updates?
I am also experiencing this, any updates?
I do with ignore_changes
@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.