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

[Bug:] azurerm_cdn_frontdoor_route - cdn_frontdoor_origin_path gets removed on update if unchanged. #24488

Merged
merged 2 commits into from
Jan 13, 2024
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
7 changes: 5 additions & 2 deletions internal/services/cdn/cdn_frontdoor_route_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,12 @@ func resourceCdnFrontDoorRouteUpdate(d *pluginsdk.ResourceData, meta interface{}
}
}

// NOTE: You need to always pass these two on update else you will
// disable your cache and disassociate your custom domains...
// NOTE: You need to always pass these three on update else you will
// disable your cache, disassociate your custom domains or remove your origin path...
updateProps := azuresdkhacks.RouteUpdatePropertiesParameters{
CustomDomains: existing.RouteProperties.CustomDomains,
CacheConfiguration: existing.RouteProperties.CacheConfiguration,
OriginPath: existing.RouteProperties.OriginPath,
}

if d.HasChange("cache") {
Expand Down Expand Up @@ -491,6 +492,8 @@ func resourceCdnFrontDoorRouteUpdate(d *pluginsdk.ResourceData, meta interface{}
}

if d.HasChange("cdn_frontdoor_origin_path") {
updateProps.OriginPath = nil

originPath := d.Get("cdn_frontdoor_origin_path").(string)
if originPath != "" {
updateProps.OriginPath = utils.String(originPath)
Expand Down
46 changes: 46 additions & 0 deletions internal/services/cdn/cdn_frontdoor_route_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ func TestAccCdnFrontDoorRoute_update(t *testing.T) {
})
}

func TestAccCdnFrontDoorRoute_originPath(t *testing.T) {
// regression test case for issue #24466
data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_route", "test")
r := CdnFrontDoorRouteResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeNoCache(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("cdn_frontdoor_origin_path").HasValue("/example"),
),
},
data.ImportStep("cdn_frontdoor_origin_group_id", "cdn_frontdoor_origin_ids"),
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("cdn_frontdoor_origin_path").HasValue("/example"),
),
},
data.ImportStep("cdn_frontdoor_origin_group_id", "cdn_frontdoor_origin_ids"),
})
}

func (r CdnFrontDoorRouteResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.FrontDoorRouteID(state.ID)
if err != nil {
Expand Down Expand Up @@ -216,6 +240,28 @@ resource "azurerm_cdn_frontdoor_route" "test" {
`, template, data.RandomInteger)
}

func (r CdnFrontDoorRouteResource) completeNoCache(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s

resource "azurerm_cdn_frontdoor_route" "test" {
name = "accTestRoute-%d"
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.test.id
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.test.id
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.test.id]
cdn_frontdoor_rule_set_ids = [azurerm_cdn_frontdoor_rule_set.test.id]
cdn_frontdoor_origin_path = "/example"

enabled = true
forwarding_protocol = "HttpsOnly"
https_redirect_enabled = true
patterns_to_match = ["/*"]
supported_protocols = ["Http", "Https"]
}
`, template, data.RandomInteger)
}

func (r CdnFrontDoorRouteResource) update(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down
Loading