cloudflare / terraform-provider-cloudflare

Cloudflare Terraform Provider
https://registry.terraform.io/providers/cloudflare/cloudflare
Mozilla Public License 2.0
766 stars 591 forks source link

cloudflare_regional_hostname fail to update #2856

Open PierreBart opened 11 months ago

PierreBart commented 11 months ago

Confirmation

Terraform and Cloudflare provider version

Terraform v1.5.3
on darwin_arm64
+ provider registry.terraform.io/cloudflare/cloudflare v4.16.0

Affected resource(s)

Terraform configuration files

data "cloudflare_zone" "zone" {
  name = "your_zone_id"
}

resource "cloudflare_record" "test" {
  name    = "test-1"
  proxied = true
  ttl     = 1
  type    = "A"
  value   = "192.0.2.1"
  zone_id = data.cloudflare_zone.zone.id
}

resource "cloudflare_regional_hostname" "test" {
  hostname   = cloudflare_record.test.hostname
  region_key = "isoeu"
  zone_id    = data.cloudflare_zone.zone.id
}

Link to debug output

https://gist.github.com/PierreBart/1082528e73e04faca66d7ce4c55dd0fd

Panic output

No response

Expected output

Updating the cloudflare_record.test.name attribute, and applying the new configuration recreates the resource and updates the cloudflare_record.cloudflare_regional_hostname resource in place.

Actual output

The apply command fails with error:

2023-10-17T12:02:36.507+0200 [ERROR] vertex "cloudflare_regional_hostname.test" error: not_found (1000)
╷
│ Error: not_found (1000)
│
│   with cloudflare_regional_hostname.test,
│   on test.tf line 14, in resource "cloudflare_regional_hostname" "test":
│   14: resource "cloudflare_regional_hostname" "test" {
│

Steps to reproduce

  1. Apply the Terraform configuration files I provided;
  2. Update the cloudflare_record.test.name value;
  3. Apply the new configuration;

Additional factoids

It seems that after the record is deleted, the regional_hostname resource is deleted from Cloudflare as well. However, the resource is still in the state and terraform tries to retrieve it but Cloudflare query fails with error 1000.

Subsequent terraform plan commands also fail with the same error.

From the API documentation, it seems that we can only patch the region attribute, not the hostname: https://developers.cloudflare.com/data-localization/regional-services/get-started/

I guess that the update of the hostname attribute should require the replacement of the resource rather than an in-place update.

References

No response

github-actions[bot] commented 11 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

luisrx7 commented 2 months ago

I'm currently using the latest Terraform and Cloudflare provider, but this issue persists.

In my use case, I only need to set up regional hostnames for records manually created in the past. The problem arises when I create a cloudflare_regional_hostname for a record like test.xpto.com, which works well. However, if that record gets deleted outside of Terraform, subsequent plan/apply operations fail with a not_found (1,000) error, and I need to manually remove the corresponding cloudflare_regional_hostname from the state. From my perspective, I expected Terraform to detect the drift and report it.