ovh / terraform-provider-ovh

Terraform OVH provider
https://registry.terraform.io/providers/ovh/ovh/latest/docs
Mozilla Public License 2.0
182 stars 133 forks source link

[BUG] ovh_domain_zone_record: can't use ttl default value of '0' #666

Closed markus-volkert-mint closed 2 months ago

markus-volkert-mint commented 2 months ago

Describe the bug

When a DNS zone record is defined in terraform where the terraform TTL is identical to the default TTL for the DNS zone in OVH, duplicated records are created. Cause is most likely, that OVH internally represents records that use the default TTL with a TTL of '0'. In the "ovh_domain_zone_record" resource, TTL is required to be > 60, and thus cannot be set to '0'.

Terraform Version

code Terraform v1.8.4 on windows_amd64 code

OVH Terraform Provider Version

code .\terraform.exe init

Initializing the backend...

Initializing provider plugins...

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

terraform {
  required_providers {
    ovh = {
      source = "ovh/ovh"
    }
  }
}

provider "ovh" {
  endpoint           = "ovh-eu"
  application_key    = "****"
  application_secret = "****"
  consumer_key       = "****"
}

resource "ovh_domain_zone_record" "test" {
  zone      = "<dns-zone-name>"
  subdomain = "test"
  fieldtype = "A"
  ttl       = 3600
  target    = "<some ip>"
}

Debug Output

No debug info available.

Panic Output

No panic output.

Expected Behavior

The provider should have noticed that there already is a matching domain zone record and not have created a second entry.

Actual Behavior

A second domain zone record has been created with a TTL of 3600, although a record already existed with a TTL of '0', which represents the default, which is '3600'.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create an "ovh_domain_zone_record" for a DNS entry that has been created in the web-UI and that uses the default TTL of the DNS zone
  2. terraform apply
rbeuque74 commented 2 months ago

Hello @markus-volkert-mint,

If I understand your issue correctly, you have currently two issues:

On the first issue, this is a problem on the provider side and we will address this. On the second issue, this is not how the provider and the OVHcloud API work. If you want to handle a previously created DNS zone record using Terraform, you should use the import statement in order to have the resource handled by Terraform. After we fix the first issue, you will still have duplicates if you create the same record than you created on the UI, and that would be normal. You need to use the import statement for that.

Feel free to correct if we misunderstood stuff here. In the mean time, I will change the title of this issue and it will be picked-up by someone on my team.

Thanks Romain

markus-volkert-mint commented 2 months ago

Hi @rbeuque74,

thanks for getting back so quickly and clarifying! I'm new to terraform and had not understood that I had to import existing DNS records before being able to manage them via terraform. I believed it was a result of the existing record and the terraform managed record having different ttls.

So, allowing the ttl to be 0 to make use of the default values will be good, but won't actually solve the issue with the duplicated entries, that was simply user-failure..

Thanks for pointing me in the right direction!

Thanks Markus