Skip to content

Commit

Permalink
Merge pull request #6705 from aqche/app_service_ip_restriction_name_a…
Browse files Browse the repository at this point in the history
…nd_priority
  • Loading branch information
jackofallops committed May 7, 2020
2 parents e451b11 + a6362e4 commit 59f2ddd
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 3 deletions.
36 changes: 36 additions & 0 deletions azurerm/helpers/azure/app_service.go
Expand Up @@ -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),
},
},
},
},
Expand Down Expand Up @@ -685,6 +697,14 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"priority": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -1430,6 +1450,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))
}
Expand All @@ -1451,6 +1473,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
Expand Down Expand Up @@ -1579,6 +1609,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)
}
}
Expand Down
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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 = {
Expand Down
131 changes: 131 additions & 0 deletions azurerm/internal/services/web/tests/resource_arm_app_service_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -2602,6 +2649,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" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/app_service.html.markdown
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/app_service.html.markdown
Expand Up @@ -315,6 +315,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:
Expand Down

0 comments on commit 59f2ddd

Please sign in to comment.