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

resource/function_app: Share the site_config schema of app_service #3666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
99 changes: 6 additions & 93 deletions azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,7 @@ func resourceArmFunctionApp() *schema.Resource {
Default: false,
},

"site_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"always_on": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"use_32_bit_worker_process": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"websockets_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"linux_fx_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
},
"site_config": azure.SchemaAppServiceSiteConfig(),

"site_credential": {
Type: schema.TypeList,
Expand Down Expand Up @@ -274,7 +245,7 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro

basicAppSettings := getBasicFunctionAppAppSettings(d, appServiceTier)

siteConfig := expandFunctionAppSiteConfig(d)
siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
siteConfig.AppSettings = &basicAppSettings

siteEnvelope := web.Site{
Expand Down Expand Up @@ -345,7 +316,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro
return err
}
basicAppSettings := getBasicFunctionAppAppSettings(d, appServiceTier)
siteConfig := expandFunctionAppSiteConfig(d)
siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
siteConfig.AppSettings = &basicAppSettings

siteEnvelope := web.Site{
Expand Down Expand Up @@ -387,7 +358,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro
}

if d.HasChange("site_config") {
siteConfig := expandFunctionAppSiteConfig(d)
siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
siteConfigResource := web.SiteConfigResource{
SiteConfig: &siteConfig,
}
Expand Down Expand Up @@ -509,8 +480,8 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error making Read request on AzureRM Function App Configuration %q: %+v", name, err)
}

siteConfig := flattenFunctionAppSiteConfig(configResp.SiteConfig)
if err = d.Set("site_config", siteConfig); err != nil {
siteConfig := azure.FlattenAppServiceSiteConfig(configResp.SiteConfig)
if err := d.Set("site_config", siteConfig); err != nil {
return err
}

Expand Down Expand Up @@ -619,64 +590,6 @@ func expandFunctionAppAppSettings(d *schema.ResourceData, appServiceTier string)
return output
}

func expandFunctionAppSiteConfig(d *schema.ResourceData) web.SiteConfig {
configs := d.Get("site_config").([]interface{})
siteConfig := web.SiteConfig{}

if len(configs) == 0 {
return siteConfig
}

config := configs[0].(map[string]interface{})

if v, ok := config["always_on"]; ok {
siteConfig.AlwaysOn = utils.Bool(v.(bool))
}

if v, ok := config["use_32_bit_worker_process"]; ok {
siteConfig.Use32BitWorkerProcess = utils.Bool(v.(bool))
}

if v, ok := config["websockets_enabled"]; ok {
siteConfig.WebSocketsEnabled = utils.Bool(v.(bool))
}

if v, ok := config["linux_fx_version"]; ok {
siteConfig.LinuxFxVersion = utils.String(v.(string))
}

return siteConfig
}

func flattenFunctionAppSiteConfig(input *web.SiteConfig) []interface{} {
results := make([]interface{}, 0)
result := make(map[string]interface{})

if input == nil {
log.Printf("[DEBUG] SiteConfig is nil")
return results
}

if input.AlwaysOn != nil {
result["always_on"] = *input.AlwaysOn
}

if input.Use32BitWorkerProcess != nil {
result["use_32_bit_worker_process"] = *input.Use32BitWorkerProcess
}

if input.WebSocketsEnabled != nil {
result["websockets_enabled"] = *input.WebSocketsEnabled
}

if input.LinuxFxVersion != nil {
result["linux_fx_version"] = *input.LinuxFxVersion
}

results = append(results, result)
return results
}

func expandFunctionAppConnectionStrings(d *schema.ResourceData) map[string]*web.ConnStringValueTypePair {
input := d.Get("connection_string").([]interface{})
output := make(map[string]*web.ConnStringValueTypePair, len(input))
Expand Down
76 changes: 76 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,35 @@ func TestAccAzureRMFunctionApp_updateLogging(t *testing.T) {
})
}

func TestAccAzureRMFunctionApp_corsSettings(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := tf.AccRandTimeInt()
rs := strings.ToLower(acctest.RandString(11))
config := testAccAzureRMFunctionApp_corsSettings(ri, rs, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.support_credentials", "true"),
resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.#", "3"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMFunctionAppDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient

Expand Down Expand Up @@ -1050,6 +1079,53 @@ resource "azurerm_function_app" "test" {
`, rInt, location, rString)
}

func testAccAzureRMFunctionApp_corsSettings(rInt int, rString, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_storage_account" "test" {
name = "acctestsa%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_function_app" "test" {
name = "acctest-%[1]d-func"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"

site_config {
cors {
allowed_origins = [
"http://www.contoso.com",
"www.contoso.com",
"contoso.com"
]
support_credentials = true
}
}
}
`, rInt, location, rString)
}

func testAccAzureRMFunctionApp_appSettingsAlwaysOn(rInt int, rString, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
61 changes: 57 additions & 4 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,67 @@ The following arguments are supported:

`site_config` supports the following:

* `always_on` - (Optional) Should the Function App be loaded at all times? Defaults to `false`.
* `use_32_bit_worker_process` - (Optional) Should the Function App run in 32 bit mode, rather than 64 bit mode? Defaults to `true`.
* `always_on` - (Optional) Should the app be loaded at all times? Defaults to `false`.

~> **Note:** when using an App Service Plan in the `Free` or `Shared` Tiers `use_32_bit_worker_process` must be set to `true`.
* `app_command_line` - (Optional) App command line to launch, e.g. `/sbin/myserver -b 0.0.0.0`.

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

* `default_documents` - (Optional) The ordering of default documents to load, if an address isn't specified.

* `dotnet_framework_version` - (Optional) The version of the .net framework's CLR used in this App Service. Possible values are `v2.0` (which will use the latest version of the .net framework for the .net CLR v2 - currently `.net 3.5`) and `v4.0` (which corresponds to the latest version of the .net CLR v4 - which at the time of writing is `.net 4.7.1`). [For more information on which .net CLR version to use based on the .net framework you're targeting - please see this table](https://en.wikipedia.org/wiki/.NET_Framework_version_history#Overview). Defaults to `v4.0`.

* `ftps_state` - (Optional) State of FTP / FTPS service for this App Service. Possible values include: `AllAllowed`, `FtpsOnly` and `Disabled`.

* `http2_enabled` - (Optional) Is HTTP2 Enabled on this App Service? Defaults to `false`.

* `ip_restriction` - (Optional) A [List of objects](/docs/configuration/attr-as-blocks.html) representing ip restrictions as defined below.

* `java_version` - (Optional) The version of Java to use. If specified `java_container` and `java_container_version` must also be specified. Possible values are `1.7`, `1.8` and `11`.

* `java_container` - (Optional) The Java Container to use. If specified `java_version` and `java_container_version` must also be specified. Possible values are `JETTY` and `TOMCAT`.

* `java_container_version` - (Optional) The version of the Java Container to use. If specified `java_version` and `java_container` must also be specified.

* `local_mysql_enabled` - (Optional) Is "MySQL In App" Enabled? This runs a local MySQL instance with your app and shares resources from the App Service plan.

~> **NOTE:** MySQL In App is not intended for production environments and will not scale beyond a single instance. Instead you may wish [to use Azure Database for MySQL](/docs/providers/azurerm/r/mysql_database.html).

* `linux_fx_version` - (Optional) Linux App Framework and version for the App Service. Possible options are a Docker container (`DOCKER|<user/image:tag>`), a base-64 encoded Docker Compose file (`COMPOSE|${filebase64("compose.yml")}`) or a base-64 encoded Kubernetes Manifest (`KUBE|${filebase64("kubernetes.yml")}`).

* `windows_fx_version` - (Optional) The Windows Docker container image (`DOCKER|<user/image:tag>`)

Additional examples of how to run Containers via the `azurerm_app_service` resource can be found in [the `./examples/app-service` directory within the Github Repository](https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/app-service).

* `managed_pipeline_mode` - (Optional) The Managed Pipeline Mode. Possible values are `Integrated` and `Classic`. Defaults to `Integrated`.

* `min_tls_version` - (Optional) The minimum supported TLS version for the app service. Possible values are `1.0`, `1.1`, and `1.2`. Defaults to `1.2` for new app services.

* `php_version` - (Optional) The version of PHP to use in this App Service. Possible values are `5.5`, `5.6`, `7.0`, `7.1` and `7.2`.

* `python_version` - (Optional) The version of Python to use in this App Service. Possible values are `2.7` and `3.4`.

* `remote_debugging_enabled` - (Optional) Is Remote Debugging Enabled? Defaults to `false`.

* `remote_debugging_version` - (Optional) Which version of Visual Studio should the Remote Debugger be compatible with? Possible values are `VS2012`, `VS2013`, `VS2015` and `VS2017`.

* `scm_type` - (Optional) The type of Source Control enabled for this App Service. Defaults to `None`. Possible values are: `BitbucketGit`, `BitbucketHg`, `CodePlexGit`, `CodePlexHg`, `Dropbox`, `ExternalGit`, `ExternalHg`, `GitHub`, `LocalGit`, `None`, `OneDrive`, `Tfs`, `VSO` and `VSTSRM`

* `use_32_bit_worker_process` - (Optional) Should the App Service run in 32 bit mode, rather than 64 bit mode?

~> **NOTE:** when using an App Service Plan in the `Free` or `Shared` Tiers `use_32_bit_worker_process` must be set to `true`.

* `virtual_network_name` - (Optional) The name of the Virtual Network which this App Service should be attached to.

* `websockets_enabled` - (Optional) Should WebSockets be enabled?

* `linux_fx_version` - (Optional) Linux App Framework and version for the AppService, e.g. `DOCKER|(golang:latest)`.
---

A `cors` block supports the following:

* `allowed_origins` - (Optional) A list of origins which should be able to make cross-origin calls. `*` can be used to allow all calls.

* `support_credentials` - (Optional) Are credentials supported?

---

Expand Down