Skip to content

Commit

Permalink
App Service Re-allignment (#19685)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Jan 12, 2023
1 parent e3691cf commit a5b0ec2
Show file tree
Hide file tree
Showing 39 changed files with 5,828 additions and 4,793 deletions.
660 changes: 660 additions & 0 deletions internal/services/appservice/helpers/app_stack.go

Large diffs are not rendered by default.

573 changes: 573 additions & 0 deletions internal/services/appservice/helpers/auto_heal.go

Large diffs are not rendered by default.

1,364 changes: 1,364 additions & 0 deletions internal/services/appservice/helpers/common_web_app_schema.go

Large diffs are not rendered by default.

90 changes: 58 additions & 32 deletions internal/services/appservice/helpers/function_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2021-02-01/web" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
apimValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
Expand Down Expand Up @@ -1047,6 +1048,7 @@ func linuxFunctionAppStackSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"3.10",
"3.9",
"3.8",
"3.7",
Expand All @@ -1067,7 +1069,7 @@ func linuxFunctionAppStackSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"12",
"12", // Deprecated, and removed from portal, but seemingly accepted by API
"14",
"16",
"18", // preview LTS Support
Expand All @@ -1088,8 +1090,8 @@ func linuxFunctionAppStackSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"7",
"7.2", // preview LTS Support
"7", // Deprecated / not available in the portal
"7.2",
}, false),
ExactlyOneOf: []string{
"site_config.0.application_stack.0.dotnet_version",
Expand Down Expand Up @@ -1120,7 +1122,7 @@ func linuxFunctionAppStackSchema() *pluginsdk.Schema {
"site_config.0.application_stack.0.docker",
"site_config.0.application_stack.0.use_custom_runtime",
},
Description: "The version of Java to use. Possible values are `8`, and `11`",
Description: "The version of Java to use. Possible values are `8`, `11`, and `17`",
},

"docker": {
Expand Down Expand Up @@ -1277,16 +1279,19 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"dotnet_version": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "v4.0",
ValidateFunc: validation.StringInSlice([]string{
"3.1",
"6",
"7",
"v3.0",
"v4.0",
"v6.0",
"v7.0",
}, false),
ExactlyOneOf: []string{
"site_config.0.application_stack.0.dotnet_version",
Expand All @@ -1295,13 +1300,13 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
"site_config.0.application_stack.0.powershell_core_version",
"site_config.0.application_stack.0.use_custom_runtime",
},
Description: "The version of .Net. Possible values are `3.1` `6` and `7`",
Description: "The version of .Net. Possible values are `v3.0`, `v4.0`, `v6.0` and `v7.0`",
},

"use_dotnet_isolated_runtime": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Computed: true,
ConflictsWith: []string{
"site_config.0.application_stack.0.java_version",
"site_config.0.application_stack.0.node_version",
Expand Down Expand Up @@ -1334,7 +1339,7 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"8",
"1.8",
"11",
"17",
}, false),
Expand All @@ -1345,7 +1350,7 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
"site_config.0.application_stack.0.powershell_core_version",
"site_config.0.application_stack.0.use_custom_runtime",
},
Description: "The version of Java to use. Possible values are `8`, and `11`",
Description: "The version of Java to use. Possible values are `1.8`, `11` and `17`",
},

"powershell_core_version": {
Expand All @@ -1368,6 +1373,7 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
"use_custom_runtime": {
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ExactlyOneOf: []string{
"site_config.0.application_stack.0.dotnet_version",
"site_config.0.application_stack.0.java_version",
Expand Down Expand Up @@ -1564,17 +1570,17 @@ func ExpandSiteConfigLinuxFunctionApp(siteConfig []SiteConfigLinuxFunctionApp, e

if linuxAppStack.PythonVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "python", false)
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("Python|%s", linuxAppStack.PythonVersion))
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("PYTHON|%s", linuxAppStack.PythonVersion))
}

if linuxAppStack.JavaVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "java", false)
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("Java|%s", linuxAppStack.JavaVersion))
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("JAVA|%s", linuxAppStack.JavaVersion))
}

if linuxAppStack.PowerShellCoreVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "powershell", false)
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("PowerShell|%s", linuxAppStack.PowerShellCoreVersion))
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("POWERSHELL|%s", linuxAppStack.PowerShellCoreVersion))
}

if linuxAppStack.CustomHandler {
Expand Down Expand Up @@ -1808,27 +1814,25 @@ func ExpandSiteConfigWindowsFunctionApp(siteConfig []SiteConfigWindowsFunctionAp
if windowsAppStack.DotNetVersion != "" {
if windowsAppStack.DotNetIsolated {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated", false)
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("DOTNET-ISOLATED|%s", windowsAppStack.DotNetVersion))
} else {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "dotnet", false)
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("DOTNET|%s", windowsAppStack.DotNetVersion))
}
expanded.NetFrameworkVersion = pointer.To(windowsAppStack.DotNetVersion)
}

if windowsAppStack.NodeVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "node", false)
appSettings = updateOrAppendAppSettings(appSettings, "WEBSITE_NODE_DEFAULT_VERSION", windowsAppStack.NodeVersion, false)
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("Node|%s", windowsAppStack.NodeVersion))
}

if windowsAppStack.JavaVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "java", false)
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("Java|%s", windowsAppStack.JavaVersion))
expanded.JavaVersion = pointer.To(windowsAppStack.JavaVersion)
}

if windowsAppStack.PowerShellCoreVersion != "" {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "powershell", false)
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("PowerShell|%s", windowsAppStack.PowerShellCoreVersion))
expanded.PowerShellVersion = pointer.To(strings.TrimPrefix(windowsAppStack.PowerShellCoreVersion, "~"))
}

if windowsAppStack.CustomHandler {
Expand Down Expand Up @@ -1994,16 +1998,23 @@ func FlattenSiteConfigLinuxFunctionApp(functionAppSiteConfig *web.SiteConfig) (*
}

if functionAppSiteConfig.Cors != nil {
corsEmpty := false
corsSettings := functionAppSiteConfig.Cors
cors := CorsSetting{}
if corsSettings.SupportCredentials != nil {
cors.SupportCredentials = *corsSettings.SupportCredentials
}

if corsSettings.AllowedOrigins != nil && len(*corsSettings.AllowedOrigins) != 0 {
cors.AllowedOrigins = *corsSettings.AllowedOrigins
if corsSettings.AllowedOrigins != nil {
if len(*corsSettings.AllowedOrigins) > 0 {
cors.AllowedOrigins = *corsSettings.AllowedOrigins
} else if !cors.SupportCredentials {
corsEmpty = true
}
}
if !corsEmpty {
result.Cors = []CorsSetting{cors}
}
result.Cors = []CorsSetting{cors}
}

var appStack []ApplicationStackLinuxFunctionApp
Expand Down Expand Up @@ -2072,26 +2083,41 @@ func FlattenSiteConfigWindowsFunctionApp(functionAppSiteConfig *web.SiteConfig)

if functionAppSiteConfig.Cors != nil {
corsSettings := functionAppSiteConfig.Cors
corsEmpty := false
cors := CorsSetting{}
if corsSettings.SupportCredentials != nil {
cors.SupportCredentials = *corsSettings.SupportCredentials
}

if corsSettings.AllowedOrigins != nil && len(*corsSettings.AllowedOrigins) != 0 {
cors.AllowedOrigins = *corsSettings.AllowedOrigins
if corsSettings.AllowedOrigins != nil {
if len(*corsSettings.AllowedOrigins) > 0 {
cors.AllowedOrigins = *corsSettings.AllowedOrigins
} else if !cors.SupportCredentials {
corsEmpty = true
}
}

if !corsEmpty {
result.Cors = []CorsSetting{cors}
}
result.Cors = []CorsSetting{cors}
}

var appStack []ApplicationStackWindowsFunctionApp
if functionAppSiteConfig.WindowsFxVersion != nil {
decoded, err := DecodeFunctionAppWindowsFxVersion(*functionAppSiteConfig.WindowsFxVersion)
if err != nil {
return nil, fmt.Errorf("flattening site config: %s", err)
powershellVersion := ""
if p := functionAppSiteConfig.PowerShellVersion; p != nil {
powershellVersion = *p
if powershellVersion == "~7" {
powershellVersion = "7"
}
appStack = decoded
}
result.ApplicationStack = appStack

result.ApplicationStack = []ApplicationStackWindowsFunctionApp{{
DotNetVersion: pointer.From(functionAppSiteConfig.NetFrameworkVersion),
DotNetIsolated: false, // set this later from app_settings
NodeVersion: "", // Need to get this from app_settings later
JavaVersion: pointer.From(functionAppSiteConfig.JavaVersion),
PowerShellCoreVersion: powershellVersion,
CustomHandler: false, // set this later from app_settings
}}

return result, nil
}
Expand Down
Loading

0 comments on commit a5b0ec2

Please sign in to comment.