Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions integration/v4_to_v5/testdata/zone/expected/zone_cross_refs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Cross-file references to cloudflare_zone.*.zone
# These should be rewritten to .name after migration



# Pattern: .zone reference in a local
locals {
cftftest_zone_domain = cloudflare_zone.minimal.name
}

# Pattern: Direct .zone reference in another resource
resource "cloudflare_dns_record" "cftftest_zone_ref" {
zone_id = cloudflare_zone.minimal.id
name = cloudflare_zone.minimal.name
type = "CNAME"
content = "example.com"
ttl = 1
}

moved {
from = cloudflare_record.cftftest_zone_ref
to = cloudflare_dns_record.cftftest_zone_ref
}

# Pattern: .zone reference in string interpolation
resource "cloudflare_dns_record" "cftftest_zone_interpolation" {
zone_id = cloudflare_zone.minimal.id
name = "cftftest-sub.${cloudflare_zone.minimal.name}"
type = "CNAME"
content = "example.com"
ttl = 1
}

moved {
from = cloudflare_record.cftftest_zone_interpolation
to = cloudflare_dns_record.cftftest_zone_interpolation
}
23 changes: 23 additions & 0 deletions integration/v4_to_v5/testdata/zone/input/zone_cross_refs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Cross-file references to cloudflare_zone.*.zone
# These should be rewritten to .name after migration

# Pattern: Direct .zone reference in another resource
resource "cloudflare_record" "cftftest_zone_ref" {
zone_id = cloudflare_zone.minimal.id
name = cloudflare_zone.minimal.zone
type = "CNAME"
content = "example.com"
}

# Pattern: .zone reference in string interpolation
resource "cloudflare_record" "cftftest_zone_interpolation" {
zone_id = cloudflare_zone.minimal.id
name = "cftftest-sub.${cloudflare_zone.minimal.zone}"
type = "CNAME"
content = "example.com"
}

# Pattern: .zone reference in a local
locals {
cftftest_zone_domain = cloudflare_zone.minimal.zone
}
16 changes: 15 additions & 1 deletion internal/resources/zone/v4_to_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func (m *V4ToV5Migrator) GetResourceRename() ([]string, string) {
return []string{"cloudflare_zone"}, "cloudflare_zone"
}

// GetComputedAttributeMappings implements the ComputedAttributeMapper interface.
// In v4, the zone's domain was accessed as cloudflare_zone.example.zone.
// In v5, it's cloudflare_zone.example.name. This enables cross-file reference
// rewriting so that any resource referencing .zone gets updated to .name.
func (m *V4ToV5Migrator) GetComputedAttributeMappings() []transform.ComputedAttributeMapping {
return []transform.ComputedAttributeMapping{
{
OldResourceType: "cloudflare_zone",
OldAttribute: "zone",
NewResourceType: "cloudflare_zone",
NewAttribute: "name",
},
}
}

// TransformConfig handles configuration file transformations.
// Transformations:
// 1. zone → name
Expand Down Expand Up @@ -103,4 +118,3 @@ func (m *V4ToV5Migrator) setAccountNestedAttribute(body *hclwrite.Body, accountI
// Set the account attribute with the nested object
body.SetAttributeRaw("account", tokens)
}

Loading