-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
New Resource azurerm_function_app_on_container
#27249
Open
xiaxyi
wants to merge
15
commits into
hashicorp:main
Choose a base branch
from
xiaxyi:functionOnAca
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
edc43ca
new resource - azure function on container apps
xiaxyi cc4dc9a
fix ci error
xiaxyi a2ba13e
fix ci error
xiaxyi 330a948
terrafmt fmt on test cases
xiaxyi b521615
Merge remote-tracking branch 'upstream/main' into functionOnAca
xiaxyi 5e63e01
update code per review
xiaxyi 4db87e8
remove log and sort imports
xiaxyi 2332cd7
fix linter error
xiaxyi d9c436b
update registration
xiaxyi 94a8c2f
update create and update poller
xiaxyi 4126c0d
Merge remote-tracking branch 'upstream/main' into functionOnAca
xiaxyi 27c6aaa
update labeler-issue-triage.yml file
xiaxyi a3288c5
merging upstream
xiaxyi 11ae80f
resolve go linter
xiaxyi 3dde8f0
remove unnecessary line
xiaxyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
internal/services/appservice/helpers/function_app_on_container.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-12-01/webapps" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
type Registry struct { | ||
Server string `tfschema:"registry_server_url"` | ||
UserName string `tfschema:"registry_username"` | ||
Password string `tfschema:"registry_password"` | ||
} | ||
|
||
func RegistrySchemaLinuxFunctionAppOnContainer() *pluginsdk.Schema { | ||
return &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeList, | ||
MaxItems: 1, | ||
Required: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"registry_server_url": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
Description: "The login endpoint of the container Registry url", | ||
}, | ||
|
||
"registry_username": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
RequiredWith: []string{"registry.0.registry_password"}, | ||
Description: "The username to use for this Container Registry.", | ||
}, | ||
|
||
"registry_password": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
RequiredWith: []string{"registry.0.registry_username"}, | ||
Description: "The name of the Secret Reference containing the password value for this user on the Container Registry.", | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type SiteConfigLinuxFunctionAppOnContainer struct { | ||
AppInsightsInstrumentationKey string `tfschema:"application_insights_key"` // App Insights Instrumentation Key | ||
AppInsightsConnectionString string `tfschema:"application_insights_connection_string"` | ||
AppScaleLimit int64 `tfschema:"app_scale_limit"` | ||
ElasticInstanceMinimum int64 `tfschema:"elastic_instance_minimum"` | ||
LinuxFxVersion string `tfschema:"linux_fx_version"` | ||
} | ||
|
||
func SiteConfigSchemaLinuxFunctionAppOnContainer() *pluginsdk.Schema { | ||
return &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"application_insights_key": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
Description: "The Instrumentation Key for connecting the Linux Function App to Application Insights.", | ||
}, | ||
|
||
"application_insights_connection_string": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
Description: "The Connection String for linking the Linux Function App to Application Insights.", | ||
}, | ||
|
||
"app_scale_limit": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Default: 10, | ||
ValidateFunc: validation.IntBetween(10, 30), | ||
Description: "The number of workers this function app can scale out to. Only applicable to apps on the Consumption and Premium plan.", | ||
}, | ||
|
||
"elastic_instance_minimum": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add |
||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Default: 10, | ||
ValidateFunc: validation.IntBetween(10, 30), | ||
Description: "The number of minimum instances for this Linux Function App. Only affects apps on Elastic Premium plans.", | ||
}, | ||
|
||
"linux_fx_version": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
Description: "The Linux FX Version", | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ExpandSiteConfigLinuxFunctionAppOnContainer(siteConfig []SiteConfigLinuxFunctionAppOnContainer, existing *webapps.SiteConfig, metadata sdk.ResourceMetaData, registry Registry, version string, storageString string, storageUsesMSI bool) *webapps.SiteConfig { | ||
if len(siteConfig) == 0 { | ||
return nil | ||
} | ||
|
||
expanded := &webapps.SiteConfig{} | ||
if existing != nil { | ||
expanded = existing | ||
} | ||
|
||
appSettings := make([]webapps.NameValuePair, 0) | ||
|
||
appSettings = updateOrAppendAppSettings(appSettings, "FUNCTIONS_EXTENSION_VERSION", version, false) | ||
|
||
if storageUsesMSI { | ||
appSettings = updateOrAppendAppSettings(appSettings, "AzureWebJobsStorage__accountName", storageString, false) | ||
} else { | ||
appSettings = updateOrAppendAppSettings(appSettings, "AzureWebJobsStorage", storageString, false) | ||
} | ||
linuxFunctionOnContainerSiteConfig := siteConfig[0] | ||
if metadata.ResourceData.HasChange("site_config.0.elastic_instance_minimum") { | ||
expanded.MinimumElasticInstanceCount = pointer.To(linuxFunctionOnContainerSiteConfig.ElasticInstanceMinimum) | ||
} | ||
|
||
if metadata.ResourceData.HasChange("site_config.0.app_scale_limit") { | ||
expanded.FunctionAppScaleLimit = pointer.To(linuxFunctionOnContainerSiteConfig.AppScaleLimit) | ||
} | ||
|
||
if linuxFunctionOnContainerSiteConfig.AppInsightsConnectionString == "" { | ||
appSettings = updateOrAppendAppSettings(appSettings, "APPLICATIONINSIGHTS_CONNECTION_STRING", linuxFunctionOnContainerSiteConfig.AppInsightsConnectionString, true) | ||
} else { | ||
appSettings = updateOrAppendAppSettings(appSettings, "APPLICATIONINSIGHTS_CONNECTION_STRING", linuxFunctionOnContainerSiteConfig.AppInsightsConnectionString, false) | ||
} | ||
|
||
// update docker related settings | ||
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_URL", registry.Server, false) | ||
if registry.UserName != "" { | ||
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_USERNAME", registry.UserName, false) | ||
} | ||
if registry.Password != "" { | ||
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_PASSWORD", registry.Password, false) | ||
} | ||
|
||
expanded.AppSettings = &appSettings | ||
return expanded | ||
} | ||
|
||
func FlattenSiteConfigLinuxFunctionAppOnContainer(functionAppOnContainer *webapps.SiteConfig) *SiteConfigLinuxFunctionAppOnContainer { | ||
result := &SiteConfigLinuxFunctionAppOnContainer{ | ||
ElasticInstanceMinimum: pointer.From(functionAppOnContainer.MinimumElasticInstanceCount), | ||
AppScaleLimit: pointer.From(functionAppOnContainer.FunctionAppScaleLimit), | ||
LinuxFxVersion: pointer.From(functionAppOnContainer.LinuxFxVersion), | ||
} | ||
|
||
return result | ||
} | ||
|
||
func EncodeLinuxFunctionAppOnContainerRegistryImage(input []Registry, image string) *string { | ||
if len(input) == 0 { | ||
return utils.String("") | ||
} | ||
dockerUrl := input[0].Server | ||
httpPrefixes := []string{"https://", "http://"} | ||
for _, prefix := range httpPrefixes { | ||
dockerUrl = strings.TrimPrefix(dockerUrl, prefix) | ||
} | ||
return utils.String(fmt.Sprintf("DOCKER|%s/%s", dockerUrl, image)) | ||
} | ||
|
||
func DecodeLinuxFunctionAppOnContainerRegistryImage(input *string, partial *webapps.StringDictionary) (string, []Registry, error) { | ||
containerRegistryList := make([]Registry, 0) | ||
if input == nil { | ||
return "", containerRegistryList, nil | ||
} | ||
parts := strings.Split(*input, "|") | ||
value := parts[1] | ||
if len(parts) != 2 || parts[0] != "DOCKER" { | ||
return "", []Registry{}, fmt.Errorf("unrecognised LinuxFxVersion format received, got %s", *input) | ||
} | ||
|
||
// mcr.microsoft.com/dockerimage:tag | ||
registryUrl := value[:strings.Index(parts[1], "/")] | ||
|
||
containerRegistry := Registry{ | ||
Server: registryUrl, | ||
} | ||
if partial.Properties != nil { | ||
for k, v := range *partial.Properties { | ||
if k == "DOCKER_REGISTRY_SERVER_URL" { | ||
containerRegistry.Server = v | ||
} | ||
if k == "DOCKER_REGISTRY_SERVER_USERNAME" { | ||
containerRegistry.UserName = v | ||
} | ||
if k == "DOCKER_REGISTRY_SERVER_PASSWORD" { | ||
containerRegistry.Password = v | ||
} | ||
} | ||
containerRegistryList = append(containerRegistryList, containerRegistry) | ||
} | ||
|
||
return value[strings.Index(parts[1], "/")+1:], containerRegistryList, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add
ValidateFunc
to set the value range