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_linux_function_app - fix linuxFxVersion for docker runtime #18194

Merged
merged 4 commits into from
Feb 1, 2023
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1593,7 +1593,14 @@ func ExpandSiteConfigLinuxFunctionApp(siteConfig []SiteConfigLinuxFunctionApp, e
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_URL", dockerConfig.RegistryURL, false)
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_USERNAME", dockerConfig.RegistryUsername, false)
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_PASSWORD", dockerConfig.RegistryPassword, false)
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("DOCKER|%s/%s:%s", dockerConfig.RegistryURL, dockerConfig.ImageName, dockerConfig.ImageTag))
var dockerUrl string
for _, prefix := range urlSchemes {
if strings.HasPrefix(dockerConfig.RegistryURL, prefix) {
dockerUrl = strings.TrimPrefix(dockerConfig.RegistryURL, prefix)
continue
}
}
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("DOCKER|%s/%s:%s", dockerUrl, dockerConfig.ImageName, dockerConfig.ImageTag))
}
} else {
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_WORKER_RUNTIME", "", true)
23 changes: 21 additions & 2 deletions internal/services/appservice/helpers/fx_strings.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,13 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

var urlSchemes = []string{
"https://",
"HTTPS://",
"http://",
"HTTP://",
}

func decodeApplicationStackLinux(fxString string) ApplicationStackLinux {
parts := strings.Split(fxString, "|")
result := ApplicationStackLinux{}
@@ -114,7 +121,12 @@ func EncodeFunctionAppLinuxFxVersion(input []ApplicationStackLinuxFunctionApp) *
appType = "DOCKER"
dockerCfg := appStack.Docker[0]
if dockerCfg.RegistryURL != "" {
appString = fmt.Sprintf("%s/%s:%s", strings.Trim(dockerCfg.RegistryURL, "/"), dockerCfg.ImageName, dockerCfg.ImageTag)
dockerUrl := dockerCfg.RegistryURL
httpPrefixes := []string{"https://", "http://"}
for _, prefix := range httpPrefixes {
dockerUrl = strings.TrimPrefix(dockerUrl, prefix)
}
appString = fmt.Sprintf("%s/%s:%s", dockerUrl, dockerCfg.ImageName, dockerCfg.ImageTag)
} else {
appString = fmt.Sprintf("%s:%s", dockerCfg.ImageName, dockerCfg.ImageTag)
}
@@ -183,7 +195,14 @@ func DecodeFunctionAppDockerFxString(input string, partial ApplicationStackDocke
return nil, fmt.Errorf("expected a docker FX version, got %q", parts[0])
}

dockerParts := strings.Split(strings.TrimPrefix(parts[1], partial.RegistryURL), ":")
dockerUrl := partial.RegistryURL
for _, prefix := range urlSchemes {
if strings.HasPrefix(dockerUrl, prefix) {
dockerUrl = strings.TrimPrefix(dockerUrl, prefix)
continue
}
}
dockerParts := strings.Split(strings.TrimPrefix(parts[1], dockerUrl), ":")
if len(dockerParts) != 2 {
return nil, fmt.Errorf("invalid docker image reference %q", parts[1])
}
Original file line number Diff line number Diff line change
@@ -2334,11 +2334,13 @@ resource "azurerm_linux_function_app" "test" {
storage_account_access_key = azurerm_storage_account.test.primary_access_key

site_config {
always_on = true

application_stack {
docker {
registry_url = "https://mcr.microsoft.com"
image_name = "azure-app-service/samples/aspnethelloworld"
image_tag = "latest"
image_name = "azure-functions/dotnet"
image_tag = "3.0-appservice-quickstart"
}
}
}