Skip to content

Commit

Permalink
azurerm_windows[linux]_function[web]_app, `azurerm_windows[linux]_f…
Browse files Browse the repository at this point in the history
…unction[web]_app_slot` - add `description` property for `ip_restriction` block (#24527)

* add description for ip restriction block

* update

* update test cases

* add linter ignore

* add ignore linter
  • Loading branch information
xiaxyi authored Mar 6, 2024
1 parent ef1b64e commit 102f63a
Show file tree
Hide file tree
Showing 17 changed files with 554 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/services/appservice/helpers/shared_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type IpRestriction struct {
Priority int64 `tfschema:"priority"`
Action string `tfschema:"action"`
Headers []IpRestrictionHeaders `tfschema:"headers"`
Description string `tfschema:"description"`
}

type IpRestrictionHeaders struct {
Expand Down Expand Up @@ -104,6 +105,13 @@ func IpRestrictionSchema() *pluginsdk.Schema {
},

"headers": IpRestrictionHeadersSchema(),

"description": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The description of the IP restriction rule.",
},
},
},
}
Expand Down Expand Up @@ -153,6 +161,12 @@ func IpRestrictionSchemaComputed() *pluginsdk.Schema {
},

"headers": IpRestrictionHeadersSchemaComputed(),

"description": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The description of the ip restriction rule.",
},
},
},
}
Expand Down Expand Up @@ -1155,6 +1169,10 @@ func ExpandIpRestrictions(restrictions []IpRestriction) (*[]webapps.IPSecurityRe
restriction.VnetSubnetResourceId = utils.String(v.VnetSubnetId)
}

if v.Description != "" {
restriction.Description = pointer.To(v.Description)
}

restriction.Priority = pointer.To(v.Priority)

restriction.Action = pointer.To(v.Action)
Expand Down Expand Up @@ -1493,6 +1511,9 @@ func FlattenIpRestrictions(ipRestrictionsList *[]webapps.IPSecurityRestriction)
}

ipRestriction.Headers = flattenIpRestrictionHeaders(pointer.From(v.Headers))
if v.Description != nil {
ipRestriction.Description = *v.Description
}

ipRestrictions = append(ipRestrictions, ipRestriction)
}
Expand Down
68 changes: 68 additions & 0 deletions internal/services/appservice/linux_function_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ func TestAccLinuxFunctionApp_withIPRestrictions(t *testing.T) {
})
}

func TestAccLinuxFunctionApp_withIPRestrictionsDescription(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_function_app", "test")
r := LinuxFunctionAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictionsDescription(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

func TestAccLinuxFunctionApp_withIPRestrictionsDefaultAction(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_function_app", "test")
r := LinuxFunctionAppResource{}
Expand Down Expand Up @@ -1912,6 +1944,42 @@ resource "azurerm_linux_function_app" "test" {
`, r.template(data, SkuStandardPlan), data.RandomInteger)
}

func (r LinuxFunctionAppResource) withIPRestrictionsDescription(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_linux_function_app" "test" {
name = "acctest-LFA-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
service_plan_id = azurerm_service_plan.test.id
storage_account_name = azurerm_storage_account.test.name
storage_account_access_key = azurerm_storage_account.test.primary_access_key
site_config {
ip_restriction {
ip_address = "13.107.6.152/31,13.107.128.0/22"
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_azure_fdid = ["55ce4ed1-4b06-4bf1-b40e-4638452104da"]
x_fd_health_probe = ["1"]
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address linux function app"
}
}
}
`, r.template(data, SkuStandardPlan), data.RandomInteger)
}

func (r LinuxFunctionAppResource) withIPRestrictionsDefaultActionDeny(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,38 @@ func TestAccLinuxFunctionAppSlot_withIPRestrictions(t *testing.T) {
})
}

func TestAccLinuxFunctionAppSlot_withIPRestrictionsDescription(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_function_app_slot", "test")
r := LinuxFunctionAppSlotResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withIPRestrictions(data, SkuStandardPlan),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictionsDescription(data, SkuStandardPlan),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictions(data, SkuStandardPlan),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("kind").HasValue("functionapp,linux"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

func TestAccLinuxFunctionAppSlot_withIPRestrictionsDefaultAction(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_function_app_slot", "test")
r := LinuxFunctionAppSlotResource{}
Expand Down Expand Up @@ -1805,6 +1837,7 @@ resource "azurerm_linux_function_app_slot" "test" {
`, r.template(data, planSku), data.RandomInteger, javaVersion)
}

// nolint: unparam
func (r LinuxFunctionAppSlotResource) withIPRestrictions(data acceptance.TestData, planSku string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -1836,6 +1869,39 @@ resource "azurerm_linux_function_app_slot" "test" {
}
`, r.template(data, planSku), data.RandomInteger)
}

func (r LinuxFunctionAppSlotResource) withIPRestrictionsDescription(data acceptance.TestData, planSku string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_linux_function_app_slot" "test" {
name = "acctest-LFAS-%d"
function_app_id = azurerm_linux_function_app.test.id
storage_account_name = azurerm_storage_account.test.name
storage_account_access_key = azurerm_storage_account.test.primary_access_key
site_config {
ip_restriction {
ip_address = "13.107.6.152/31,13.107.128.0/22"
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_azure_fdid = ["55ce4ed1-4b06-4bf1-b40e-4638452104da"]
x_fd_health_probe = ["1"]
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address linux function app"
}
}
}
`, r.template(data, planSku), data.RandomInteger)
}
func (r LinuxFunctionAppSlotResource) withIPRestrictionsDefaultActionDeny(data acceptance.TestData, planSku string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -2331,6 +2397,7 @@ resource "azurerm_linux_function_app_slot" "test" {
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address 10.10.10.10/32"
}
load_balancing_mode = "LeastResponseTime"
Expand Down
62 changes: 62 additions & 0 deletions internal/services/appservice/linux_web_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,35 @@ func TestAccLinuxWebApp_withIPRestrictions(t *testing.T) {
})
}

func TestAccLinuxWebApp_withIPRestrictionsDescription(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_web_app", "test")
r := LinuxWebAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictionsDescription(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
})
}

func TestAccLinuxWebApp_withIPRestrictionsDefaultAction(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_web_app", "test")
r := LinuxWebAppResource{}
Expand Down Expand Up @@ -2528,6 +2557,39 @@ resource "azurerm_linux_web_app" "test" {
`, r.baseTemplate(data), data.RandomInteger)
}

func (r LinuxWebAppResource) withIPRestrictionsDescription(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_linux_web_app" "test" {
name = "acctestWA-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
service_plan_id = azurerm_service_plan.test.id
site_config {
ip_restriction {
ip_address = "10.10.10.10/32"
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_azure_fdid = ["55ce4ed1-4b06-4bf1-b40e-4638452104da"]
x_fd_health_probe = ["1"]
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address 10.10.10.10/32"
}
}
}
`, r.baseTemplate(data), data.RandomInteger)
}

func (r LinuxWebAppResource) withIPRestrictionsDefaultActionDeny(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
61 changes: 61 additions & 0 deletions internal/services/appservice/linux_web_app_slot_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,35 @@ func TestAccLinuxWebAppSlot_withIPRestrictions(t *testing.T) {
})
}

func TestAccLinuxWebAppSlot_withIPRestrictionsDescription(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_web_app_slot", "test")
r := LinuxWebAppSlotResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictionsDescription(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.withIPRestrictions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("site_credential.0.password"),
})
}

func TestAccLinuxWebAppSlot_withIPRestrictionsDefaultAction(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_web_app_slot", "test")
r := LinuxWebAppSlotResource{}
Expand Down Expand Up @@ -2080,6 +2109,37 @@ resource "azurerm_linux_web_app_slot" "test" {
`, r.baseTemplate(data), data.RandomInteger)
}

func (r LinuxWebAppSlotResource) withIPRestrictionsDescription(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_linux_web_app_slot" "test" {
name = "acctestWAS-%d"
app_service_id = azurerm_linux_web_app.test.id
site_config {
ip_restriction {
ip_address = "10.10.10.10/32"
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_azure_fdid = ["55ce4ed1-4b06-4bf1-b40e-4638452104da"]
x_fd_health_probe = ["1"]
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address linux function app"
}
}
}
`, r.baseTemplate(data), data.RandomInteger)
}

func (r LinuxWebAppSlotResource) withIPRestrictionsDefaultActionDeny(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -2136,6 +2196,7 @@ resource "azurerm_linux_web_app_slot" "test" {
x_forwarded_for = ["9.9.9.9/32", "2002::1234:abcd:ffff:c0a8:101/64"]
x_forwarded_host = ["example.com"]
}
description = "Allow ip address linux web app slot"
}
}
}
Expand Down
Loading

0 comments on commit 102f63a

Please sign in to comment.