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 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
23 changes: 19 additions & 4 deletions azurerm/resource_arm_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package azurerm

import (
"fmt"
"log"
"regexp"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
"log"
"regexp"
)

var azureFirewallResourceName = "azurerm_firewall"
Expand Down Expand Up @@ -51,7 +50,8 @@ func resourceArmFirewall() *schema.Resource {
"subnet_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
ForceNew: true,
ValidateFunc: validateAzureFirewallSubnetName,
},
"internal_public_ip_address_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -379,3 +379,18 @@ func validateAzureFirewallName(v interface{}, k string) (warnings []string, erro

return warnings, errors
}

func validateAzureFirewallSubnetName(v interface{}, k string) (warnings []string, errors []error) {
parsed, err := parseAzureResourceID(v.(string))
if err != nil {
errors = append(errors, fmt.Errorf("Error parsing Azure Resource ID %q", v.(string)))
return warnings, errors
}
subnetName := parsed.Path["subnets"]
if subnetName != "AzureFirewallSubnet" {
errors = append(errors, fmt.Errorf("The name of the Subnet for %q must be exactly 'AzureFirewallSubnet' to be used for the Azure Firewall resource", k))

}

return warnings, errors
}