-
Notifications
You must be signed in to change notification settings - Fork 626
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
Import process for cloudflare_record modifies the 'name' attribute #148
Comments
Thanks for the report @james-robson! I'm a touch confused here as I think there might be something else at play because we currently just shy of 1k DNS entries using this format via an import and we don't have the issue as above (we run the bleeding edge provider). I see your One option here is that we update the |
Hi @jacobbednarz, thanks for getting back to me. I'm unsure how I would preserve the ID, I had assumed that it was updating because the resource was changing (and therefore getting a new ID). From the Terraform import docs:
I'll have a play around with it and see if there is anything I can do to change that. |
Follow up - I removed the existing entry from Terraform with |
Alright, I managed to setup a reproducible case for this one and I have some answers. The TL;DR is that the My comment above regarding the ID changing was a bit of a red herring however it was caused by the We have a couple of options we could do here.
I don't think these are mutually exclusive to complete however it does feel like your usage of the field is unintended and we could prevent this with some better documentation. In the same breath, it wouldn't hurt to add better safety rails in the provider if someone does decide to put in the full domain. |
Actually, API accepts both bare label and FQDN as valid |
@patryk so your vote is for adding the |
Yeah, I suppose the least invasive way is what we need here. I'd go with |
When importing `cloudflare_record` resources the `name` attribute is trimmed[1] to exclude the `domain` value. This creates an issue if you import the resources but use the full the domain as the `name` attribute because the Terraform state file will never match what is stored and will result in continuious changes wanting to be applied. After a brief discussion on the issue[2], it was decided that instead of limiting to what can be passed into the `name` attribute, we should use a `DiffSuppressFunc` that will allow the partial labels and full FQDNs to work by trimming the zone name as a part of the comparison. This will be the least amount of friction and maintain full backwards compatibility. Fixes #148. [1]: https://github.com/terraform-providers/terraform-provider-cloudflare/blob/ef8e9abfdb12bfd200520771792089c2a7129af0/cloudflare/resource_cloudflare_record.go#L513 [2]: https://github.com/terraform-providers/terraform-provider-cloudflare/issues/148#issuecomment-438507279
🆒 #151 should get us what we're after here. @james-robson do you mind taking that PR for a test and make sure it addresses your issue too? |
When importing `cloudflare_record` resources the `name` attribute is trimmed[1] to exclude the `domain` value. This creates an issue if you import the resources but use the full the domain as the `name` attribute because the Terraform state file will never match what is stored and will result in continuious changes wanting to be applied. After a brief discussion on the issue[2], it was decided that instead of limiting to what can be passed into the `name` attribute, we should use a `DiffSuppressFunc` that will allow the partial labels and full FQDNs to work by trimming the zone name as a part of the comparison. This will be the least amount of friction and maintain full backwards compatibility. Fixes #148. [1]: https://github.com/terraform-providers/terraform-provider-cloudflare/blob/ef8e9abfdb12bfd200520771792089c2a7129af0/cloudflare/resource_cloudflare_record.go#L513 [2]: https://github.com/terraform-providers/terraform-provider-cloudflare/issues/148#issuecomment-438507279
Merged already, but please @james-robson check it out whether it fixes your issue. |
Thanks for the quick turnaround @jacobbednarz and @patryk, I'll test this out ASAP and let you know the outcome. |
@jacobbednarz, @patryk - I managed to get the plugin working by building from master and checking it in to my One thing that did cause issues for me (and the reason it took me a while to get back to you) was that I initially ran into another issue where the plan output failed saying the terraform-cloudflare-provider file was missing. It turned out to be the same issue as this other provider: hashicorp/terraform-provider-helm#111 I had to re-build the provider with I'm not sure whether this is something that should be in the README or the makefile, what are your thoughts? |
This is something that has cropped up in a few other go projects I work on and it's commonly due to relying on Alpine linux as it is now using musl libc. Using I'm +1 for opening a PR documenting this but on the fence about having it as a default without further investigation. |
@jacobbednarz you are absolutely right, as I'm on a Mac I used a golang:alpine Docker container to build the Linux binary. That's good information, thanks for getting back to me. I'll try and get a PR up for the README note today. |
Terraform Version
0.11.8
Affected Resource(s)
Terraform Configuration Files
General description
When importing a cloudflare record the import seems to work OK. However if you run a plan immediately after the import the plan shows that the record should be destroyed and re-created because the name has changed. This appears to be because the name in question contains the zone name (see the example below) and the zone name is trimmed. I'm not sure if there is a specific reason for removing the zone name from the record name but that is what causes the issue.
Expected Behavior
Importing a cloudflare record into Terraform creates a new entry in the state file. Running plan immediately after shows no changes.
Actual Behavior
Importing the record works OK, however if you run a plan the name has been modified (the suffix has been removed) which causes a new record to be created. The plan output looks as follows:
Steps to Reproduce
foo.example.com
terraform import cloudflare_record.example example.com/1234abcd
foo
instead offoo.example.com
Important Factoids
This is happening because of lines 512 and 513 in
resource_cloudflare_record.go
which appears to trim the zone name from the record.Name value:I'd like to know if there is a reason for this trim as it looks intentional. If so we would have to change our naming convention for all domain records in cloudflare.
The text was updated successfully, but these errors were encountered: