diff --git a/aws/dx_vif.go b/aws/dx_vif.go index 92ee5358cc7..941c21c134b 100644 --- a/aws/dx_vif.go +++ b/aws/dx_vif.go @@ -6,7 +6,6 @@ import ( "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/resource" "github.com/hashicorp/terraform/helper/schema" @@ -27,14 +26,7 @@ func dxVirtualInterfaceRead(id string, conn *directconnect.DirectConnect) (*dire func dxVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).dxconn - 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() - if err := setTagsDX(conn, d, arn); err != nil { + if err := setTagsDX(conn, d, d.Get("arn").(string)); err != nil { return err } @@ -120,49 +112,3 @@ func dxVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directco return nil } - -// Attributes common to public VIFs and creator side of hosted public VIFs. -func dxPublicVirtualInterfaceAttributes(d *schema.ResourceData, meta interface{}, vif *directconnect.VirtualInterface) error { - if err := dxVirtualInterfaceAttributes(d, meta, vif); err != nil { - return err - } - d.Set("route_filter_prefixes", flattenDxRouteFilterPrefixes(vif.RouteFilterPrefixes)) - - return nil -} - -// Attributes common to private VIFs and creator side of hosted private VIFs. -func dxPrivateVirtualInterfaceAttributes(d *schema.ResourceData, meta interface{}, vif *directconnect.VirtualInterface) error { - return dxVirtualInterfaceAttributes(d, meta, vif) -} - -// Attributes common to public/private VIFs and creator side of hosted public/private VIFs. -func dxVirtualInterfaceAttributes(d *schema.ResourceData, meta interface{}, vif *directconnect.VirtualInterface) error { - if err := dxVirtualInterfaceArnAttribute(d, meta); err != nil { - return err - } - - d.Set("connection_id", vif.ConnectionId) - d.Set("name", vif.VirtualInterfaceName) - d.Set("vlan", vif.Vlan) - d.Set("bgp_asn", vif.Asn) - d.Set("bgp_auth_key", vif.AuthKey) - d.Set("address_family", vif.AddressFamily) - d.Set("customer_address", vif.CustomerAddress) - d.Set("amazon_address", vif.AmazonAddress) - - return nil -} - -func dxVirtualInterfaceArnAttribute(d *schema.ResourceData, meta interface{}) 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 nil -} diff --git a/aws/resource_aws_dx_hosted_private_virtual_interface.go b/aws/resource_aws_dx_hosted_private_virtual_interface.go index c793bbbe98d..f0ce581ff78 100644 --- a/aws/resource_aws_dx_hosted_private_virtual_interface.go +++ b/aws/resource_aws_dx_hosted_private_virtual_interface.go @@ -6,6 +6,7 @@ import ( "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" @@ -17,7 +18,7 @@ func resourceAwsDxHostedPrivateVirtualInterface() *schema.Resource { Read: resourceAwsDxHostedPrivateVirtualInterfaceRead, Delete: resourceAwsDxHostedPrivateVirtualInterfaceDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: resourceAwsDxHostedPrivateVirtualInterfaceImport, }, Schema: map[string]*schema.Schema{ @@ -98,13 +99,13 @@ func resourceAwsDxHostedPrivateVirtualInterfaceCreate(d *schema.ResourceData, me AddressFamily: aws.String(d.Get("address_family").(string)), }, } - if v, ok := d.GetOk("bgp_auth_key"); ok { + if v, ok := d.GetOk("bgp_auth_key"); ok && v.(string) != "" { req.NewPrivateVirtualInterfaceAllocation.AuthKey = aws.String(v.(string)) } - if v, ok := d.GetOk("customer_address"); ok { + if v, ok := d.GetOk("customer_address"); ok && v.(string) != "" { req.NewPrivateVirtualInterfaceAllocation.CustomerAddress = aws.String(v.(string)) } - if v, ok := d.GetOk("amazon_address"); ok { + if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" { req.NewPrivateVirtualInterfaceAllocation.AmazonAddress = aws.String(v.(string)) } @@ -115,6 +116,14 @@ func resourceAwsDxHostedPrivateVirtualInterfaceCreate(d *schema.ResourceData, me } d.SetId(aws.StringValue(resp.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 := dxHostedPrivateVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { return err @@ -136,14 +145,36 @@ func resourceAwsDxHostedPrivateVirtualInterfaceRead(d *schema.ResourceData, meta return nil } + d.Set("connection_id", vif.ConnectionId) + d.Set("name", vif.VirtualInterfaceName) + d.Set("vlan", vif.Vlan) + d.Set("bgp_asn", vif.Asn) + d.Set("bgp_auth_key", vif.AuthKey) + d.Set("address_family", vif.AddressFamily) + d.Set("customer_address", vif.CustomerAddress) + d.Set("amazon_address", vif.AmazonAddress) d.Set("owner_account_id", vif.OwnerAccount) - return dxPrivateVirtualInterfaceAttributes(d, meta, vif) + + return nil } func resourceAwsDxHostedPrivateVirtualInterfaceDelete(d *schema.ResourceData, meta interface{}) error { return dxVirtualInterfaceDelete(d, meta) } +func resourceAwsDxHostedPrivateVirtualInterfaceImport(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 dxHostedPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { return dxVirtualInterfaceWaitUntilAvailable( d, diff --git a/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go b/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go index cea7d588b1b..77479b4859b 100644 --- a/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go +++ b/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go @@ -6,6 +6,7 @@ import ( "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" ) @@ -17,7 +18,7 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepter() *schema.Resource { Update: resourceAwsDxHostedPrivateVirtualInterfaceAccepterUpdate, Delete: resourceAwsDxHostedPrivateVirtualInterfaceAccepterDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: resourceAwsDxHostedPrivateVirtualInterfaceAccepterImport, }, Schema: map[string]*schema.Schema{ @@ -66,10 +67,10 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterCreate(d *schema.Resource req := &directconnect.ConfirmPrivateVirtualInterfaceInput{ VirtualInterfaceId: aws.String(vifId), } - if vgwOk { + if vgwOk && vgwIdRaw.(string) != "" { req.VirtualGatewayId = aws.String(vgwIdRaw.(string)) } - if dxgwOk { + if dxgwOk && dxgwIdRaw.(string) != "" { req.DirectConnectGatewayId = aws.String(dxgwIdRaw.(string)) } @@ -80,6 +81,14 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterCreate(d *schema.Resource } d.SetId(vifId) + 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 := dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(d, conn); err != nil { return err @@ -101,9 +110,6 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterRead(d *schema.ResourceDa return nil } - if err := dxVirtualInterfaceArnAttribute(d, meta); err != nil { - return err - } d.Set("virtual_interface_id", vif.VirtualInterfaceId) d.Set("vpn_gateway_id", vif.VirtualGatewayId) d.Set("dx_gateway_id", vif.DirectConnectGatewayId) @@ -126,6 +132,19 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterDelete(d *schema.Resource return dxVirtualInterfaceDelete(d, meta) } +func resourceAwsDxHostedPrivateVirtualInterfaceAccepterImport(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 dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { return dxVirtualInterfaceWaitUntilAvailable( d, diff --git a/aws/resource_aws_dx_hosted_private_virtual_interface_test.go b/aws/resource_aws_dx_hosted_private_virtual_interface_test.go index 451bd87ed7c..a7ddff6003f 100644 --- a/aws/resource_aws_dx_hosted_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_hosted_private_virtual_interface_test.go @@ -23,7 +23,8 @@ func TestAccAwsDxHostedPrivateVirtualInterface_basic(t *testing.T) { if ownerAccountId == "" { t.Skipf("Environment variable %s is not set", key) } - vifName := fmt.Sprintf("tf-dx-vif-%s", acctest.RandString(5)) + vifName := fmt.Sprintf("terraform-testacc-dxvif-%s", acctest.RandString(5)) + bgpAsn := randIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAwsDxHostedPrivateVirtualInterface_basic(t *testing.T) { CheckDestroy: testAccCheckAwsDxHostedPrivateVirtualInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccDxHostedPrivateVirtualInterfaceConfig_basic(connectionId, ownerAccountId, vifName), + Config: testAccDxHostedPrivateVirtualInterfaceConfig_basic(connectionId, ownerAccountId, vifName, bgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxHostedPrivateVirtualInterfaceExists("aws_dx_hosted_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "name", vifName), @@ -65,7 +66,7 @@ func testAccCheckAwsDxHostedPrivateVirtualInterfaceDestroy(s *terraform.State) e } for _, v := range resp.VirtualInterfaces { if *v.VirtualInterfaceId == rs.Primary.ID && !(*v.VirtualInterfaceState == directconnect.VirtualInterfaceStateDeleted) { - return fmt.Errorf("[DESTROY ERROR] Dx Public VIF (%s) not deleted", rs.Primary.ID) + return fmt.Errorf("[DESTROY ERROR] Dx Private VIF (%s) not deleted", rs.Primary.ID) } } } @@ -83,7 +84,7 @@ func testAccCheckAwsDxHostedPrivateVirtualInterfaceExists(name string) resource. } } -func testAccDxHostedPrivateVirtualInterfaceConfig_basic(cid, ownerAcctId, n string) string { +func testAccDxHostedPrivateVirtualInterfaceConfig_basic(cid, ownerAcctId, n string, bgpAsn int) string { return fmt.Sprintf(` resource "aws_dx_hosted_private_virtual_interface" "foo" { connection_id = "%s" @@ -92,7 +93,7 @@ resource "aws_dx_hosted_private_virtual_interface" "foo" { name = "%s" vlan = 4094 address_family = "ipv4" - bgp_asn = 65352 + bgp_asn = %d } -`, cid, ownerAcctId, n) +`, cid, ownerAcctId, n, bgpAsn) } diff --git a/website/docs/r/dx_hosted_private_virtual_interface.html.markdown b/website/docs/r/dx_hosted_private_virtual_interface.html.markdown index 85b0cf79db9..9953d85d249 100644 --- a/website/docs/r/dx_hosted_private_virtual_interface.html.markdown +++ b/website/docs/r/dx_hosted_private_virtual_interface.html.markdown @@ -28,15 +28,15 @@ resource "aws_dx_hosted_private_virtual_interface" "foo" { The following arguments are supported: +* `address_family` - (Required) The address family for the BGP peer. `ipv4 ` or `ipv6`. +* `bgp_asn` - (Required) The autonomous system (AS) number for Border Gateway Protocol (BGP) configuration. * `connection_id` - (Required) The ID of the Direct Connect connection (or LAG) on which to create the virtual interface. -* `owner_account_id` - (Required) The AWS account that will own the new virtual interface. * `name` - (Required) The name for the virtual interface. +* `owner_account_id` - (Required) The AWS account that will own the new virtual interface. * `vlan` - (Required) The VLAN ID. -* `bgp_asn` - (Required) The autonomous system (AS) number for Border Gateway Protocol (BGP) configuration. +* `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. * `bgp_auth_key` - (Optional) The authentication key for BGP configuration. -* `address_family` - (Required) The address family for the BGP peer. `ipv4 ` or `ipv6`. * `customer_address` - (Optional) The IPv4 CIDR destination address to which Amazon should send traffic. Required for IPv4 BGP peers. -* `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. ## Attributes Reference diff --git a/website/docs/r/dx_hosted_private_virtual_interface_accepter.html.markdown b/website/docs/r/dx_hosted_private_virtual_interface_accepter.html.markdown index d346a24a62c..ef0ebd23c2d 100644 --- a/website/docs/r/dx_hosted_private_virtual_interface_accepter.html.markdown +++ b/website/docs/r/dx_hosted_private_virtual_interface_accepter.html.markdown @@ -60,9 +60,9 @@ resource "aws_dx_hosted_private_virtual_interface_accepter" "accepter" { The following arguments are supported: * `virtual_interface_id` - (Required) The ID of the Direct Connect virtual interface to accept. -* `vpn_gateway_id` - (Optional) The ID of the [virtual private gateway](vpn_gateway.html) to which to connect the virtual interface. * `dx_gateway_id` - (Optional) The ID of the Direct Connect gateway to which to connect the virtual interface. * `tags` - (Optional) A mapping of tags to assign to the resource. +* `vpn_gateway_id` - (Optional) The ID of the [virtual private gateway](vpn_gateway.html) to which to connect the virtual interface. ## Attributes Reference