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

azurerm_windows_function_app - correcting runtime settings. #18076

Closed
wants to merge 17 commits into from
111 changes: 96 additions & 15 deletions internal/services/appservice/helpers/function_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2021-02-01/web"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
apimValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -1332,7 +1333,7 @@ func windowsFunctionAppStackSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"8",
"1.8",
"11",
"17",
}, false),
Expand All @@ -1343,7 +1344,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`, and `11`",
},

"powershell_core_version": {
Expand Down Expand Up @@ -1738,6 +1739,9 @@ func ExpandSiteConfigWindowsFunctionApp(siteConfig []SiteConfigWindowsFunctionAp
expanded = existing
// need to zero fxversion to re-calculate based on changes below or removing app_stack doesn't apply
expanded.WindowsFxVersion = utils.String("")
expanded.PowerShellVersion = utils.String("")
expanded.JavaVersion = utils.String("")
expanded.NodeVersion = utils.String("")
}

appSettings := make([]web.NameValuePair, 0)
Expand Down Expand Up @@ -1806,27 +1810,47 @@ 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))
if !features.FourPointOhBeta() {
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))
if !features.FourPointOhBeta() {
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("DOTNET|%s", windowsAppStack.DotNetVersion))
}
}
if windowsAppStack.DotNetVersion == "3.1" {
expanded.NetFrameworkVersion = utils.String("v4.0")
} else {
expanded.NetFrameworkVersion = utils.String(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 !features.FourPointOhBeta() {
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))
if !features.FourPointOhBeta() {
expanded.WindowsFxVersion = utils.String(fmt.Sprintf("Java|%s", windowsAppStack.JavaVersion))
}
expanded.JavaVersion = utils.String(windowsAppStack.JavaVersion)
}

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

if windowsAppStack.CustomHandler {
Expand Down Expand Up @@ -2017,7 +2041,7 @@ func FlattenSiteConfigLinuxFunctionApp(functionAppSiteConfig *web.SiteConfig) (*
return result, nil
}

func FlattenSiteConfigWindowsFunctionApp(functionAppSiteConfig *web.SiteConfig) (*SiteConfigWindowsFunctionApp, error) {
func FlattenSiteConfigWindowsFunctionApp(functionAppSiteConfig *web.SiteConfig, input web.StringDictionary) (*SiteConfigWindowsFunctionApp, error) {
if functionAppSiteConfig == nil {
return nil, fmt.Errorf("flattening site config: SiteConfig was nil")
}
Expand Down Expand Up @@ -2081,15 +2105,72 @@ func FlattenSiteConfigWindowsFunctionApp(functionAppSiteConfig *web.SiteConfig)
}
}

var appStack []ApplicationStackWindowsFunctionApp
if functionAppSiteConfig.WindowsFxVersion != nil {
decoded, err := DecodeFunctionAppWindowsFxVersion(*functionAppSiteConfig.WindowsFxVersion)
if err != nil {
return nil, fmt.Errorf("flattening site config: %s", err)
var winFunctionAppStack []ApplicationStackWindowsFunctionApp
runtimeStack := ""
nodeVer := ""
if input.Properties != nil {
for k, v := range input.Properties {
switch k {
case "WEBSITE_NODE_DEFAULT_VERSION":
nodeVer = utils.NormalizeNilableString(v)
case "FUNCTIONS_WORKER_RUNTIME":
runtimeStack = utils.NormalizeNilableString(v)
}
}
appStack = decoded
}
result.ApplicationStack = appStack

switch runtimeStack {
case "java":
if functionAppSiteConfig.JavaVersion != nil && *functionAppSiteConfig.JavaVersion != "" {
appStack := ApplicationStackWindowsFunctionApp{
JavaVersion: utils.NormalizeNilableString(functionAppSiteConfig.JavaVersion),
}
winFunctionAppStack = append(winFunctionAppStack, appStack)
}
case "dotnet":
if functionAppSiteConfig.NetFrameworkVersion != nil && *functionAppSiteConfig.NetFrameworkVersion != "" {
dotnetVersion := *functionAppSiteConfig.NetFrameworkVersion
if dotnetVersion == "v4.0" {
dotnetVersion = "3.1"
} else if dotnetVersion == "v6.0" {
dotnetVersion = "6"
}
appStack := ApplicationStackWindowsFunctionApp{
DotNetVersion: dotnetVersion,
}
winFunctionAppStack = append(winFunctionAppStack, appStack)
}
case "dotnet-isolated":
appStack := ApplicationStackWindowsFunctionApp{DotNetIsolated: true}
if functionAppSiteConfig.NetFrameworkVersion != nil && *functionAppSiteConfig.NetFrameworkVersion != "" {
dotnetVersion := *functionAppSiteConfig.NetFrameworkVersion
if dotnetVersion == "v4.0" {
dotnetVersion = "3.1"
} else if dotnetVersion == "v6.0" {
dotnetVersion = "6"
}
appStack.DotNetVersion = dotnetVersion
winFunctionAppStack = append(winFunctionAppStack, appStack)
}
case "node":
if nodeVer != "" {
appStack := ApplicationStackWindowsFunctionApp{NodeVersion: nodeVer}
winFunctionAppStack = append(winFunctionAppStack, appStack)
}
case "powershell":
if functionAppSiteConfig.PowerShellVersion != nil && *functionAppSiteConfig.PowerShellVersion != "" {
appStack := ApplicationStackWindowsFunctionApp{PowerShellCoreVersion: utils.NormalizeNilableString(functionAppSiteConfig.PowerShellVersion)}
if *functionAppSiteConfig.PowerShellVersion == "~7" {
appStack.PowerShellCoreVersion = "7"
}
winFunctionAppStack = append(winFunctionAppStack, appStack)
}
case "custom":
appStack := ApplicationStackWindowsFunctionApp{CustomHandler: true}
winFunctionAppStack = append(winFunctionAppStack, appStack)
}

result.ApplicationStack = winFunctionAppStack

return result, nil
}
Expand Down
Loading