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

App Service refactor and feature alignment #7945

Merged
merged 17 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
1,939 changes: 0 additions & 1,939 deletions azurerm/helpers/azure/app_service.go

This file was deleted.

1,877 changes: 1,853 additions & 24 deletions azurerm/internal/services/web/app_service.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azure
package web

import (
"time"
Expand All @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func SchemaAppServiceBackup() *schema.Schema {
func schemaAppServiceBackup() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -87,7 +87,7 @@ func SchemaAppServiceBackup() *schema.Schema {
}
}

func ExpandAppServiceBackup(input []interface{}) *web.BackupRequest {
func expandAppServiceBackup(input []interface{}) *web.BackupRequest {
if len(input) == 0 {
return nil
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func ExpandAppServiceBackup(input []interface{}) *web.BackupRequest {
return request
}

func FlattenAppServiceBackup(input *web.BackupRequestProperties) []interface{} {
func flattenAppServiceBackup(input *web.BackupRequestProperties) []interface{} {
if input == nil {
return []interface{}{}
}
Expand Down
130 changes: 130 additions & 0 deletions azurerm/internal/services/web/app_service_site_source_control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package web

import (
"log"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func schemaAppServiceSiteSourceControl() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
ConflictsWith: []string{"site_config.0.scm_type"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repo_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"branch": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"manual_integration": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"use_mercurial": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"rollback_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
}
}

func schemaDataSourceAppServiceSiteSourceControl() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repo_url": {
Type: schema.TypeString,
Computed: true,
},

"branch": {
Type: schema.TypeString,
Computed: true,
},

"manual_integration": {
Type: schema.TypeBool,
Computed: true,
},

"use_mercurial": {
Type: schema.TypeBool,
Computed: true,
},

"rollback_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
}
}

func expandAppServiceSiteSourceControl(d *schema.ResourceData) *web.SiteSourceControlProperties {
sourceControlRaw := d.Get("source_control").([]interface{})
sourceControl := sourceControlRaw[0].(map[string]interface{})

result := &web.SiteSourceControlProperties{
RepoURL: utils.String(sourceControl["repo_url"].(string)),
Branch: utils.String(sourceControl["branch"].(string)),
IsManualIntegration: utils.Bool(sourceControl["manual_integration"].(bool)),
IsMercurial: utils.Bool(sourceControl["use_mercurial"].(bool)),
DeploymentRollbackEnabled: utils.Bool(sourceControl["rollback_enabled"].(bool)),
}

return result
}

func flattenAppServiceSourceControl(input *web.SiteSourceControlProperties) []interface{} {
results := make([]interface{}, 0)
result := make(map[string]interface{})

if input == nil {
log.Printf("[DEBUG] SiteSourceControlProperties is nil")
return results
}

if input.RepoURL != nil && *input.RepoURL != "" {
result["repo_url"] = *input.RepoURL
}

if input.Branch != nil && *input.Branch != "" {
result["branch"] = *input.Branch
} else {
result["branch"] = "master"
}

result["use_mercurial"] = *input.IsMercurial

result["manual_integration"] = *input.IsManualIntegration

result["rollback_enabled"] = *input.DeploymentRollbackEnabled

return append(results, result)
}
21 changes: 3 additions & 18 deletions azurerm/internal/services/web/data_source_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func dataSourceArmAppService() *schema.Resource {
Computed: true,
},

"site_config": azure.SchemaAppServiceDataSourceSiteConfig(),
"site_config": schemaAppServiceDataSourceSiteConfig(),

"client_affinity_enabled": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -122,22 +122,7 @@ func dataSourceArmAppService() *schema.Resource {
Computed: true,
},

"source_control": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repo_url": {
Type: schema.TypeString,
Computed: true,
},
"branch": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"source_control": schemaDataSourceAppServiceSiteSourceControl(),
},
}
}
Expand Down Expand Up @@ -216,7 +201,7 @@ func dataSourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error
return err
}

siteConfig := azure.FlattenAppServiceSiteConfig(configResp.SiteConfig)
siteConfig := flattenAppServiceSiteConfig(configResp.SiteConfig)
if err := d.Set("site_config", siteConfig); err != nil {
return err
}
Expand Down
49 changes: 36 additions & 13 deletions azurerm/internal/services/web/data_source_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ func dataSourceArmFunctionApp() *schema.Resource {
Computed: true,
},

"os_type": {
Type: schema.TypeString,
Computed: true,
},

"outbound_ip_addresses": {
Type: schema.TypeString,
Computed: true,
},

"possible_outbound_ip_addresses": {
Type: schema.TypeString,
Computed: true,
},

"site_credential": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -96,20 +111,9 @@ func dataSourceArmFunctionApp() *schema.Resource {
},
},

"os_type": {
Type: schema.TypeString,
Computed: true,
},
"site_config": schemaFunctionAppDataSourceSiteConfig(),

"outbound_ip_addresses": {
Type: schema.TypeString,
Computed: true,
},

"possible_outbound_ip_addresses": {
Type: schema.TypeString,
Computed: true,
},
"source_control": schemaDataSourceAppServiceSiteSourceControl(),

"tags": tags.Schema(),
},
Expand Down Expand Up @@ -145,6 +149,11 @@ func dataSourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error making Read request on AzureRM Function App ConnectionStrings %q: %+v", name, err)
}

scmResp, err := client.GetSourceControl(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Source Control %q: %+v", name, err)
}

siteCredFuture, err := client.ListPublishingCredentials(ctx, resourceGroup, name)
if err != nil {
return err
Expand All @@ -157,6 +166,10 @@ func dataSourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Site Credential %q: %+v", name, err)
}
configResp, err := client.GetConfiguration(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM Function App Configuration %q: %+v", name, err)
}

d.SetId(*resp.ID)

Expand Down Expand Up @@ -196,5 +209,15 @@ func dataSourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) erro
return err
}

siteConfig := flattenFunctionAppSiteConfig(configResp.SiteConfig)
if err = d.Set("site_config", siteConfig); err != nil {
return err
}

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

return tags.FlattenAndSet(d, resp.Tags)
}
Loading