-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New resource: aws_dx_transit_virtual_interface #8522
Merged
bflad
merged 10 commits into
hashicorp:master
from
ewbankkit:issue-8490.dx_transit_virtual_interface
Aug 6, 2019
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a9b932
Add 'aws_dx_transit_virtual_interface' resource.
ewbankkit 68c2994
Documentation fix after review.
0528415
Update website/docs/r/dx_transit_virtual_interface.html.markdown
ewbankkit 630edbd
Code changes after review.
085be40
Ensure correct VIF type during import of Direct Connect Virtual Inter…
405b5d6
Fix:
5a60769
'%#v' -> '%s' when logging request structure.
aee8c35
Run acceptance tests serially: 'Only one Transit Virtual Interface is…
5a039e1
Set 'arn' in Read method. Remove duplicate code.
9763e96
Use common 'Exists' and 'Destroy' methods - https://github.com/terraf…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/arn" | ||
"github.com/aws/aws-sdk-go/service/directconnect" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func resourceAwsDxTransitVirtualInterface() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsDxTransitVirtualInterfaceCreate, | ||
Read: resourceAwsDxTransitVirtualInterfaceRead, | ||
Update: resourceAwsDxTransitVirtualInterfaceUpdate, | ||
Delete: resourceAwsDxTransitVirtualInterfaceDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: resourceAwsDxTransitVirtualInterfaceImport, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"address_family": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
directconnect.AddressFamilyIpv4, | ||
directconnect.AddressFamilyIpv6, | ||
}, false), | ||
}, | ||
"amazon_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"aws_device": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bgp_asn": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"bgp_auth_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"connection_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"customer_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"dx_gateway_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"jumbo_frame_capable": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"mtu": { | ||
Type: schema.TypeInt, | ||
Default: 1500, | ||
Optional: true, | ||
ValidateFunc: validation.IntInSlice([]int{1500, 8500}), | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"tags": tagsSchema(), | ||
"vlan": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.IntBetween(1, 4094), | ||
}, | ||
}, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(10 * time.Minute), | ||
Update: schema.DefaultTimeout(10 * time.Minute), | ||
Delete: schema.DefaultTimeout(10 * time.Minute), | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsDxTransitVirtualInterfaceCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).dxconn | ||
|
||
req := &directconnect.CreateTransitVirtualInterfaceInput{ | ||
ConnectionId: aws.String(d.Get("connection_id").(string)), | ||
NewTransitVirtualInterface: &directconnect.NewTransitVirtualInterface{ | ||
AddressFamily: aws.String(d.Get("address_family").(string)), | ||
Asn: aws.Int64(int64(d.Get("bgp_asn").(int))), | ||
DirectConnectGatewayId: aws.String(d.Get("dx_gateway_id").(string)), | ||
Mtu: aws.Int64(int64(d.Get("mtu").(int))), | ||
VirtualInterfaceName: aws.String(d.Get("name").(string)), | ||
Vlan: aws.Int64(int64(d.Get("vlan").(int))), | ||
}, | ||
} | ||
if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" { | ||
req.NewTransitVirtualInterface.AmazonAddress = aws.String(v.(string)) | ||
} | ||
if v, ok := d.GetOk("bgp_auth_key"); ok { | ||
req.NewTransitVirtualInterface.AuthKey = aws.String(v.(string)) | ||
} | ||
if v, ok := d.GetOk("customer_address"); ok && v.(string) != "" { | ||
req.NewTransitVirtualInterface.CustomerAddress = aws.String(v.(string)) | ||
} | ||
|
||
log.Printf("[DEBUG] Creating Direct Connect transit virtual interface: %#v", req) | ||
resp, err := conn.CreateTransitVirtualInterface(req) | ||
if err != nil { | ||
return fmt.Errorf("error creating Direct Connect transit virtual interface: %s", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(resp.VirtualInterface.VirtualInterfaceId)) | ||
arn := arn.ARN{ | ||
Partition: meta.(*AWSClient).partition, | ||
Region: meta.(*AWSClient).region, | ||
Service: "directconnect", | ||
AccountID: meta.(*AWSClient).accountid, | ||
Resource: fmt.Sprintf("dxvif/%s", d.Id()), | ||
}.String() | ||
d.Set("arn", arn) | ||
|
||
if err := dxTransitVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { | ||
return err | ||
} | ||
|
||
return resourceAwsDxTransitVirtualInterfaceUpdate(d, meta) | ||
} | ||
|
||
func resourceAwsDxTransitVirtualInterfaceRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).dxconn | ||
|
||
vif, err := dxVirtualInterfaceRead(d.Id(), conn) | ||
if err != nil { | ||
return err | ||
} | ||
if vif == nil { | ||
log.Printf("[WARN] Direct Connect transit virtual interface (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.Set("address_family", vif.AddressFamily) | ||
d.Set("amazon_address", vif.AmazonAddress) | ||
d.Set("aws_device", vif.AwsDeviceV2) | ||
d.Set("bgp_asn", vif.Asn) | ||
d.Set("bgp_auth_key", vif.AuthKey) | ||
d.Set("connection_id", vif.ConnectionId) | ||
d.Set("customer_address", vif.CustomerAddress) | ||
d.Set("dx_gateway_id", vif.DirectConnectGatewayId) | ||
d.Set("jumbo_frame_capable", vif.JumboFrameCapable) | ||
d.Set("mtu", vif.Mtu) | ||
d.Set("name", vif.VirtualInterfaceName) | ||
d.Set("vlan", vif.Vlan) | ||
if err := getTagsDX(conn, d, d.Get("arn").(string)); err != nil { | ||
return fmt.Errorf("error getting Direct Connect transit virtual interface (%s) tags: %s", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsDxTransitVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { | ||
if err := dxVirtualInterfaceUpdate(d, meta); err != nil { | ||
return err | ||
} | ||
|
||
if err := dxTransitVirtualInterfaceWaitUntilAvailable(meta.(*AWSClient).dxconn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { | ||
return err | ||
} | ||
|
||
return resourceAwsDxTransitVirtualInterfaceRead(d, meta) | ||
} | ||
|
||
func resourceAwsDxTransitVirtualInterfaceDelete(d *schema.ResourceData, meta interface{}) error { | ||
return dxVirtualInterfaceDelete(d, meta) | ||
} | ||
|
||
func resourceAwsDxTransitVirtualInterfaceImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
arn := arn.ARN{ | ||
Partition: meta.(*AWSClient).partition, | ||
Region: meta.(*AWSClient).region, | ||
Service: "directconnect", | ||
AccountID: meta.(*AWSClient).accountid, | ||
Resource: fmt.Sprintf("dxvif/%s", d.Id()), | ||
}.String() | ||
d.Set("arn", arn) | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func dxTransitVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { | ||
return dxVirtualInterfaceWaitUntilAvailable( | ||
conn, | ||
vifId, | ||
timeout, | ||
[]string{ | ||
directconnect.VirtualInterfaceStatePending, | ||
}, | ||
[]string{ | ||
directconnect.VirtualInterfaceStateAvailable, | ||
directconnect.VirtualInterfaceStateDown, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
CreateTransitVirtualInterface
can support tag-on-create and already handles MTU appropriately above, we should prefer to callRead
afterCreate
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.