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 4b7d622 commit 2b93824
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 117 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
80 changes: 64 additions & 16 deletions aws/resource_aws_dx_private_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 resourceAwsDxPrivateVirtualInterface() *schema.Resource {
Expand All @@ -20,23 +21,70 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Schema: mergeSchemas(
dxVirtualInterfaceSchemaWithTags,
map[string]*schema.Schema{
"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"dx_gateway_id"},
},
"dx_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"vpn_gateway_id"},
},
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,
},
"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"dx_gateway_id"},
},
"dx_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"vpn_gateway_id"},
},
"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,
},
"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 2b93824

Please sign in to comment.