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_logic_app_standard - fix setting public_network_access for conflicting API properties #28465

Merged
merged 3 commits into from
Jan 13, 2025
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
42 changes: 32 additions & 10 deletions internal/services/logic/logic_app_standard_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ func resourceLogicAppStandardCreate(d *pluginsdk.ResourceData, meta interface{})
}

publicNetworkAccess := d.Get("public_network_access").(string)
if !features.FivePointOhBeta() && publicNetworkAccess == "" {
if !features.FivePointOhBeta() {
// if a user is still using `site_config.public_network_access_enabled` we should be setting `public_network_access` for them
publicNetworkAccess = helpers.PublicNetworkAccessEnabled
publicNetworkAccess = reconcilePNA(d)
if v := siteEnvelope.Properties.SiteConfig.PublicNetworkAccess; v != nil && *v == helpers.PublicNetworkAccessDisabled {
publicNetworkAccess = helpers.PublicNetworkAccessDisabled
}
Expand Down Expand Up @@ -379,6 +379,7 @@ func resourceLogicAppStandardCreate(d *pluginsdk.ResourceData, meta interface{})
}

d.SetId(id.ID())

return resourceLogicAppStandardUpdate(d, meta)
}

Expand Down Expand Up @@ -455,6 +456,10 @@ func resourceLogicAppStandardUpdate(d *pluginsdk.ResourceData, meta interface{})
}
}

if !features.FivePointOhBeta() { // Until 5.0 the site_config value of this must be reflected back into the top-level property if not set there
siteConfig.PublicNetworkAccess = pointer.To(reconcilePNA(d))
}

if clientCertEnabled {
siteEnvelope.Properties.ClientCertMode = pointer.To(webapps.ClientCertMode(clientCertMode))
}
Expand Down Expand Up @@ -484,7 +489,7 @@ func resourceLogicAppStandardUpdate(d *pluginsdk.ResourceData, meta interface{})
return fmt.Errorf("updating %s: %+v", *id, err)
}

if d.HasChange("site_config") { // update siteConfig before appSettings in case the appSettings get covered by basicAppSettings
if d.HasChange("site_config") || (d.HasChange("public_network_access") && !features.FivePointOhBeta()) { // update siteConfig before appSettings in case the appSettings get covered by basicAppSettings
siteConfigResource := webapps.SiteConfigResource{
Properties: &siteConfig,
}
Expand Down Expand Up @@ -1367,13 +1372,7 @@ func expandLogicAppStandardSiteConfig(d *pluginsdk.ResourceData) (webapps.SiteCo
}

if !features.FivePointOhBeta() {
if v, ok := config["public_network_access_enabled"]; ok {
pna := helpers.PublicNetworkAccessEnabled
if !v.(bool) {
pna = helpers.PublicNetworkAccessDisabled
}
siteConfig.PublicNetworkAccess = pointer.To(pna)
}
siteConfig.PublicNetworkAccess = pointer.To(reconcilePNA(d))
}

return siteConfig, nil
Expand Down Expand Up @@ -1555,3 +1554,26 @@ func expandHeaders(input interface{}) map[string][]string {

return output
}

func reconcilePNA(d *pluginsdk.ResourceData) string {
pna := ""
scPNASet := true
if !d.GetRawConfig().AsValueMap()["public_network_access"].IsNull() { // is top level set, takes precedence
pna = d.Get("public_network_access").(string)
}
if sc := d.GetRawConfig().AsValueMap()["site_config"]; !sc.IsNull() {
if len(sc.AsValueSlice()) > 0 && !sc.AsValueSlice()[0].AsValueMap()["public_network_access_enabled"].IsNull() {
scPNASet = true
}
}
if pna == "" && scPNASet { // if not, or it's empty, is site_config value set
pnaBool := d.Get("site_config.0.public_network_access_enabled").(bool)
if pnaBool {
pna = helpers.PublicNetworkAccessEnabled
} else {
pna = helpers.PublicNetworkAccessDisabled
}
}

return pna
}
13 changes: 13 additions & 0 deletions internal/services/logic/logic_app_standard_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ func TestAccLogicAppStandard_publicNetworkAccessDisabled(t *testing.T) {
Config: r.publicNetworkAccess(data, "Disabled"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Disabled"),
check.That(data.ResourceName).Key("site_config.0.public_network_access_enabled").HasValue("false"),
),
},
data.ImportStep(),
{
Config: r.publicNetworkAccess(data, "Enabled"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Enabled"),
check.That(data.ResourceName).Key("site_config.0.public_network_access_enabled").HasValue("true"),
),
},
data.ImportStep(),
{
Config: r.publicNetworkAccess(data, "Disabled"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Disabled"),
check.That(data.ResourceName).Key("site_config.0.public_network_access_enabled").HasValue("false"),
),
},
data.ImportStep(),
Expand Down
Loading