Merge commit '33183c0'

* commit '33183c0':
  Implement a hash function for string sets
This commit is contained in:
Clint Shryock 2015-05-05 15:01:02 -05:00
commit 7b082d007e
10 changed files with 28 additions and 64 deletions

View File

@ -6,7 +6,6 @@ import (
"strings" "strings"
"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"
@ -81,9 +80,7 @@ func resourceAwsAutoscalingGroup() *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))
},
}, },
"load_balancers": &schema.Schema{ "load_balancers": &schema.Schema{
@ -91,9 +88,7 @@ func resourceAwsAutoscalingGroup() *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))
},
}, },
"vpc_zone_identifier": &schema.Schema{ "vpc_zone_identifier": &schema.Schema{
@ -102,9 +97,7 @@ func resourceAwsAutoscalingGroup() *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))
},
}, },
"termination_policies": &schema.Schema{ "termination_policies": &schema.Schema{
@ -113,9 +106,7 @@ func resourceAwsAutoscalingGroup() *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))
},
}, },
"tag": autoscalingTagsSchema(), "tag": autoscalingTagsSchema(),

View File

@ -9,7 +9,6 @@ import (
"github.com/awslabs/aws-sdk-go/service/iam" "github.com/awslabs/aws-sdk-go/service/iam"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"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"
) )
@ -132,18 +131,14 @@ func resourceAwsDbInstance() *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))
},
}, },
"security_group_names": &schema.Schema{ "security_group_names": &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))
},
}, },
"final_snapshot_identifier": &schema.Schema{ "final_snapshot_identifier": &schema.Schema{
@ -372,9 +367,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
// Create an empty schema.Set to hold all vpc security group ids // Create an empty schema.Set to hold all vpc security group ids
ids := &schema.Set{ ids := &schema.Set{
F: func(v interface{}) int { F: schema.HashString,
return hashcode.String(v.(string))
},
} }
for _, v := range v.VPCSecurityGroups { for _, v := range v.VPCSecurityGroups {
ids.Add(*v.VPCSecurityGroupID) ids.Add(*v.VPCSecurityGroupID)
@ -383,9 +376,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
// Create an empty schema.Set to hold all security group names // Create an empty schema.Set to hold all security group names
sgn := &schema.Set{ sgn := &schema.Set{
F: func(v interface{}) int { F: schema.HashString,
return hashcode.String(v.(string))
},
} }
for _, v := range v.DBSecurityGroups { for _, v := range v.DBSecurityGroups {
sgn.Add(*v.DBSecurityGroupName) sgn.Add(*v.DBSecurityGroupName)

View File

@ -8,7 +8,6 @@ import (
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"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"
) )
@ -37,9 +36,7 @@ func resourceAwsDbSubnetGroup() *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

@ -43,9 +43,7 @@ func resourceAwsElb() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Computed: true, Computed: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"instances": &schema.Schema{ "instances": &schema.Schema{
@ -53,9 +51,7 @@ func resourceAwsElb() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Optional: true, Optional: true,
Computed: true, Computed: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"security_groups": &schema.Schema{ "security_groups": &schema.Schema{
@ -63,9 +59,7 @@ func resourceAwsElb() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Optional: true, Optional: true,
Computed: true, Computed: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"source_security_group": &schema.Schema{ "source_security_group": &schema.Schema{
@ -80,9 +74,7 @@ func resourceAwsElb() *schema.Resource {
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Computed: true, Computed: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
"idle_timeout": &schema.Schema{ "idle_timeout": &schema.Schema{

View File

@ -107,9 +107,7 @@ func resourceAwsInstance() *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))
},
}, },
"vpc_security_group_ids": &schema.Schema{ "vpc_security_group_ids": &schema.Schema{

View File

@ -76,9 +76,7 @@ func resourceAwsLaunchConfiguration() *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))
},
}, },
"associate_public_ip_address": &schema.Schema{ "associate_public_ip_address": &schema.Schema{

View File

@ -34,9 +34,7 @@ func resourceAwsNetworkInterface() *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))
},
}, },
"security_groups": &schema.Schema{ "security_groups": &schema.Schema{
@ -44,9 +42,7 @@ func resourceAwsNetworkInterface() *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))
},
}, },
"attachment": &schema.Schema{ "attachment": &schema.Schema{

View File

@ -88,9 +88,7 @@ func resourceAwsRoute53Record() *schema.Resource {
ConflictsWith: []string{"alias"}, ConflictsWith: []string{"alias"},
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Optional: true, Optional: true,
Set: func(v interface{}) int { Set: schema.HashString,
return hashcode.String(v.(string))
},
}, },
}, },
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/awslabs/aws-sdk-go/service/rds" "github.com/awslabs/aws-sdk-go/service/rds"
"github.com/awslabs/aws-sdk-go/service/route53" "github.com/awslabs/aws-sdk-go/service/route53"
"github.com/hashicorp/terraform/flatmap" "github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -38,9 +37,7 @@ func testConf() map[string]string {
} }
func TestexpandIPPerms(t *testing.T) { func TestexpandIPPerms(t *testing.T) {
hash := func(v interface{}) int { hash := schema.HashString
return hashcode.String(v.(string))
}
expanded := []interface{}{ expanded := []interface{}{
map[string]interface{}{ map[string]interface{}{
@ -121,9 +118,7 @@ func TestexpandIPPerms(t *testing.T) {
} }
func TestExpandIPPerms_nonVPC(t *testing.T) { func TestExpandIPPerms_nonVPC(t *testing.T) {
hash := func(v interface{}) int { hash := schema.HashString
return hashcode.String(v.(string))
}
expanded := []interface{}{ expanded := []interface{}{
map[string]interface{}{ map[string]interface{}{

View File

@ -5,8 +5,16 @@ import (
"reflect" "reflect"
"sort" "sort"
"sync" "sync"
"github.com/hashicorp/terraform/helper/hashcode"
) )
// HashString hashes strings. If you want a Set of strings, this is the
// SchemaSetFunc you want.
func HashString(v interface{}) int {
return hashcode.String(v.(string))
}
// Set is a set data structure that is returned for elements of type // Set is a set data structure that is returned for elements of type
// TypeSet. // TypeSet.
type Set struct { type Set struct {