From 800566f3ab293a4c23d56cddd2149baccd449df3 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Mon, 16 Sep 2019 18:01:02 +0000 Subject: [PATCH] Firewall case insensitive protocol Signed-off-by: Modular Magician --- google/resource_compute_firewall.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/google/resource_compute_firewall.go b/google/resource_compute_firewall.go index 6962775b41a..255671e97ae 100644 --- a/google/resource_compute_firewall.go +++ b/google/resource_compute_firewall.go @@ -21,6 +21,7 @@ import ( "reflect" "sort" "strconv" + "strings" "time" "github.com/hashicorp/terraform/helper/hashcode" @@ -32,7 +33,7 @@ import ( func resourceComputeFirewallRuleHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["protocol"].(string))) + buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["protocol"].(string)))) // We need to make sure to sort the strings below so that we always // generate the same hash code no matter what is in the set. @@ -48,6 +49,13 @@ func resourceComputeFirewallRuleHash(v interface{}) int { return hashcode.String(buf.String()) } +func compareCaseInsensitive(k, old, new string, d *schema.ResourceData) bool { + if strings.ToLower(old) == strings.ToLower(new) { + return true + } + return false +} + func resourceComputeFirewall() *schema.Resource { return &schema.Resource{ Create: resourceComputeFirewallCreate, @@ -195,8 +203,9 @@ func computeFirewallAllowSchema() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ "protocol": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareCaseInsensitive, }, "ports": { Type: schema.TypeList, @@ -213,8 +222,9 @@ func computeFirewallDenySchema() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ "protocol": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: compareCaseInsensitive, }, "ports": { Type: schema.TypeList,