Skip to content

Commit

Permalink
Merge pull request #8531 from terraform-providers/b/app-service-ado-bug
Browse files Browse the repository at this point in the history
`azurerm_app_service` && `azurerm_function_app` - don't try to manage source_control when scm_type is `VSTSRM`
  • Loading branch information
tombuildsstuff authored Sep 21, 2020
2 parents ae075dd + 5f956cc commit 0a92989
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 1 addition & 4 deletions azurerm/internal/services/web/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},

Expand Down
11 changes: 8 additions & 3 deletions azurerm/internal/services/web/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ScmTypeNone

if d.HasChange("site_config") || hasSourceControl {
// update the main configuration
siteConfig, err := expandAppServiceSiteConfig(d.Get("site_config"))
Expand All @@ -387,16 +389,19 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
SiteConfig: siteConfig,
}

if hasSourceControl {
siteConfigResource.SiteConfig.ScmType = "None"
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 = web.ScmTypeNone
}

if _, err := client.CreateOrUpdateConfiguration(ctx, id.ResourceGroup, id.Name, siteConfigResource); err != nil {
return fmt.Errorf("Error updating Configuration for App Service %q: %+v", id.Name, err)
}
}

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
Expand Down
11 changes: 8 additions & 3 deletions azurerm/internal/services/web/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ScmTypeNone

if d.HasChange("site_config") || hasSourceControl {
siteConfig, err := expandFunctionAppSiteConfig(d)
if err != nil {
Expand All @@ -467,16 +469,19 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro
SiteConfig: &siteConfig,
}

if hasSourceControl {
siteConfigResource.SiteConfig.ScmType = "None"
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 = web.ScmTypeNone
}

if _, err := client.CreateOrUpdateConfiguration(ctx, id.ResourceGroup, id.Name, siteConfigResource); err != nil {
return fmt.Errorf("Error updating Configuration for Function App %q: %+v", id.Name, err)
}
}

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
Expand Down

0 comments on commit 0a92989

Please sign in to comment.