Skip to content

netlify_site_domain_settings_changes fix update in place without changes #121

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

werwolfby
Copy link

@werwolfby werwolfby commented Jun 26, 2025

This error fixes state when I specify netlify_site_domain_settings_changes resource like this:

resource "netlify_site_domain_settings" "my_site" {
  site_id                      = data.netlify_site.my_site.id
  custom_domain       = "www.my.site"
}

This cause changes on each plan/apply:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # netlify_site_domain_settings.my_site will be updated in-place
  ~ resource "netlify_site_domain_settings" "my_site" {
      ~ last_updated                 = "Wednesday, 25-Jun-25 22:58:25 PDT" -> (known after apply)
        # (5 unchanged attributes hidden)
    }

This changes fixes the issue.

This pull request improves the handling of optional fields in the site_domain_settings resource by ensuring null values are explicitly managed and adds a new test case to prevent configuration drift. The changes enhance both the functionality and reliability of the resource.

Enhancements to site_domain_settings resource:

  • Updated the Read method in internal/provider/site_domain_settings_resource.go to explicitly set optional fields (CustomDomain, BranchDeployCustomDomain, and DeployPreviewCustomDomain) to StringNull when they are not provided by the API. This ensures consistent state representation for optional fields.

New test case for preventing configuration drift:

  • Added a new test function TestAccSiteDomainSettingsNullFields in internal/provider/site_domain_settings_resource_test.go. This test verifies that optional fields remain null when not set and ensures no drift occurs when reapplying the same configuration. It also includes an import verification step.

Fix constant drift detection in netlify_site_domain_settings by properly
handling null values from the API. The Read function now correctly sets
null values for empty optional fields instead of converting them to
empty strings, preventing Terraform from detecting false differences.
@werwolfby werwolfby requested a review from a team as a code owner June 26, 2025 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant