Skip to content

Commit

Permalink
Change interface to 'dxVirtualInterfaceRead'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and Kit Ewbank committed Jun 21, 2018
1 parent d7bd808 commit 6a1f5a4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 72 deletions.
133 changes: 62 additions & 71 deletions aws/dx_vif.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,75 @@ import (
"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 isNoSuchDxVirtualInterfaceErr(err error) bool {
return isAWSErr(err, "DirectConnectClientException", "does not exist")
}

func dxVirtualInterfaceRead(d *schema.ResourceData, meta interface{}) (*directconnect.VirtualInterface, error) {
conn := meta.(*AWSClient).dxconn

resp, state, err := dxVirtualInterfaceStateRefresh(conn, d.Id())()
func dxVirtualInterfaceRead(id string, conn *directconnect.DirectConnect) (*directconnect.VirtualInterface, error) {
resp, state, err := dxVirtualInterfaceStateRefresh(conn, id)()
if err != nil {
return nil, fmt.Errorf("Error reading Direct Connect virtual interface: %s", err.Error())
}
terminalStates := map[string]bool{
directconnect.VirtualInterfaceStateDeleted: true,
directconnect.VirtualInterfaceStateDeleting: true,
directconnect.VirtualInterfaceStateRejected: true,
}
if _, ok := terminalStates[state]; ok {
log.Printf("[WARN] Direct Connect virtual interface (%s) not found, removing from state", d.Id())
d.SetId("")
if state == directconnect.VirtualInterfaceStateDeleted {
return nil, nil
}

Expand Down Expand Up @@ -195,62 +245,3 @@ func flattenDxRouteFilterPrefixes(prefixes []*directconnect.RouteFilterPrefix) *
}
return schema.NewSet(schema.HashString, out)
}

// 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,
},
}
4 changes: 3 additions & 1 deletion aws/resource_aws_dx_private_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int
func resourceAwsDxPrivateVirtualInterfaceRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).dxconn

vif, err := dxVirtualInterfaceRead(d, meta)
vif, err := dxVirtualInterfaceRead(d.Id(), conn)
if err != nil {
return err
}
if vif == nil {
log.Printf("[WARN] Direct Connect virtual interface (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

Expand Down

0 comments on commit 6a1f5a4

Please sign in to comment.