Skip to content
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

azurerm_static_site_custom_domain - set validation_token in create instead of read #22848

Merged
merged 1 commit into from
Aug 8, 2023
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
14 changes: 10 additions & 4 deletions internal/services/web/static_site_custom_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2021-02-01/web" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/web/parse"
Expand Down Expand Up @@ -161,6 +162,15 @@ func resourceStaticSiteCustomDomainCreateOrUpdate(d *pluginsdk.ResourceData, met
}
}

// we set `validation_token` into state here since it's removed from the API once it's been validated
// setting it in the read would overwrite the value with an empty string and cause a diff, since this
// is not a user specifiable field we don't need to be concerned with it at import time either
resp, err := client.GetStaticSiteCustomDomain(ctx, staticSiteId.ResourceGroup, id.StaticSiteName, id.CustomDomainName)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
}
d.Set("validation_token", pointer.From(resp.ValidationToken))

d.SetId(id.ID())
stephybun marked this conversation as resolved.
Show resolved Hide resolved

return resourceStaticSiteCustomDomainRead(d, meta)
Expand Down Expand Up @@ -188,10 +198,6 @@ func resourceStaticSiteCustomDomainRead(d *pluginsdk.ResourceData, meta interfac
d.Set("domain_name", id.CustomDomainName)
d.Set("static_site_id", parse.NewStaticSiteID(id.SubscriptionId, id.ResourceGroup, id.StaticSiteName).ID())

if props := resp.StaticSiteCustomDomainOverviewARMResourceProperties; props != nil {
d.Set("validation_token", resp.ValidationToken)
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAccAzureStaticSiteCustomDomain_basic(t *testing.T) {
check.That(data.ResourceName).Key("validation_token").Exists(),
),
},
data.ImportStep("validation_type"),
data.ImportStep("validation_type", "validation_token"),
})
}

Expand Down
Loading