Skip to content

Commit

Permalink
Merge pull request #1144 from modular-magician/codegen-pr-2324
Browse files Browse the repository at this point in the history
Firewall case insensitive protocol
  • Loading branch information
slevenick authored Sep 16, 2019
2 parents f9ad5ad + 173efc1 commit 6ef1ea9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions google-beta/resource_compute_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform/helper/hashcode"
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -199,8 +207,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,
Expand All @@ -217,8 +226,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,
Expand Down

0 comments on commit 6ef1ea9

Please sign in to comment.