Skip to content

Commit

Permalink
Remove 'mergeSchemas'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and Kit Ewbank committed Jun 22, 2018
1 parent 07324ec commit 9fde05d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 112 deletions.
60 changes: 0 additions & 60 deletions aws/dx_vif.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,8 @@ import (
"github.com/aws/aws-sdk-go/service/directconnect"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

// Schemas common to all (public/private, hosted or not) virtual interfaces.
var dxVirtualInterfaceSchemaWithTags = mergeSchemas(
dxVirtualInterfaceSchema,
map[string]*schema.Schema{
"tags": tagsSchema(),
},
)
var dxVirtualInterfaceSchema = map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"connection_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"vlan": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 4094),
},
"bgp_asn": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"bgp_auth_key": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"address_family": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{directconnect.AddressFamilyIpv4, directconnect.AddressFamilyIpv6}, false),
},
"customer_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"amazon_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
}

func dxVirtualInterfaceRead(id string, conn *directconnect.DirectConnect) (*directconnect.VirtualInterface, error) {
resp, state, err := dxVirtualInterfaceStateRefresh(conn, id)()
if err != nil {
Expand Down
70 changes: 59 additions & 11 deletions aws/resource_aws_dx_public_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/directconnect"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceAwsDxPublicVirtualInterface() *schema.Resource {
Expand All @@ -21,18 +22,65 @@ func resourceAwsDxPublicVirtualInterface() *schema.Resource {
},
CustomizeDiff: resourceAwsDxPublicVirtualInterfaceCustomizeDiff,

Schema: mergeSchemas(
dxVirtualInterfaceSchemaWithTags,
map[string]*schema.Schema{
"route_filter_prefixes": &schema.Schema{
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1,
},
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
),
"connection_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"vlan": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 4094),
},
"bgp_asn": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"bgp_auth_key": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"address_family": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{directconnect.AddressFamilyIpv4, directconnect.AddressFamilyIpv6}, false),
},
"customer_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"amazon_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"route_filter_prefixes": &schema.Schema{
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1,
},
"tags": tagsSchema(),
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Expand Down
13 changes: 0 additions & 13 deletions aws/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"regexp"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

// Base64Encode encodes data if the input isn't already encoded using base64.StdEncoding.EncodeToString.
Expand Down Expand Up @@ -48,15 +47,3 @@ func isResourceNotFoundError(err error) bool {
_, ok := err.(*resource.NotFoundError)
return ok
}

func mergeSchemas(schemas ...map[string]*schema.Schema) map[string]*schema.Schema {
merged := make(map[string]*schema.Schema)

for _, schema := range schemas {
for k, v := range schema {
merged[k] = v
}
}

return merged
}
28 changes: 0 additions & 28 deletions aws/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package aws

import (
"testing"

"github.com/hashicorp/terraform/helper/schema"
)

var base64encodingTests = []struct {
Expand Down Expand Up @@ -74,29 +72,3 @@ func TestJsonBytesEqualWhitespaceAndNoWhitespace(t *testing.T) {
t.Errorf("Expected jsonBytesEqual to return false for %s == %s", noWhitespaceDiff, whitespaceDiff)
}
}

func TestMergeSchemas(t *testing.T) {
s1 := map[string]*schema.Schema{
"aaa": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"zzz": {
Type: schema.TypeInt,
Optional: true,
Default: 42,
},
}
s2 := map[string]*schema.Schema{
"xxx": {
Type: schema.TypeFloat,
Computed: true,
},
}

s3 := mergeSchemas(s1, s2)
if len(s3) != 3 {
t.Errorf("Expected merge schema to be of size 3, got %d", len(s3))
}
}

0 comments on commit 9fde05d

Please sign in to comment.