From 6ef3b793897075fc620a1aad81088a538455f7e3 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Tue, 25 Aug 2020 11:53:19 +0100 Subject: [PATCH 1/3] add source control special case for ADO controlled apps --- azurerm/internal/services/web/app_service.go | 5 +---- .../internal/services/web/resource_arm_app_service.go | 9 +++++++-- .../internal/services/web/resource_arm_function_app.go | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/web/app_service.go b/azurerm/internal/services/web/app_service.go index 0eede91b3c5f..9e21b0ed791f 100644 --- a/azurerm/internal/services/web/app_service.go +++ b/azurerm/internal/services/web/app_service.go @@ -426,10 +426,7 @@ func schemaAppServiceSiteConfig() *schema.Schema { string(web.ScmTypeOneDrive), string(web.ScmTypeTfs), string(web.ScmTypeVSO), - // Not in the specs, but is set by Azure Pipelines - // https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureRmWebAppDeploymentV4/operations/AzureAppServiceUtility.ts#L19 - // upstream issue: https://github.com/Azure/azure-rest-api-specs/issues/5345 - "VSTSRM", + string(web.ScmTypeVSTSRM), }, false), }, diff --git a/azurerm/internal/services/web/resource_arm_app_service.go b/azurerm/internal/services/web/resource_arm_app_service.go index a3570549f6c2..1ebdc2e51163 100644 --- a/azurerm/internal/services/web/resource_arm_app_service.go +++ b/azurerm/internal/services/web/resource_arm_app_service.go @@ -377,6 +377,8 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error // If `source_control` is defined, we need to set site_config.0.scm_type to "None" or we cannot update it _, hasSourceControl := d.GetOk("source_control.0.repo_url") + scmType := web.ScmType("None") + if d.HasChange("site_config") || hasSourceControl { // update the main configuration siteConfig, err := expandAppServiceSiteConfig(d.Get("site_config")) @@ -387,7 +389,9 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error SiteConfig: siteConfig, } - if hasSourceControl { + scmType = siteConfig.ScmType + // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception + if hasSourceControl && scmType != web.ScmTypeVSTSRM { siteConfigResource.SiteConfig.ScmType = "None" } @@ -396,7 +400,8 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error } } - if hasSourceControl { + // Don't send source_control changes for ADO controlled Apps + if hasSourceControl && scmType != web.ScmTypeVSTSRM { sourceControlProperties := expandAppServiceSiteSourceControl(d) sourceControl := &web.SiteSourceControl{} sourceControl.SiteSourceControlProperties = sourceControlProperties diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index 95e2230e19f6..7e8c9f557a0d 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -458,6 +458,8 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro // repo_url is required by the API _, hasSourceControl := d.GetOk("source_control.0.repo_url") + scmType := web.ScmType("None") + if d.HasChange("site_config") || hasSourceControl { siteConfig, err := expandFunctionAppSiteConfig(d) if err != nil { @@ -467,7 +469,9 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro SiteConfig: &siteConfig, } - if hasSourceControl { + scmType = siteConfig.ScmType + // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception + if hasSourceControl && scmType != web.ScmTypeVSTSRM { siteConfigResource.SiteConfig.ScmType = "None" } @@ -476,7 +480,8 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro } } - if hasSourceControl { + // Don't send source_control changes for ADO controlled Apps + if hasSourceControl && scmType != web.ScmTypeVSTSRM { sourceControlProperties := expandAppServiceSiteSourceControl(d) sourceControl := &web.SiteSourceControl{} sourceControl.SiteSourceControlProperties = sourceControlProperties From 4058ea14b8e154fe0ddcc04fff58872ab7c63263 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Tue, 25 Aug 2020 11:53:19 +0100 Subject: [PATCH 2/3] add source control special case for ADO controlled apps --- azurerm/internal/services/web/app_service.go | 5 +---- .../internal/services/web/resource_arm_app_service.go | 9 +++++++-- .../internal/services/web/resource_arm_function_app.go | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/web/app_service.go b/azurerm/internal/services/web/app_service.go index 97224e1cb5e6..5bd7e2cf32e5 100644 --- a/azurerm/internal/services/web/app_service.go +++ b/azurerm/internal/services/web/app_service.go @@ -421,10 +421,7 @@ func schemaAppServiceSiteConfig() *schema.Schema { string(web.ScmTypeOneDrive), string(web.ScmTypeTfs), string(web.ScmTypeVSO), - // Not in the specs, but is set by Azure Pipelines - // https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureRmWebAppDeploymentV4/operations/AzureAppServiceUtility.ts#L19 - // upstream issue: https://github.com/Azure/azure-rest-api-specs/issues/5345 - "VSTSRM", + string(web.ScmTypeVSTSRM), }, false), }, diff --git a/azurerm/internal/services/web/resource_arm_app_service.go b/azurerm/internal/services/web/resource_arm_app_service.go index a3570549f6c2..1ebdc2e51163 100644 --- a/azurerm/internal/services/web/resource_arm_app_service.go +++ b/azurerm/internal/services/web/resource_arm_app_service.go @@ -377,6 +377,8 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error // If `source_control` is defined, we need to set site_config.0.scm_type to "None" or we cannot update it _, hasSourceControl := d.GetOk("source_control.0.repo_url") + scmType := web.ScmType("None") + if d.HasChange("site_config") || hasSourceControl { // update the main configuration siteConfig, err := expandAppServiceSiteConfig(d.Get("site_config")) @@ -387,7 +389,9 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error SiteConfig: siteConfig, } - if hasSourceControl { + scmType = siteConfig.ScmType + // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception + if hasSourceControl && scmType != web.ScmTypeVSTSRM { siteConfigResource.SiteConfig.ScmType = "None" } @@ -396,7 +400,8 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error } } - if hasSourceControl { + // Don't send source_control changes for ADO controlled Apps + if hasSourceControl && scmType != web.ScmTypeVSTSRM { sourceControlProperties := expandAppServiceSiteSourceControl(d) sourceControl := &web.SiteSourceControl{} sourceControl.SiteSourceControlProperties = sourceControlProperties diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index 062c519f0a94..7ce3205b42cd 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -458,6 +458,8 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro // repo_url is required by the API _, hasSourceControl := d.GetOk("source_control.0.repo_url") + scmType := web.ScmType("None") + if d.HasChange("site_config") || hasSourceControl { siteConfig, err := expandFunctionAppSiteConfig(d) if err != nil { @@ -467,7 +469,9 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro SiteConfig: &siteConfig, } - if hasSourceControl { + scmType = siteConfig.ScmType + // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception + if hasSourceControl && scmType != web.ScmTypeVSTSRM { siteConfigResource.SiteConfig.ScmType = "None" } @@ -476,7 +480,8 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro } } - if hasSourceControl { + // Don't send source_control changes for ADO controlled Apps + if hasSourceControl && scmType != web.ScmTypeVSTSRM { sourceControlProperties := expandAppServiceSiteSourceControl(d) sourceControl := &web.SiteSourceControl{} sourceControl.SiteSourceControlProperties = sourceControlProperties From ece80e94c1e0936d28848ca1b93553dd69b6e307 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 19 Sep 2020 11:11:29 -0700 Subject: [PATCH 3/3] address pr comments --- azurerm/internal/services/web/resource_arm_app_service.go | 4 ++-- azurerm/internal/services/web/resource_arm_function_app.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/web/resource_arm_app_service.go b/azurerm/internal/services/web/resource_arm_app_service.go index 1ebdc2e51163..1d6166525f67 100644 --- a/azurerm/internal/services/web/resource_arm_app_service.go +++ b/azurerm/internal/services/web/resource_arm_app_service.go @@ -377,7 +377,7 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error // If `source_control` is defined, we need to set site_config.0.scm_type to "None" or we cannot update it _, hasSourceControl := d.GetOk("source_control.0.repo_url") - scmType := web.ScmType("None") + scmType := web.ScmTypeNone if d.HasChange("site_config") || hasSourceControl { // update the main configuration @@ -392,7 +392,7 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error scmType = siteConfig.ScmType // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception if hasSourceControl && scmType != web.ScmTypeVSTSRM { - siteConfigResource.SiteConfig.ScmType = "None" + siteConfigResource.SiteConfig.ScmType = web.ScmTypeNone } if _, err := client.CreateOrUpdateConfiguration(ctx, id.ResourceGroup, id.Name, siteConfigResource); err != nil { diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index 7e8c9f557a0d..94666fc2c4a0 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -458,7 +458,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro // repo_url is required by the API _, hasSourceControl := d.GetOk("source_control.0.repo_url") - scmType := web.ScmType("None") + scmType := web.ScmTypeNone if d.HasChange("site_config") || hasSourceControl { siteConfig, err := expandFunctionAppSiteConfig(d) @@ -472,7 +472,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro scmType = siteConfig.ScmType // ScmType being set blocks the update of source_control in _most_ cases, ADO is an exception if hasSourceControl && scmType != web.ScmTypeVSTSRM { - siteConfigResource.SiteConfig.ScmType = "None" + siteConfigResource.SiteConfig.ScmType = web.ScmTypeNone } if _, err := client.CreateOrUpdateConfiguration(ctx, id.ResourceGroup, id.Name, siteConfigResource); err != nil {