Merge pull request #5046 from tpounds/use-built-in-schema-string-hash

Use built-in schema.HashString instead of custom hash functions.
This commit is contained in:
Paul Hinze 2016-02-12 07:58:34 -06:00
commit 66ec38b2d9
22 changed files with 36 additions and 120 deletions

View File

@ -5,7 +5,6 @@ import (
"regexp" "regexp"
"github.com/hashicorp/atlas-go/v1" "github.com/hashicorp/atlas-go/v1"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -51,9 +50,7 @@ func resourceArtifact() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"metadata": &schema.Schema{ "metadata": &schema.Schema{

View File

@ -1,7 +1,6 @@
package aws package aws
import ( import (
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/mutexkv" "github.com/hashicorp/terraform/helper/mutexkv"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -73,9 +72,7 @@ func Provider() terraform.ResourceProvider {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Optional: true, Optional: true,
ConflictsWith: []string{"forbidden_account_ids"}, ConflictsWith: []string{"forbidden_account_ids"},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"forbidden_account_ids": &schema.Schema{ "forbidden_account_ids": &schema.Schema{
@ -83,9 +80,7 @@ func Provider() terraform.ResourceProvider {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Optional: true, Optional: true,
ConflictsWith: []string{"allowed_account_ids"}, ConflictsWith: []string{"allowed_account_ids"},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"dynamodb_endpoint": &schema.Schema{ "dynamodb_endpoint": &schema.Schema{

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -61,9 +60,7 @@ func resourceAwsCloudWatchMetricAlarm() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"alarm_description": &schema.Schema{ "alarm_description": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -77,17 +74,13 @@ func resourceAwsCloudWatchMetricAlarm() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"ok_actions": &schema.Schema{ "ok_actions": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"unit": &schema.Schema{ "unit": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache"
"github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -89,18 +88,14 @@ func resourceAwsElasticacheCluster() *schema.Resource {
Computed: true, Computed: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"security_group_ids": &schema.Schema{ "security_group_ids": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Computed: true, Computed: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
// Exported Attributes // Exported Attributes
"cache_nodes": &schema.Schema{ "cache_nodes": &schema.Schema{
@ -142,9 +137,7 @@ func resourceAwsElasticacheCluster() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"snapshot_window": &schema.Schema{ "snapshot_window": &schema.Schema{
@ -185,9 +178,7 @@ func resourceAwsElasticacheCluster() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"tags": tagsSchema(), "tags": tagsSchema(),

View File

@ -8,7 +8,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -35,9 +34,7 @@ func resourceAwsElasticacheSecurityGroup() *schema.Resource {
Required: true, Required: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -9,7 +9,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -41,9 +40,7 @@ func resourceAwsElasticacheSubnetGroup() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Required: true, Required: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -117,9 +117,7 @@ func resourceAwsInstance() *schema.Resource {
Optional: true, Optional: true,
Computed: true, Computed: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"public_dns": &schema.Schema{ "public_dns": &schema.Schema{

View File

@ -8,7 +8,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -29,9 +28,7 @@ func resourceAwsProxyProtocolPolicy() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Required: true, Required: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -34,9 +34,7 @@ func resourceAwsRouteTable() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"route": &schema.Schema{ "route": &schema.Schema{

View File

@ -106,9 +106,7 @@ func resourceAwsSecurityGroup() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"self": &schema.Schema{ "self": &schema.Schema{
@ -152,9 +150,7 @@ func resourceAwsSecurityGroup() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"self": &schema.Schema{ "self": &schema.Schema{

View File

@ -7,7 +7,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -38,9 +37,7 @@ func resourceAwsVpcEndpoint() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -85,7 +85,7 @@ func resourceDockerContainer() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash, Set: schema.HashString,
}, },
"publish_all_ports": &schema.Schema{ "publish_all_ports": &schema.Schema{
@ -225,7 +225,7 @@ func resourceDockerContainer() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash, Set: schema.HashString,
}, },
"links": &schema.Schema{ "links": &schema.Schema{
@ -233,7 +233,7 @@ func resourceDockerContainer() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash, Set: schema.HashString,
}, },
"ip_address": &schema.Schema{ "ip_address": &schema.Schema{
@ -339,7 +339,7 @@ func resourceDockerContainer() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: stringSetHash, Set: schema.HashString,
}, },
}, },
} }
@ -407,7 +407,3 @@ func resourceDockerVolumesHash(v interface{}) int {
return hashcode.String(buf.String()) return hashcode.String(buf.String())
} }
func stringSetHash(v interface{}) int {
return hashcode.String(v.(string))
}

View File

@ -51,9 +51,7 @@ func resourceComputeFirewall() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
}, },
@ -64,27 +62,21 @@ func resourceComputeFirewall() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"source_tags": &schema.Schema{ "source_tags": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"target_tags": &schema.Schema{ "target_tags": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"self_link": &schema.Schema{ "self_link": &schema.Schema{

View File

@ -5,19 +5,14 @@ import (
"log" "log"
"strings" "strings"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/compute/v1" "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
) )
func stringHashcode(v interface{}) int {
return hashcode.String(v.(string))
}
func stringScopeHashcode(v interface{}) int { func stringScopeHashcode(v interface{}) int {
v = canonicalizeServiceScope(v.(string)) v = canonicalizeServiceScope(v.(string))
return hashcode.String(v.(string)) return schema.HashString(v)
} }
func resourceComputeInstance() *schema.Resource { func resourceComputeInstance() *schema.Resource {
@ -263,7 +258,7 @@ func resourceComputeInstance() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: stringHashcode, Set: schema.HashString,
}, },
"metadata_fingerprint": &schema.Schema{ "metadata_fingerprint": &schema.Schema{

View File

@ -8,7 +8,6 @@ import (
"google.golang.org/api/compute/v1" "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -82,9 +81,7 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"target_size": &schema.Schema{ "target_size": &schema.Schema{

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/compute/v1" "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
@ -234,9 +233,7 @@ func resourceComputeInstanceTemplate() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"metadata_fingerprint": &schema.Schema{ "metadata_fingerprint": &schema.Schema{

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/compute/v1" "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
@ -82,9 +81,7 @@ func resourceComputeRoute() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"self_link": &schema.Schema{ "self_link": &schema.Schema{

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"time" "time"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies" "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies"
@ -53,9 +52,7 @@ func resourceFWPolicyV1() *schema.Resource {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -97,9 +97,7 @@ func resourceLBPoolV1() *schema.Resource {
Optional: true, Optional: true,
ForceNew: false, ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"time" "time"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -67,9 +66,7 @@ func resourceNetworkingPortV2() *schema.Resource {
ForceNew: false, ForceNew: false,
Computed: true, Computed: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"device_id": &schema.Schema{ "device_id": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"time" "time"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -88,9 +87,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
Optional: true, Optional: true,
ForceNew: false, ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"host_routes": &schema.Schema{ "host_routes": &schema.Schema{
Type: schema.TypeList, Type: schema.TypeList,

View File

@ -6,7 +6,6 @@ import (
"github.com/hashicorp/hil/ast" "github.com/hashicorp/hil/ast"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -213,9 +212,7 @@ func TestConfigFieldReader_ComputedSet(t *testing.T) {
"strSet": &Schema{ "strSet": &Schema{
Type: TypeSet, Type: TypeSet,
Elem: &Schema{Type: TypeString}, Elem: &Schema{Type: TypeString},
Set: func(v interface{}) int { Set: HashString,
return hashcode.String(v.(string))
},
}, },
} }