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

Added validation for firewall subnet name and forced new resource on change in subnet ID #3406

Merged
merged 3 commits into from
May 10, 2019
Merged
Changes from 2 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
21 changes: 18 additions & 3 deletions azurerm/resource_arm_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package azurerm

import (
"fmt"
"github.com/hashicorp/terraform/helper/validation"
"log"
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -49,9 +51,13 @@ func resourceArmFirewall() *schema.Resource {
ValidateFunc: validate.NoEmptyStrings,
},
"subnet_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
azure.ValidateResourceID,
validateAzureFirewallSubnetName,
),
},
"internal_public_ip_address_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -379,3 +385,12 @@ func validateAzureFirewallName(v interface{}, k string) (warnings []string, erro

return warnings, errors
}

func validateAzureFirewallSubnetName(v interface{}, k string) (warnings []string, errors []error) {
value := strings.Split(v.(string), "/")
if value[len(value)-1] != "AzureFirewallSubnet" {
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
errors = append(errors, fmt.Errorf("%q must have the name 'AzureFirewallSubnet' to be used for the Azure Firewall resource", k))
}

return warnings, errors
}