Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] - Declaring an already-existing domain is rejected, with no clear migration path #314

Open
io7m opened this issue Feb 1, 2023 · 1 comment
Assignees
Labels

Comments

@io7m
Copy link

io7m commented Feb 1, 2023

Describe the bug
I'm not certain if this is a bug or a feature request.

I have a domain and a set of instances in Vultr, and I'm trying to seamlessly migrate to using Terraform to manage them. I have a domain, let's call it example.com, with a lot of records in it. I'm trying to migrate to using Terraform
to manage the domain, so the first step has been to declare it in the Terraform file:

resource "vultr_dns_domain" "example_domain" {
  domain = "example.com"
}

Unfortunately, terraform plan then tries to create a plan that will create that domain, even though it already exists. Running the plan will fail as you might expect:

vultr_dns_domain.example_domain: Creating...
╷
│ Error: error while creating domain : {"error":"Unable to create domain: Domain already exists","status":400}
│ 
│   with vultr_dns_domain.example_domain,
│   on domain.tf line 39, in resource "vultr_dns_domain" "example_domain":
│   39: resource "vultr_dns_domain" "example_domain" {
│ 
╵

To Reproduce
Steps to reproduce the behavior:

  1. Create a domain in the Vultr control panel.
  2. Declare the same domain in a Terraform file.
  3. terraform plan
  4. terraform apply

Expected behavior
I would expect Terraform to see that the domain already exists, and avoid creating it. It might create a plan to remove any records it doesn't know about, but that's not essential. In fact, it seems to be the general behavior of the Vultr provider to ignore extra values it doesn't know about (like extra VPS instances existing already).

Screenshots

Desktop (please complete the following information where applicable:


$ terraform --version
Terraform v1.3.7
on linux_amd64
+ provider registry.terraform.io/vultr/vultr v2.12.0

Additional context

@io7m io7m added the bug label Feb 1, 2023
@optik-aper
Copy link
Member

Hello @io7m! Apologies for the slow response. Most resources can be imported into terraform state using the terraform import process/command. Just to be sure I tested it out like so:

main.tf:

resource "vultr_dns_domain" "fake-domain" {
  domain = "whattestvultr.dev"
}

data "vultr_dns_domain" "fake-data" {
  domain = "whattestvultr.dev"
}

output "domain_date" {
  value = data.vultr_dns_domain.fake-data.date_created
}

And then, import the existing domain into Terraform:

terraform import vultr_dns_domain.fake-domain whattestvultr.dev                                                                      1 ↵ 13:00
vultr_dns_domain.fake-domain: Importing from ID "whattestvultr.dev"...
vultr_dns_domain.fake-domain: Import prepared!
  Prepared vultr_dns_domain for import
vultr_dns_domain.fake-domain: Refreshing state... [id=whattestvultr.dev]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Finally, just check that the output shows:

Outputs:

domain_date = "2023-02-21T20:02:52+00:00"

That should cover your use case but let me know if not!

@optik-aper optik-aper added question and removed bug labels Mar 3, 2023
@optik-aper optik-aper changed the title [BUG] - Declaring an already-existing domain is rejected, with no clear migration path [QUESTION] - Declaring an already-existing domain is rejected, with no clear migration path Mar 3, 2023
@optik-aper optik-aper self-assigned this Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants