Skip to content

Commit

Permalink
Merge pull request #2831 from joakimhew/feature/app_service_site_auth…
Browse files Browse the repository at this point in the history
…_settings

azurerm_app_service: Adds authentication support
  • Loading branch information
tombuildsstuff authored May 22, 2019
2 parents 4509a41 + 5a9e7fc commit ef1914f
Show file tree
Hide file tree
Showing 16 changed files with 1,958 additions and 97 deletions.
550 changes: 550 additions & 0 deletions azurerm/helpers/azure/app_service.go

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func resourceArmAppService() *schema.Resource {

"site_config": azure.SchemaAppServiceSiteConfig(),

"auth_settings": azure.SchemaAppServiceAuthSettings(),

"client_affinity_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -279,6 +281,17 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error

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.UpdateAuthSettings(ctx, resGroup, name, auth); err != nil {
return fmt.Errorf("Error updating auth settings for App Service %q (Resource Group %q): %+s", name, resGroup, err)
}

return resourceArmAppServiceUpdate(d, meta)
}

Expand Down Expand Up @@ -338,6 +351,20 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
}
}

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.UpdateAuthSettings(ctx, resGroup, name, authSettings); err != nil {
return fmt.Errorf("Error updating Authentication Settings for App Service %q: %+v", name, err)
}
}

if d.HasChange("client_affinity_enabled") {

affinity := d.Get("client_affinity_enabled").(bool)
Expand Down Expand Up @@ -433,6 +460,11 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error making Read request on AzureRM App Service Configuration %q: %+v", name, err)
}

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

appSettingsResp, err := client.ListApplicationSettings(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(appSettingsResp.Response) {
Expand Down Expand Up @@ -496,6 +528,11 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
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)
}

scm := flattenAppServiceSourceControl(scmResp.SiteSourceControlProperties)
if err := d.Set("source_control", scm); err != nil {
return err
Expand Down
Loading

0 comments on commit ef1914f

Please sign in to comment.