From 357f1588750833337d26010d3eb76e4a6f5a918c Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Mon, 11 Feb 2019 22:11:49 +0100 Subject: [PATCH 01/13] Add CORS to schema --- azurerm/helpers/azure/app_service.go | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index e774fff5dfb8..ced6f34f5b27 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -12,6 +12,25 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +// Once Microsoft adds support for `supports_credentials` in their SDK we should add that to this schema. +func SchemaAppServiceCorsSettings() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allowed_origins": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + } +} + func SchemaAppServiceSiteConfig() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, @@ -207,11 +226,55 @@ func SchemaAppServiceSiteConfig() *schema.Schema { Type: schema.TypeString, Optional: true, }, + + "cors": SchemaAppServiceCorsSettings(), }, }, } } +func ExpandAppServiceCorsSettings(input interface{}) web.CorsSettings { + settings := input.([]interface{}) + corsSettings := web.CorsSettings{} + + if len(settings) == 0 { + return corsSettings + } + + setting := settings[0].(map[string]interface{}) + + if v, ok := setting["allowed_origins"]; ok { + input := v.([]interface{}) + + allowedOrigins := make([]string, 0) + for _, param := range input { + allowedOrigins = append(allowedOrigins, param.(string)) + } + + corsSettings.AllowedOrigins = &allowedOrigins + } + + return corsSettings +} + +func FlattenAppServiceCorsSettings(input *web.CorsSettings) []interface{} { + results := make([]interface{}, 0) + result := make(map[string]interface{}) + + if input == nil { + log.Printf("[DEBUG] CorsSettings is nil") + return results + } + + allowedOrigins := make([]string, 0) + if s := input.AllowedOrigins; s != nil { + allowedOrigins = *s + } + result["allowed_origins"] = allowedOrigins + + return append(results, result) +} + func ExpandAppServiceSiteConfig(input interface{}) web.SiteConfig { configs := input.([]interface{}) siteConfig := web.SiteConfig{} @@ -340,6 +403,12 @@ func ExpandAppServiceSiteConfig(input interface{}) web.SiteConfig { siteConfig.VnetName = utils.String(v.(string)) } + if v, ok := config["cors"]; ok { + corsSettings := v.(interface{}) + expand := ExpandAppServiceCorsSettings(corsSettings) + siteConfig.Cors = &expand + } + return siteConfig } @@ -451,5 +520,9 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["ftps_state"] = string(input.FtpsState) result["min_tls_version"] = string(input.MinTLSVersion) + if input.Cors != nil { + result["cors"] = FlattenAppServiceCorsSettings(input.Cors) + } + return append(results, result) } From 7f4cb2104dda43f8759e62d9cb182ec5e191f64b Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Mon, 11 Feb 2019 22:12:11 +0100 Subject: [PATCH 02/13] Add acctest --- azurerm/resource_arm_app_service_test.go | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 0731acffab9a..5d174cf541cc 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -1182,6 +1182,35 @@ func TestAccAzureRMAppService_minTls(t *testing.T) { }) } +func TestAccAzureRMAppService_corsSettings(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := tf.AccRandTimeInt() + config := testAccAzureRMAppService_corsSettings(ri, testLocation()) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.#", "1"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.#", "3"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.0", "http://www.contoso.com"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.1", "www.contoso.com"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.2", "contoso.com"), + )}, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).appServicesClient @@ -2412,3 +2441,40 @@ resource "azurerm_app_service" "test" { } `, rInt, location, rInt, rInt, tlsVersion) } + +func testAccAzureRMAppService_corsSettings(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_app_service_plan" "test" { + name = "acctestASP-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + tier = "Standard" + size = "S1" + } +} + +resource "azurerm_app_service" "test" { + name = "acctestAS-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + + site_config { + cors { + allowed_origins = [ + "http://www.contoso.com", + "www.contoso.com", + "contoso.com" + ] + } + } +} +`, rInt, location, rInt, rInt) +} From 8f62150edc48c851dd732fb201870a9f3ed58682 Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Mon, 11 Feb 2019 22:12:23 +0100 Subject: [PATCH 03/13] Add documentation --- website/docs/r/app_service.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index aec06d99abfa..e24e76f7726e 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -191,6 +191,8 @@ The following arguments are supported: * `websockets_enabled` - (Optional) Should WebSockets be enabled? +* `cors` - (Optional) CORS settings + --- `ip_restriction` supports the following: @@ -243,6 +245,12 @@ The following attributes are exported: * `repo_url` - URL of the Git repository for this App Service. * `branch` - Branch name of the Git repository for this App Service. +--- + +`cors` supports the following: + +* `allowed_origins` - (Required) List of allowed origins + ## Import App Services can be imported using the `resource id`, e.g. From b1cd596765e65c49185466ececef24768c0ee18d Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Thu, 14 Feb 2019 13:54:48 +0100 Subject: [PATCH 04/13] Add support_credentials --- azurerm/helpers/azure/app_service.go | 13 +++++++++++++ azurerm/resource_arm_app_service_test.go | 4 +++- website/docs/r/app_service.html.markdown | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index ced6f34f5b27..87e76f805651 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -26,6 +26,11 @@ func SchemaAppServiceCorsSettings() *schema.Schema { Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "support_credentials": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, } @@ -254,6 +259,10 @@ func ExpandAppServiceCorsSettings(input interface{}) web.CorsSettings { corsSettings.AllowedOrigins = &allowedOrigins } + if v, ok := setting["support_credentials"]; ok { + corsSettings.SupportCredentials = utils.Bool(v.(bool)) + } + return corsSettings } @@ -272,6 +281,10 @@ func FlattenAppServiceCorsSettings(input *web.CorsSettings) []interface{} { } result["allowed_origins"] = allowedOrigins + if input.SupportCredentials != nil { + result["support_credentials"] = *input.SupportCredentials + } + return append(results, result) } diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 5d174cf541cc..e07d2c5d62f6 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -1197,6 +1197,7 @@ func TestAccAzureRMAppService_corsSettings(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(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"), resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.0", "http://www.contoso.com"), resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.1", "www.contoso.com"), @@ -2472,7 +2473,8 @@ resource "azurerm_app_service" "test" { "http://www.contoso.com", "www.contoso.com", "contoso.com" - ] + ] + support_credentials = true } } } diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index e24e76f7726e..6d1230b53115 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -251,6 +251,8 @@ The following attributes are exported: * `allowed_origins` - (Required) List of allowed origins +* `support_credentials` - (Optional) Should credential headers be allowed? Defaults to `false`. + ## Import App Services can be imported using the `resource id`, e.g. From 427bb9f631fc72c379e4e8443eb39ad94b67913f Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Thu, 14 Feb 2019 14:32:29 +0100 Subject: [PATCH 05/13] Convert tabs to spaces --- azurerm/resource_arm_app_service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index e07d2c5d62f6..af0e2cd19280 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -2473,8 +2473,8 @@ resource "azurerm_app_service" "test" { "http://www.contoso.com", "www.contoso.com", "contoso.com" - ] - support_credentials = true + ] + support_credentials = true } } } From 3fbbeccddeaf275db863b4b50bf0e057c568738a Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Sat, 23 Feb 2019 15:48:32 +0100 Subject: [PATCH 06/13] Change allowed_origin Type to TypeSet --- azurerm/helpers/azure/app_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index 87e76f805651..e64a0819a838 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -22,7 +22,7 @@ func SchemaAppServiceCorsSettings() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "allowed_origins": { - Type: schema.TypeList, + Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, From a3d61b7598ef5cef51df75d475012c597825b52b Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Thu, 28 Feb 2019 14:47:33 +0100 Subject: [PATCH 07/13] Change description of cors block --- website/docs/r/app_service.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 6d1230b53115..1d1471e17ace 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -191,7 +191,7 @@ The following arguments are supported: * `websockets_enabled` - (Optional) Should WebSockets be enabled? -* `cors` - (Optional) CORS settings +* `cors` - A `cors` block as defined below. --- From 98a4815072d4fda224c556367f43aca1d6ca6b57 Mon Sep 17 00:00:00 2001 From: Joakim Hansson Date: Thu, 28 Feb 2019 14:51:31 +0100 Subject: [PATCH 08/13] Remove comment related to azure SDK update --- azurerm/helpers/azure/app_service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index e64a0819a838..a2e4194851ef 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -// Once Microsoft adds support for `supports_credentials` in their SDK we should add that to this schema. func SchemaAppServiceCorsSettings() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, From 378752984a4734b3c7814bbfd0ef77aad88d5655 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 29 Mar 2019 11:49:04 +0100 Subject: [PATCH 09/13] Changes from code review --- azurerm/data_source_app_service.go | 2 +- azurerm/helpers/azure/app_service.go | 182 +++++++++++++++++- azurerm/resource_arm_app_service_slot_test.go | 73 +++++++ azurerm/resource_arm_app_service_test.go | 3 - website/docs/d/app_service.html.markdown | 28 ++- website/docs/r/app_service.html.markdown | 11 +- website/docs/r/app_service_slot.html.markdown | 20 +- 7 files changed, 293 insertions(+), 26 deletions(-) diff --git a/azurerm/data_source_app_service.go b/azurerm/data_source_app_service.go index 445306507990..5977abbbd9ff 100644 --- a/azurerm/data_source_app_service.go +++ b/azurerm/data_source_app_service.go @@ -28,7 +28,7 @@ func dataSourceArmAppService() *schema.Resource { Computed: true, }, - "site_config": azure.SchemaAppServiceSiteConfig(), + "site_config": azure.SchemaAppServiceDataSourceSiteConfig(), "client_affinity_enabled": { Type: schema.TypeBool, diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index a2e4194851ef..1148fac6a1a7 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -231,7 +231,178 @@ func SchemaAppServiceSiteConfig() *schema.Schema { Optional: true, }, - "cors": SchemaAppServiceCorsSettings(), + "cors": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allowed_origins": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "support_credentials": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, + }, + }, + } +} + +func SchemaAppServiceDataSourceSiteConfig() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "always_on": { + Type: schema.TypeBool, + Computed: true, + }, + + "app_command_line": { + Type: schema.TypeString, + Computed: true, + }, + + "default_documents": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "dotnet_framework_version": { + Type: schema.TypeString, + Computed: true, + }, + + "http2_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "ip_restriction": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "subnet_mask": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "java_version": { + Type: schema.TypeString, + Computed: true, + }, + + "java_container": { + Type: schema.TypeString, + Computed: true, + }, + + "java_container_version": { + Type: schema.TypeString, + Computed: true, + }, + + "local_mysql_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "managed_pipeline_mode": { + Type: schema.TypeString, + Computed: true, + }, + + "php_version": { + Type: schema.TypeString, + Computed: true, + }, + + "python_version": { + Type: schema.TypeString, + Computed: true, + }, + + "remote_debugging_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "remote_debugging_version": { + Type: schema.TypeString, + Computed: true, + }, + + "scm_type": { + Type: schema.TypeString, + Computed: true, + }, + + "use_32_bit_worker_process": { + Type: schema.TypeBool, + Computed: true, + }, + + "websockets_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "ftps_state": { + Type: schema.TypeString, + Computed: true, + }, + + "linux_fx_version": { + Type: schema.TypeString, + Computed: true, + }, + + "min_tls_version": { + Type: schema.TypeString, + Computed: true, + }, + + "virtual_network_name": { + Type: schema.TypeString, + Computed: true, + }, + + "cors": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allowed_origins": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "support_credentials": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, }, }, } @@ -267,13 +438,12 @@ func ExpandAppServiceCorsSettings(input interface{}) web.CorsSettings { func FlattenAppServiceCorsSettings(input *web.CorsSettings) []interface{} { results := make([]interface{}, 0) - result := make(map[string]interface{}) - if input == nil { - log.Printf("[DEBUG] CorsSettings is nil") return results } + result := make(map[string]interface{}) + allowedOrigins := make([]string, 0) if s := input.AllowedOrigins; s != nil { allowedOrigins = *s @@ -532,9 +702,7 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["ftps_state"] = string(input.FtpsState) result["min_tls_version"] = string(input.MinTLSVersion) - if input.Cors != nil { - result["cors"] = FlattenAppServiceCorsSettings(input.Cors) - } + result["cors"] = FlattenAppServiceCorsSettings(input.Cors) return append(results, result) } diff --git a/azurerm/resource_arm_app_service_slot_test.go b/azurerm/resource_arm_app_service_slot_test.go index f155754d2ae8..35a9001780fa 100644 --- a/azurerm/resource_arm_app_service_slot_test.go +++ b/azurerm/resource_arm_app_service_slot_test.go @@ -258,6 +258,33 @@ func TestAccAzureRMAppServiceSlot_connectionStrings(t *testing.T) { }) } +func TestAccAzureRMAppServiceSlot_corsSettings(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAppServiceSlot_corsSettings(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(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 TestAccAzureRMAppServiceSlot_defaultDocuments(t *testing.T) { resourceName := "azurerm_app_service_slot.test" ri := tf.AccRandTimeInt() @@ -1251,6 +1278,52 @@ resource "azurerm_app_service_slot" "test" { `, rInt, location, rInt, rInt, rInt) } +func testAccAzureRMAppServiceSlot_corsSettings(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_app_service_plan" "test" { + name = "acctestASP-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + tier = "Standard" + size = "S1" + } +} + +resource "azurerm_app_service" "test" { + name = "acctestAS-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + app_service_plan_id = "${azurerm_app_service_plan.test.id}" +} + +resource "azurerm_app_service_slot" "test" { + name = "acctestASSlot-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + app_service_name = "${azurerm_app_service.test.name}" + + site_config { + cors { + allowed_origins = [ + "http://www.contoso.com", + "www.contoso.com", + "contoso.com" + ] + support_credentials = true + } + } +} +`, rInt, location, rInt, rInt, rInt) +} + func testAccAzureRMAppServiceSlot_defaultDocuments(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index af0e2cd19280..d150fcc78ce1 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -1199,9 +1199,6 @@ func TestAccAzureRMAppService_corsSettings(t *testing.T) { 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"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.0", "http://www.contoso.com"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.1", "www.contoso.com"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.2", "contoso.com"), )}, { ResourceName: resourceName, diff --git a/website/docs/d/app_service.html.markdown b/website/docs/d/app_service.html.markdown index 1c771a698874..d310167f14fe 100644 --- a/website/docs/d/app_service.html.markdown +++ b/website/docs/d/app_service.html.markdown @@ -69,12 +69,30 @@ output "app_service_id" { --- +A `cors` block exports the following: + +* `allowed_origins` - A list of origins which are able to make cross-origin calls. + +* `support_credentials` - Are credentials supported? + +--- + +A `ip_restriction` block exports the following: + +* `ip_address` - The IP Address used for this IP Restriction. + +* `subnet_mask` - The Subnet mask used for this IP Restriction. + +--- + `site_config` supports the following: * `always_on` - Is the app be loaded at all times? * `app_command_line` - App command line to launch. +* `cors` - A `cors` block as defined above. + * `default_documents` - The ordering of default documents to load, if an address isn't specified. * `dotnet_framework_version` - The version of the .net framework's CLR used in this App Service. @@ -83,7 +101,7 @@ output "app_service_id" { * `ftps_state` - State of FTP / FTPS service for this AppService. -* `ip_restriction` - One or more `ip_restriction` blocks as defined below. +* `ip_restriction` - One or more `ip_restriction` blocks as defined above. * `java_version` - The version of Java in use. @@ -114,11 +132,3 @@ output "app_service_id" { * `websockets_enabled` - Are WebSockets enabled for this App Service? * `virtual_network_name` - The name of the Virtual Network which this App Service is attached to. - ---- - -`ip_restriction` exports the following: - -* `ip_address` - The IP Address used for this IP Restriction. - -* `subnet_mask` - The Subnet mask used for this IP Restriction. diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 1d1471e17ace..540fb022f874 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -159,6 +159,7 @@ The following arguments are supported: * `always_on` - (Optional) Should the app be loaded at all times? Defaults to `false`. * `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`. * `http2_enabled` - (Optional) Is HTTP2 Enabled on this App Service? Defaults to `false`. @@ -191,11 +192,17 @@ The following arguments are supported: * `websockets_enabled` - (Optional) Should WebSockets be enabled? -* `cors` - A `cors` block as defined below. +--- + +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? --- -`ip_restriction` supports the following: +A `ip_restriction` block supports the following: * `ip_address` - (Required) The IP Address used for this IP Restriction. diff --git a/website/docs/r/app_service_slot.html.markdown b/website/docs/r/app_service_slot.html.markdown index 9345f03f6ba5..9c0756d6645f 100644 --- a/website/docs/r/app_service_slot.html.markdown +++ b/website/docs/r/app_service_slot.html.markdown @@ -184,6 +184,7 @@ The following arguments are supported: * `always_on` - (Optional) Should the app be loaded at all times? Defaults to `false`. * `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 Slot. 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`. * `http2_enabled` - (Optional) Is HTTP2 Enabled on this App Service? Defaults to `false`. @@ -212,18 +213,29 @@ The following arguments are supported: --- -`ip_restriction` supports the following: +A `cors` block supports the following: -* `ip_address` - (Required) The IP Address used for this IP Restriction. +* `allowed_origins` - (Optional) A list of origins which should be able to make cross-origin calls. `*` can be used to allow all calls. -* `subnet_mask` - (Optional) The Subnet mask used for this IP Restriction. Defaults to `255.255.255.255`. +* `support_credentials` - (Optional) Are credentials supported? + +--- -`identity` supports the following: +A `identity` block supports the following: * `type` - (Required) Specifies the identity type of the App Service. At this time the only allowed value is `SystemAssigned`. ~> The assigned `principal_id` and `tenant_id` can be retrieved after the App Service Slot has been created. +--- + +A `ip_restriction` block supports the following: + +* `ip_address` - (Required) The IP Address used for this IP Restriction. + +* `subnet_mask` - (Optional) The Subnet mask used for this IP Restriction. Defaults to `255.255.255.255`. + + ## Attributes Reference The following attributes are exported: From cd7550c2cd8f5b1b73b1258b2d9b5c504fdde778 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 29 Mar 2019 11:59:59 +0100 Subject: [PATCH 10/13] removing dead code --- azurerm/helpers/azure/app_service.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index 1a3f8659d42a..6c8c9d23be26 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -12,29 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func SchemaAppServiceCorsSettings() *schema.Schema { - return &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "allowed_origins": { - Type: schema.TypeSet, - Required: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "support_credentials": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - }, - }, - } -} - func SchemaAppServiceSiteConfig() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, From 43392dbf7a528f40973870184672ff775e54bbed Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 29 Mar 2019 12:04:48 +0100 Subject: [PATCH 11/13] removing the dupe documentation --- website/docs/r/app_service.html.markdown | 8 -------- 1 file changed, 8 deletions(-) diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 1c89fb77f2e3..30c3a7f80431 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -221,14 +221,6 @@ The following attributes are exported: * `repo_url` - URL of the Git repository for this App Service. * `branch` - Branch name of the Git repository for this App Service. ---- - -`cors` supports the following: - -* `allowed_origins` - (Required) List of allowed origins - -* `support_credentials` - (Optional) Should credential headers be allowed? Defaults to `false`. - ## Import App Services can be imported using the `resource id`, e.g. From 7a9b2cca08d62d3d6a6767809504294eaab95c8e Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 29 Mar 2019 12:29:00 +0100 Subject: [PATCH 12/13] casting to a *schema.Set rather than `[]interface{}` --- azurerm/helpers/azure/app_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index 6c8c9d23be26..c057c1e006eb 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -411,7 +411,7 @@ func ExpandAppServiceCorsSettings(input interface{}) web.CorsSettings { setting := settings[0].(map[string]interface{}) if v, ok := setting["allowed_origins"]; ok { - input := v.([]interface{}) + input := v.(*schema.Set).List() allowedOrigins := make([]string, 0) for _, param := range input { From 83617f18590552423b5d5d71f016de3dd20cc26c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 29 Mar 2019 13:08:29 +0100 Subject: [PATCH 13/13] Fixing the tests --- azurerm/helpers/azure/app_service.go | 8 +++++--- azurerm/resource_arm_app_service_slot_test.go | 3 --- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index c057c1e006eb..16c2cbb66fce 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -436,11 +436,13 @@ func FlattenAppServiceCorsSettings(input *web.CorsSettings) []interface{} { result := make(map[string]interface{}) - allowedOrigins := make([]string, 0) + allowedOrigins := make([]interface{}, 0) if s := input.AllowedOrigins; s != nil { - allowedOrigins = *s + for _, v := range *s { + allowedOrigins = append(allowedOrigins, v) + } } - result["allowed_origins"] = allowedOrigins + result["allowed_origins"] = schema.NewSet(schema.HashString, allowedOrigins) if input.SupportCredentials != nil { result["support_credentials"] = *input.SupportCredentials diff --git a/azurerm/resource_arm_app_service_slot_test.go b/azurerm/resource_arm_app_service_slot_test.go index 897ab6739992..4bb9df69b550 100644 --- a/azurerm/resource_arm_app_service_slot_test.go +++ b/azurerm/resource_arm_app_service_slot_test.go @@ -272,9 +272,6 @@ func TestAccAzureRMAppServiceSlot_corsSettings(t *testing.T) { Config: testAccAzureRMAppServiceSlot_corsSettings(ri, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(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,