@@ -54,3 +54,44 @@ func TestAccSiteDomainSettings(t *testing.T) {
54
54
},
55
55
}, func (s * terraform.State ) error { return nil })
56
56
}
57
+
58
+ func TestAccSiteDomainSettingsNullFields (t * testing.T ) {
59
+ // Test case for preventing drift when optional fields are null from API
60
+ accTest (t , []resource.TestStep {
61
+ {
62
+ Config : `resource "netlify_site_domain_settings" "null_fields" {
63
+ site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26"
64
+ custom_domain = "tf-test-null-fields.examplepetstore.com"
65
+ }` ,
66
+ Check : resource .ComposeAggregateTestCheckFunc (
67
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "site_id" , "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" ),
68
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "custom_domain" , "tf-test-null-fields.examplepetstore.com" ),
69
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "domain_aliases.#" , "0" ),
70
+ // These should be null/empty when not set
71
+ resource .TestCheckNoResourceAttr ("netlify_site_domain_settings.null_fields" , "branch_deploy_custom_domain" ),
72
+ resource .TestCheckNoResourceAttr ("netlify_site_domain_settings.null_fields" , "deploy_preview_custom_domain" ),
73
+ ),
74
+ },
75
+ {
76
+ // Second step with same config should not detect changes (no drift)
77
+ Config : `resource "netlify_site_domain_settings" "null_fields" {
78
+ site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26"
79
+ custom_domain = "tf-test-null-fields.examplepetstore.com"
80
+ }` ,
81
+ PlanOnly : true ,
82
+ Check : resource .ComposeAggregateTestCheckFunc (
83
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "site_id" , "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" ),
84
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "custom_domain" , "tf-test-null-fields.examplepetstore.com" ),
85
+ resource .TestCheckResourceAttr ("netlify_site_domain_settings.null_fields" , "domain_aliases.#" , "0" ),
86
+ ),
87
+ },
88
+ {
89
+ ResourceName : "netlify_site_domain_settings.null_fields" ,
90
+ ImportState : true ,
91
+ ImportStateId : "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" ,
92
+ ImportStateVerifyIdentifierAttribute : "site_id" ,
93
+ ImportStateVerify : true ,
94
+ ImportStateVerifyIgnore : []string {"last_updated" },
95
+ },
96
+ }, func (s * terraform.State ) error { return nil })
97
+ }
0 commit comments