Skip to content

Commit

Permalink
add source control special case for ADO controlled apps
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Aug 25, 2020
1 parent 8c52648 commit 6ef3b79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 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 @@ -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),
},

Expand Down
9 changes: 7 additions & 2 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.ScmType("None")

if d.HasChange("site_config") || hasSourceControl {
// update the main configuration
siteConfig, err := expandAppServiceSiteConfig(d.Get("site_config"))
Expand All @@ -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"
}

Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 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.ScmType("None")

if d.HasChange("site_config") || hasSourceControl {
siteConfig, err := expandFunctionAppSiteConfig(d)
if err != nil {
Expand All @@ -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"
}

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

0 comments on commit 6ef3b79

Please sign in to comment.