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_app_service && azurerm_function_app - don't try to manage source_control when scm_type is VSTSRM #8531

Merged
merged 4 commits into from
Sep 21, 2020
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
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