Skip to content

Commit

Permalink
azurerm_linux_function_app, azurerm_windows_function_app - set th…
Browse files Browse the repository at this point in the history
…e storage account for function app using elastic plans automatically (hashicorp#21212)
  • Loading branch information
xiaxyi authored Sep 20, 2023
1 parent e266595 commit 1ed6ded
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
20 changes: 6 additions & 14 deletions internal/services/appservice/linux_function_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,16 @@ func (r LinuxFunctionAppResource) Create() sdk.ResourceFunc {
suffix := uuid.New().String()[0:4]
_, contentOverVnetEnabled := functionApp.AppSettings["WEBSITE_CONTENTOVERVNET"]
_, contentSharePresent := functionApp.AppSettings["WEBSITE_CONTENTSHARE"]
_, contentShareConnectionString := functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]
if _, contentShareConnectionStringPresent := functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]; !contentShareConnectionStringPresent {
functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}

if !contentSharePresent {
if contentOverVnetEnabled {
return fmt.Errorf("the app_setting WEBSITE_CONTENTSHARE must be specified and set to a valid share when WEBSITE_CONTENTOVERVNET is specified")
}
functionApp.AppSettings["WEBSITE_CONTENTSHARE"] = fmt.Sprintf("%s-%s", strings.ToLower(functionApp.Name), suffix)
}
if !contentShareConnectionString {
if contentOverVnetEnabled && contentSharePresent {
return fmt.Errorf("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING must be set when WEBSITE_CONTENTSHARE and WEBSITE_CONTENTOVERVNET are specified")
}
functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}
} else {
if _, present := functionApp.AppSettings["AzureWebJobsStorage__accountName"]; !present {
functionApp.AppSettings["AzureWebJobsStorage__accountName"] = storageString
Expand Down Expand Up @@ -945,20 +941,16 @@ func (r LinuxFunctionAppResource) Update() sdk.ResourceFunc {
suffix := uuid.New().String()[0:4]
_, contentOverVnetEnabled := state.AppSettings["WEBSITE_CONTENTOVERVNET"]
_, contentSharePresent := state.AppSettings["WEBSITE_CONTENTSHARE"]
_, contentShareConnectionString := state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]
if _, contentShareConnectionStringPresent := state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]; !contentShareConnectionStringPresent {
state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}

if !contentSharePresent {
if contentOverVnetEnabled {
return fmt.Errorf("the value of WEBSITE_CONTENTSHARE must be set to a predefined share when the storage account is restricted to a virtual network")
}
state.AppSettings["WEBSITE_CONTENTSHARE"] = fmt.Sprintf("%s-%s", strings.ToLower(state.Name), suffix)
}
if !contentShareConnectionString {
if contentOverVnetEnabled && contentSharePresent {
return fmt.Errorf("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING must be set when WEBSITE_CONTENTSHARE and WEBSITE_CONTENTOVERVNET is specified")
}
state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}
} else {
if _, present := state.AppSettings["AzureWebJobsStorage__accountName"]; !present {
state.AppSettings["AzureWebJobsStorage__accountName"] = storageString
Expand Down
20 changes: 6 additions & 14 deletions internal/services/appservice/windows_function_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,16 @@ func (r WindowsFunctionAppResource) Create() sdk.ResourceFunc {
suffix := uuid.New().String()[0:4]
_, contentOverVnetEnabled := functionApp.AppSettings["WEBSITE_CONTENTOVERVNET"]
_, contentSharePresent := functionApp.AppSettings["WEBSITE_CONTENTSHARE"]
_, contentShareConnectionString := functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]
if _, contentShareConnectionStringPresent := functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]; !contentShareConnectionStringPresent {
functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}

if !contentSharePresent {
if contentOverVnetEnabled {
return fmt.Errorf("the app_setting WEBSITE_CONTENTSHARE must be specified and set to a valid share when WEBSITE_CONTENTOVERVNET is specified")
}
functionApp.AppSettings["WEBSITE_CONTENTSHARE"] = fmt.Sprintf("%s-%s", strings.ToLower(functionApp.Name), suffix)
}
if !contentShareConnectionString {
if contentOverVnetEnabled && contentSharePresent {
return fmt.Errorf("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING must be set when WEBSITE_CONTENTSHARE and WEBSITE_CONTENTOVERVNET are specified")
}
functionApp.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}
} else {
if _, present := functionApp.AppSettings["AzureWebJobsStorage__accountName"]; !present {
functionApp.AppSettings["AzureWebJobsStorage__accountName"] = storageString
Expand Down Expand Up @@ -948,20 +944,16 @@ func (r WindowsFunctionAppResource) Update() sdk.ResourceFunc {
suffix := uuid.New().String()[0:4]
_, contentOverVnetEnabled := state.AppSettings["WEBSITE_CONTENTOVERVNET"]
_, contentSharePresent := state.AppSettings["WEBSITE_CONTENTSHARE"]
_, contentShareConnectionString := state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]
if _, contentShareConnectionStringPresent := state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"]; !contentShareConnectionStringPresent {
state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}

if !contentSharePresent {
if contentOverVnetEnabled {
return fmt.Errorf("the value of WEBSITE_CONTENTSHARE must be set to a predefined share when the storage account is restricted to a virtual network")
}
state.AppSettings["WEBSITE_CONTENTSHARE"] = fmt.Sprintf("%s-%s", strings.ToLower(state.Name), suffix)
}
if !contentShareConnectionString {
if contentOverVnetEnabled && contentSharePresent {
return fmt.Errorf("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING must be set when WEBSITE_CONTENTSHARE and WEBSITE_CONTENTOVERVNET is specified")
}
state.AppSettings["WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"] = storageString
}
} else {
if _, present := state.AppSettings["AzureWebJobsStorage__accountName"]; !present {
state.AppSettings["AzureWebJobsStorage__accountName"] = storageString
Expand Down
12 changes: 8 additions & 4 deletions website/docs/r/linux_function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ The following arguments are supported:

* `app_settings` - (Optional) A map of key-value pairs for [App Settings](https://docs.microsoft.com/azure/azure-functions/functions-app-settings) and custom values.

~> **Note:** for runtime related settings, please use `node_version` in `site_config` to set the node version and use `functions_extension_version` to set the function runtime version, terraform will assign the values to the key `WEBSITE_NODE_DEFAULT_VERSION` and `FUNCTIONS_EXTENSION_VERSION` in app setting.
~> **Note:** For runtime related settings, please use `node_version` in `site_config` to set the node version and use `functions_extension_version` to set the function runtime version, terraform will assign the values to the key `WEBSITE_NODE_DEFAULT_VERSION` and `FUNCTIONS_EXTENSION_VERSION` in app setting.

~> **Note:** For storage related settings, please use related properties that are available such as `storage_account_access_key`, terraform will assign the value to keys such as `WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`, `AzureWebJobsStorage` in app_setting.
~> **Note:** for application insight related settings, please use `application_insights_connection_string` and `application_insights_key`, terraform will assign the value to the key `APPINSIGHTS_INSTRUMENTATIONKEY` and `APPLICATIONINSIGHTS_CONNECTION_STRING` in app setting.
~> **Note:** for health check related settings, please use `health_check_eviction_time_in_min`, terraform will assign the value to the key `WEBSITE_HEALTHCHECK_MAXPINGFAILURES` in app setting.
~> **NOTE:** Please create a predefined share if you are restricting your storage account to a virtual network by setting `WEBSITE_CONTENTOVERVNET` to 1 in app_setting.

~> **Note:** For application insight related settings, please use `application_insights_connection_string` and `application_insights_key`, terraform will assign the value to the key `APPINSIGHTS_INSTRUMENTATIONKEY` and `APPLICATIONINSIGHTS_CONNECTION_STRING` in app setting.

~> **Note:** For health check related settings, please use `health_check_eviction_time_in_min`, terraform will assign the value to the key `WEBSITE_HEALTHCHECK_MAXPINGFAILURES` in app setting.

~> **Note:** Please create a predefined share if you are restricting your storage account to a virtual network by setting `WEBSITE_CONTENTOVERVNET` to 1 in app_setting.

* `auth_settings` - (Optional) A `auth_settings` block as defined below.

Expand Down
14 changes: 9 additions & 5 deletions website/docs/r/windows_function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ The following arguments are supported:
---

* `app_settings` - (Optional) A map of key-value pairs for [App Settings](https://docs.microsoft.com/azure/azure-functions/functions-app-settings) and custom values.

~> **Note:** for runtime related settings, please use `node_version` in `site_config` to set the node version and use `functions_extension_version` to set the function runtime version, terraform will assign the values to the key `WEBSITE_NODE_DEFAULT_VERSION` and `FUNCTIONS_EXTENSION_VERSION` in app setting.

~> **Note:** For runtime related settings, please use `node_version` in `site_config` to set the node version and use `functions_extension_version` to set the function runtime version, terraform will assign the values to the key `WEBSITE_NODE_DEFAULT_VERSION` and `FUNCTIONS_EXTENSION_VERSION` in app setting.

~> **Note:** For storage related settings, please use related properties that are available such as `storage_account_access_key`, terraform will assign the value to keys such as `WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`, `AzureWebJobsStorage` in app_setting.
~> **Note:** for application insight related settings, please use `application_insights_connection_string` and `application_insights_key`, terraform will assign the value to the key `APPINSIGHTS_INSTRUMENTATIONKEY` and `APPLICATIONINSIGHTS_CONNECTION_STRING` in app setting.
~> **Note:** for health check related settings, please use `health_check_eviction_time_in_min`, terraform will assign the value to the key `WEBSITE_HEALTHCHECK_MAXPINGFAILURES` in app setting.
~> **NOTE:** Please create a predefined share if you are restricting your storage account to a virtual network by setting `WEBSITE_CONTENTOVERVNET` to 1 in app_setting.

~> **Note:** For application insight related settings, please use `application_insights_connection_string` and `application_insights_key`, terraform will assign the value to the key `APPINSIGHTS_INSTRUMENTATIONKEY` and `APPLICATIONINSIGHTS_CONNECTION_STRING` in app setting.

~> **Note:** For health check related settings, please use `health_check_eviction_time_in_min`, terraform will assign the value to the key `WEBSITE_HEALTHCHECK_MAXPINGFAILURES` in app setting.

~> **Note:** Please create a predefined share if you are restricting your storage account to a virtual network by setting `WEBSITE_CONTENTOVERVNET` to 1 in app_setting.

* `auth_settings` - (Optional) A `auth_settings` block as defined below.

Expand Down

0 comments on commit 1ed6ded

Please sign in to comment.