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

"azurerm_key_vault" - supports ipv4 and cidr format for property "network_acls.ip_rules" #10266

Merged
merged 1 commit into from
Jan 27, 2021
Merged
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
11 changes: 9 additions & 2 deletions azurerm/internal/services/keyvault/key_vault_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
commonValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
Expand Down Expand Up @@ -165,8 +166,14 @@ func resourceKeyVault() *schema.Resource {
"ip_rules": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.Any(
commonValidate.IPv4Address,
commonValidate.CIDR,
),
},
Set: set.HashIPv4AddressOrCIDR,
},
"virtual_network_subnet_ids": {
Type: schema.TypeSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ resource "azurerm_key_vault" "test" {
network_acls {
default_action = "Allow"
bypass = "AzureServices"
ip_rules = ["123.0.0.102/32"]
ip_rules = ["123.0.0.102/32", "123.0.0.101"]
virtual_network_subnet_ids = [azurerm_subnet.test_a.id]
}
}
Expand Down
15 changes: 15 additions & 0 deletions azurerm/internal/tf/set/set.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package set

import (
"fmt"
"net"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
)

func HashInt(v interface{}) int {
Expand Down Expand Up @@ -40,3 +42,16 @@ func normalizeIPv6Address(ipv6 interface{}) string {
}
return r.String()
}

func HashIPv4AddressOrCIDR(ipv4 interface{}) int {
warnings, errors := validate.IPv4Address(ipv4, "")

// maybe cidr, just hash it
if len(warnings) > 0 || len(errors) > 0 {
return schema.HashString(ipv4)
}

// convert to cidr hash
cidr := fmt.Sprintf("%s/32", ipv4.(string))
return schema.HashString(cidr)
}