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

Support for auth_settings in app service slot #3659

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
38 changes: 38 additions & 0 deletions azurerm/resource_arm_app_service_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func resourceArmAppServiceSlot() *schema.Resource {

"site_config": azure.SchemaAppServiceSiteConfig(),

"auth_settings": azure.SchemaAppServiceAuthSettings(),

"client_affinity_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -245,6 +247,17 @@ func resourceArmAppServiceSlotCreate(d *schema.ResourceData, meta interface{}) e

d.SetId(*read.ID)

authSettingsRaw := d.Get("auth_settings").([]interface{})
authSettings := azure.ExpandAppServiceAuthSettings(authSettingsRaw)

auth := web.SiteAuthSettings{
ID: read.ID,
SiteAuthSettingsProperties: &authSettings}

if _, err := client.UpdateAuthSettingsSlot(ctx, resGroup, appServiceName, auth, slot); err != nil {
return fmt.Errorf("Error updating auth settings for App Service %q/%q (Resource Group %q): %+s", appServiceName, slot, resGroup, err)
}

return resourceArmAppServiceSlotUpdate(d, meta)
}

Expand Down Expand Up @@ -289,6 +302,7 @@ func resourceArmAppServiceSlotUpdate(d *schema.ResourceData, meta interface{}) e
if err != nil {
return err
}

if d.HasChange("site_config") {
// update the main configuration
siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
Expand All @@ -300,6 +314,20 @@ func resourceArmAppServiceSlotUpdate(d *schema.ResourceData, meta interface{}) e
}
}

if d.HasChange("auth_settings") {
authSettingsRaw := d.Get("auth_settings").([]interface{})
authSettingsProperties := azure.ExpandAppServiceAuthSettings(authSettingsRaw)
id := d.Id()
authSettings := web.SiteAuthSettings{
ID: &id,
SiteAuthSettingsProperties: &authSettingsProperties,
}

if _, err := client.UpdateAuthSettingsSlot(ctx, resGroup, appServiceName, authSettings, slot); err != nil {
return fmt.Errorf("Error updating Authentication Settings for App Service %q: %+v", appServiceName, err)
}
}

if d.HasChange("client_affinity_enabled") {
affinity := d.Get("client_affinity_enabled").(bool)
sitePatchResource := web.SitePatchResource{
Expand Down Expand Up @@ -374,6 +402,11 @@ func resourceArmAppServiceSlotRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error making Read request on AzureRM App Service Slot Configuration %q/%q: %+v", appServiceName, slot, err)
}

authResp, err := client.GetAuthSettingsSlot(ctx, resGroup, appServiceName, slot)
if err != nil {
return fmt.Errorf("Error retrieving the AuthSettings for App Service %q/%q (Resource Group %q): %+v", appServiceName, slot, resGroup, err)
}

appSettingsResp, err := client.ListApplicationSettingsSlot(ctx, resGroup, appServiceName, slot)
if err != nil {
if utils.ResponseWasNotFound(appSettingsResp.Response) {
Expand Down Expand Up @@ -429,6 +462,11 @@ func resourceArmAppServiceSlotRead(d *schema.ResourceData, meta interface{}) err
return err
}

authSettings := azure.FlattenAppServiceAuthSettings(authResp.SiteAuthSettingsProperties)
if err := d.Set("auth_settings", authSettings); err != nil {
return fmt.Errorf("Error setting `auth_settings`: %+s", err)
}

siteCred := flattenAppServiceSiteCredential(siteCredResp.UserProperties)
if err := d.Set("site_credential", siteCred); err != nil {
return err
Expand Down
Loading