diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index fd9ae4b636f2..b18c16733640 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -316,6 +316,18 @@ func SchemaAppServiceSiteConfig() *schema.Schema { Optional: true, ValidateFunc: validation.StringIsNotEmpty, }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "priority": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(1, 2147483647), + }, }, }, }, @@ -679,6 +691,14 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema { Type: schema.TypeString, Computed: true, }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "priority": { + Type: schema.TypeInt, + Computed: true, + }, }, }, }, @@ -1419,6 +1439,8 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) { ipAddress := restriction["ip_address"].(string) vNetSubnetID := restriction["virtual_network_subnet_id"].(string) + name := restriction["name"].(string) + priority := restriction["priority"].(int) if vNetSubnetID != "" && ipAddress != "" { return siteConfig, fmt.Errorf(fmt.Sprintf("only one of `ip_address` or `virtual_network_subnet_id` can be set for `site_config.0.ip_restriction.%d`", i)) } @@ -1440,6 +1462,14 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) { ipSecurityRestriction.VnetSubnetResourceID = &vNetSubnetID } + if name != "" { + ipSecurityRestriction.Name = &name + } + + if priority != 0 { + ipSecurityRestriction.Priority = utils.Int32(int32(priority)) + } + restrictions = append(restrictions, ipSecurityRestriction) } siteConfig.IPSecurityRestrictions = &restrictions @@ -1564,6 +1594,12 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { if vNetSubnetID := v.VnetSubnetResourceID; vNetSubnetID != nil { block["virtual_network_subnet_id"] = *vNetSubnetID } + if name := v.Name; name != nil { + block["name"] = *name + } + if priority := v.Priority; priority != nil { + block["priority"] = *priority + } restrictions = append(restrictions, block) } } diff --git a/azurerm/internal/services/web/tests/data_source_app_service_test.go b/azurerm/internal/services/web/tests/data_source_app_service_test.go index 263e30d8896f..570d1e9fcf53 100644 --- a/azurerm/internal/services/web/tests/data_source_app_service_test.go +++ b/azurerm/internal/services/web/tests/data_source_app_service_test.go @@ -137,6 +137,8 @@ func TestAccDataSourceAzureRMAppService_ipRestriction(t *testing.T) { Config: testAccDataSourceAppService_ipRestriction(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10/32"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.name", "test-restriction"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.priority", "123"), ), }, }, @@ -271,7 +273,7 @@ data "azurerm_app_service" "test" { } func testAccDataSourceAppService_ipRestriction(data acceptance.TestData) string { - config := testAccAzureRMAppService_oneIpRestriction(data) + config := testAccAzureRMAppService_completeIpRestriction(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go index 777493cc5075..00afcba2f640 100644 --- a/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go @@ -857,7 +857,7 @@ func TestAccAzureRMAppServiceSlot_remoteDebugging(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceSlotExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_version", "VS2015"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_version", "VS2019"), ), }, }, @@ -3109,7 +3109,7 @@ resource "azurerm_app_service_slot" "test" { site_config { remote_debugging_enabled = true - remote_debugging_version = "VS2015" + remote_debugging_version = "VS2019" } tags = { diff --git a/azurerm/internal/services/web/tests/resource_arm_app_service_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go index 5acb93cc831c..709c9b40fe8b 100644 --- a/azurerm/internal/services/web/tests/resource_arm_app_service_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go @@ -514,6 +514,53 @@ func TestAccAzureRMAppService_oneIpRestriction(t *testing.T) { }) } +func TestAccAzureRMAppService_completeIpRestriction(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAppService_completeIpRestriction(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10/32"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.name", "test-restriction"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.priority", "123"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMAppService_manyCompleteIpRestrictions(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10/32"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.name", "test-restriction"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.priority", "123"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.ip_address", "20.20.20.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.name", "test-restriction-2"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.priority", "1234"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMAppService_completeIpRestriction(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10/32"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.name", "test-restriction"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.priority", "123"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMAppService_oneVNetSubnetIpRestriction(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ @@ -2582,6 +2629,90 @@ resource "azurerm_app_service" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } +func testAccAzureRMAppService_completeIpRestriction(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +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 { + ip_restriction { + ip_address = "10.10.10.10/32" + name = "test-restriction" + priority = 123 + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMAppService_manyCompleteIpRestrictions(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +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 { + ip_restriction { + ip_address = "10.10.10.10/32" + name = "test-restriction" + priority = 123 + } + + ip_restriction { + ip_address = "20.20.20.0/24" + name = "test-restriction-2" + priority = 1234 + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + func testAccAzureRMAppService_oneVNetSubnetIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/d/app_service.html.markdown b/website/docs/d/app_service.html.markdown index 07d6832efc6b..b73d39320132 100644 --- a/website/docs/d/app_service.html.markdown +++ b/website/docs/d/app_service.html.markdown @@ -85,6 +85,10 @@ A `ip_restriction` block exports the following: * `subnet_mask` - The Subnet mask used for this IP Restriction. +* `name` - The name for this IP Restriction. + +* `priority` - The priority for this IP Restriction. + --- `site_config` supports the following: diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 71470c6a9892..b044515baa89 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -309,6 +309,10 @@ A `ip_restriction` block supports the following: -> **NOTE:** One of either `ip_address` or `virtual_network_subnet_id` must be specified +* `name` - (Optional) The name for this IP Restriction. + +* `priority` - (Optional) The priority for this IP Restriction. Restrictions are enforced in priority order. By default, priority is set to 65000 if not specified. + --- A `microsoft` block supports the following: