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 Re-allignment #19685

Merged
merged 28 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
26ad2fa
app-stacks pt1
jackofallops Nov 28, 2022
8dd94d4
app stack changes for windows web app
jackofallops Dec 5, 2022
2bdd80c
add node18 test
jackofallops Dec 6, 2022
4a0c047
java strings are fun
jackofallops Dec 7, 2022
0a97d3d
linuxFxVersion string processing
jackofallops Dec 7, 2022
4d9c7b5
add linuxFxString error capability
jackofallops Dec 7, 2022
9f6f11e
update decoding and tests for java on linux
jackofallops Dec 7, 2022
5b5358b
finish Go support on linux
jackofallops Dec 7, 2022
d182a36
linux web app slot stack updates
jackofallops Dec 7, 2022
1680563
minor refactor for separation
jackofallops Dec 8, 2022
507cece
windows function apps
jackofallops Dec 8, 2022
9900cf2
windows function app slot
jackofallops Dec 9, 2022
9ee52fc
goimports
jackofallops Dec 9, 2022
4243501
update linux function app and slot and tests
jackofallops Dec 9, 2022
8e328de
fixup win func schema
jackofallops Dec 12, 2022
2708ee3
test fixes
jackofallops Dec 13, 2022
fe86fca
node flatten fix
jackofallops Dec 13, 2022
78ab076
normalise cors
jackofallops Dec 13, 2022
e0f9ca0
more stack tweaks
jackofallops Dec 14, 2022
5033a14
linting fixes
jackofallops Dec 14, 2022
bb205ec
more linting fixes
jackofallops Dec 14, 2022
94249db
unparam ignore on test config
jackofallops Dec 14, 2022
4a08434
update application_stack docks
jackofallops Jan 5, 2023
51689c0
remove old node workaround
jackofallops Jan 5, 2023
b382598
review changes pt1
jackofallops Jan 6, 2023
78362e1
review changes pt2
jackofallops Jan 9, 2023
c5d59b9
fix docker parts for windows slot
jackofallops Jan 10, 2023
38ceaf4
remove completed TODOs
jackofallops Jan 12, 2023
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
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential breaking change?

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))
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

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))
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

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))
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

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