digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
508 stars 277 forks source link

Certificate not found on import of digitalocean_certificate #1195

Closed piercefreeman closed 3 months ago

piercefreeman commented 3 months ago

Bug Report

Describe the bug

I'm trying to import a certificate that I've created outside of terraform into my current state.

$ doctl compute certificate list
ID                                      Name                        DNS Names                      SHA-1 Fingerprint                           Expiration Date         Created At              Type            State
{uuid4}                       my-app-cert                        app.mydomain.ai                             {sha}                           2024-10-28T19:04:58Z    2024-07-30T20:05:00Z    lets_encrypt    verified
terraform import -var-file .tfvars "digitalocean_certificate.cert" {uuid4}

Affected Resource(s)

digitalocean_certificate.cert

Expected Behavior

The certificate is successfully found and imported.

Actual Behavior

digitalocean_certificate.cert: Import prepared!
  Prepared digitalocean_certificate for import
digitalocean_certificate.cert: Refreshing state... [id=e13a3e8f-599a-48cd-aa6b-b944dac8a6ea]

╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "digitalocean_certificate.cert", the provider detected that no object exists with the given id. Only
│ pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform
│ apply" to create a new remote object for this resource.
╵

╷
│ Error: certificate not found
│
│   with data.digitalocean_certificate.prod_populated_proxy_cert[0],
│   on /Users/piercefreeman/projects/tf-infrastructure/app/web.tf line 216, in data "digitalocean_certificate" "prod_populated_proxy_cert":
│  216: data "digitalocean_certificate" "prod_populated_proxy_cert" {
│

Steps to Reproduce

Terraform version

Terraform v1.9.3
on darwin_arm64
+ provider registry.terraform.io/digitalocean/digitalocean v2.39.2

Additional context

This occurs with all certificates that I attempt to import.

andrewsomething commented 3 months ago

Hi @piercefreeman,

As certificates generated using Let's Encrypt will change their ID when renewed and certificates must use a unique name, we use the certificates name as its ID in Terraform. e.g.:

terraform import digitalocean_certificate.cert my-app-cert

https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/certificate#import

Let us know if that resolves the problem for you.

piercefreeman commented 3 months ago

Thanks for checking this out @andrewsomething. I've confirmed using the credential name does solve this issue; missed the indication in the docs that this endpoint takes the name vs the UUID as in other imports. Will go ahead and close this out.