Skip to content

Commit

Permalink
resource/aws_vpc_peering_connection_accepter: Finish import implement…
Browse files Browse the repository at this point in the history
…ation

Reference: #4486

Output from acceptance testing:

```
--- PASS: TestAccAWSVPCPeeringConnectionAccepter_sameRegionSameAccount (38.63s)
--- PASS: TestAccAWSVPCPeeringConnectionAccepter_sameRegionDifferentAccount (39.03s)
--- PASS: TestAccAWSVPCPeeringConnectionAccepter_differentRegionDifferentAccount (39.65s)
--- PASS: TestAccAWSVPCPeeringConnectionAccepter_differentRegionSameAccount (42.12s)
```
  • Loading branch information
bflad committed Jan 11, 2020
1 parent a8f9930 commit 70c3eda
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
20 changes: 6 additions & 14 deletions aws/resource_aws_vpc_peering_connection_accepter.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package aws

import (
"log"

"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

const (
schemaNameVPCPeeringConnectionID = "vpc_peering_connection_id"
)

func resourceAwsVpcPeeringConnectionAccepter() *schema.Resource {
return &schema.Resource{
Create: resourceAwsVPCPeeringAccepterCreate,
Read: resourceAwsVPCPeeringRead,
Update: resourceAwsVPCPeeringUpdate,
Delete: resourceAwsVPCPeeringAccepterDelete,
Importer: &schema.ResourceImporter{
State: func(data *schema.ResourceData, m interface{}) (result []*schema.ResourceData, err error) {
err = data.Set(schemaNameVPCPeeringConnectionID, data.Id())
if err != nil {
return nil, fmt.Errorf("setting attribute '%s': %v", schemaNameVPCPeeringConnectionID, err)
}
State: func(d *schema.ResourceData, m interface{}) (result []*schema.ResourceData, err error) {
d.Set("vpc_peering_connection_id", d.Id())

return []*schema.ResourceData{data}, nil
return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
schemaNameVPCPeeringConnectionID: {
"vpc_peering_connection_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Expand Down Expand Up @@ -67,7 +59,7 @@ func resourceAwsVpcPeeringConnectionAccepter() *schema.Resource {
}

func resourceAwsVPCPeeringAccepterCreate(d *schema.ResourceData, meta interface{}) error {
id := d.Get(schemaNameVPCPeeringConnectionID).(string)
id := d.Get("vpc_peering_connection_id").(string)
d.SetId(id)

if err := resourceAwsVPCPeeringRead(d, meta); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions aws/resource_aws_vpc_peering_connection_accepter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestAccAWSVPCPeeringConnectionAccepter_sameRegionSameAccount(t *testing.T)
resource.TestCheckResourceAttr(resourceNameAccepter, "accept_status", "active"),
),
},
{
Config: testAccAwsVPCPeeringConnectionAccepterConfigSameRegionSameAccount(rName),
ResourceName: resourceNameAccepter,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"auto_accept"},
},
},
})
}
Expand Down Expand Up @@ -91,6 +98,13 @@ func TestAccAWSVPCPeeringConnectionAccepter_differentRegionSameAccount(t *testin
resource.TestCheckResourceAttr(resourceNameAccepter, "accept_status", "active"),
),
},
{
Config: testAccAwsVPCPeeringConnectionAccepterConfigDifferentRegionSameAccount(rName),
ResourceName: resourceNameAccepter,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"auto_accept"},
},
},
})
}
Expand Down
21 changes: 21 additions & 0 deletions website/docs/r/vpc_peering_connection_accepter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,24 @@ connection in the peer VPC over the VPC Peering Connection.
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the VPC Peering Connection.

## Import

VPC Peering Connection Accepters can be imported by using the Peering Connection ID, e.g.

```sh
$ terraform import aws_vpc_peering_connection_accepter.example pcx-12345678
```

Certain resource arguments, like `auto_accept`, do not have an EC2 API method for reading the information after peering connection creation. If the argument is set in the Terraform configuration on an imported resource, Terraform will always show a difference. To workaround this behavior, either omit the argument from the Terraform configuration or use [`ignore_changes`](/docs/configuration/resources.html#ignore_changes) to hide the difference, e.g.

```hcl
resource "aws_vpc_peering_connection_accepter" "example" {
# ... other configuration ...
# There is no AWS EC2 API for reading auto_accept
lifecycle {
ignore_changes = ["auto_accept"]
}
}
```

0 comments on commit 70c3eda

Please sign in to comment.