From 11ba9b10421ce1f1febb39993226568ed46d59d3 Mon Sep 17 00:00:00 2001 From: jba Date: Mon, 9 Mar 2015 09:59:52 +0100 Subject: [PATCH 1/5] add the auto_accecpt option --- .../resource_aws_vpc_peering_connection.go | 50 ++++++++++++++++--- .../providers/aws/r/vpc_peering.html.markdown | 2 + 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index 5a3d8bda1..cbf80331d 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -35,6 +35,14 @@ func resourceAwsVpcPeeringConnection() *schema.Resource { Required: true, ForceNew: true, }, + "auto_accept": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + }, + "accept_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, "tags": tagsSchema(), }, } @@ -76,7 +84,6 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error d.Id(), err) } - // Update our attributes and return return resourceAwsVpcPeeringUpdate(d, meta) } @@ -93,10 +100,41 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { pc := pcRaw.(*ec2.VPCPeeringConnection) - d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID) - d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID) - d.Set("vpc_id", pc.RequesterVPCInfo.VPCID) - d.Set("tags", tagsToMapSDK(pc.Tags)) + if d.Get("auto_accept").(bool) { + resourceVpcPeeringConnectionAccept(ec2conn, pc, d) + } else { + d.Set("accept_status", pc.Status.Code) + } + + d.Set("peer_owner_id", pc.AccepterVpcInfo.OwnerId) + d.Set("peer_vpc_id", pc.AccepterVpcInfo.VpcId) + d.Set("vpc_id", pc.RequesterVpcInfo.VpcId) + d.Set("tags", tagsToMap(pc.Tags)) + + return nil +} + +func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, d *schema.ResourceData) error { + if oldPc.Status.Code == "pending-acceptance" { + log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", d.Id()) + _, err := conn.AcceptVpcPeeringConnection(d.Id()) + if err != nil { + return fmt.Errorf("Error accepting vpc peering connection: %s", err) + } + + pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())() + if err != nil { + return err + } + if pcRaw == nil { + d.SetId("") + return nil + } + + pc := pcRaw.(*ec2.VpcPeeringConnection) + d.Set("accept_status", pc.Status.Code) + + } return nil } @@ -110,7 +148,7 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error d.SetPartial("tags") } - return resourceAwsRouteTableRead(d, meta) + return resourceAwsVpcPeeringRead(d, meta) } func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/website/source/docs/providers/aws/r/vpc_peering.html.markdown b/website/source/docs/providers/aws/r/vpc_peering.html.markdown index 1d396a584..56e75b0bf 100644 --- a/website/source/docs/providers/aws/r/vpc_peering.html.markdown +++ b/website/source/docs/providers/aws/r/vpc_peering.html.markdown @@ -46,6 +46,7 @@ The following arguments are supported: * `peer_owner_id` - (Required) The AWS account ID of the owner of the peer VPC. * `peer_vpc_id` - (Required) The ID of the VPC with which you are creating the VPC peering connection. * `vpc_id` - (Required) The ID of the requester VPC. +* `auto_accept` - (Optional) Accept the peering ( you need to be the owner of both vpc) * `tags` - (Optional) A mapping of tags to assign to the resource. ## Attributes Reference @@ -53,6 +54,7 @@ The following arguments are supported: The following attributes are exported: * `id` - The ID of the VPC Peering Connectiona +* `accept_status` - The Status of the VPC peering connection request. ## Notes From 5658fd61223e63bcd904be5b66d24286ee1e2a66 Mon Sep 17 00:00:00 2001 From: jba Date: Tue, 10 Mar 2015 10:02:44 +0100 Subject: [PATCH 2/5] clean code --- .../resource_aws_vpc_peering_connection.go | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index cbf80331d..0c8001c4d 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -100,12 +100,18 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { pc := pcRaw.(*ec2.VPCPeeringConnection) - if d.Get("auto_accept").(bool) { - resourceVpcPeeringConnectionAccept(ec2conn, pc, d) - } else { - d.Set("accept_status", pc.Status.Code) + code := pc.Status.Code + if _, ok := d.GetOk("auto_accept"); ok { + updatedCode, err := resourceVpcPeeringConnectionAccept(ec2conn, pc, d.Id()) + if err != nil { + return fmt.Errorf("Error accepting vpc peering connection: %s", err) + } + + code = updatedCode } + d.Set("accept_status", code) + d.Set("peer_owner_id", pc.AccepterVpcInfo.OwnerId) d.Set("peer_vpc_id", pc.AccepterVpcInfo.VpcId) d.Set("vpc_id", pc.RequesterVpcInfo.VpcId) @@ -114,29 +120,18 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, d *schema.ResourceData) error { +func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, id string) (string, error) { + //func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, d *schema.ResourceData) error { if oldPc.Status.Code == "pending-acceptance" { - log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", d.Id()) - _, err := conn.AcceptVpcPeeringConnection(d.Id()) - if err != nil { - return fmt.Errorf("Error accepting vpc peering connection: %s", err) - } - - pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())() - if err != nil { - return err - } - if pcRaw == nil { - d.SetId("") - return nil - } + log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id) + _, err := conn.AcceptVpcPeeringConnection(id) + pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, id)() pc := pcRaw.(*ec2.VpcPeeringConnection) - d.Set("accept_status", pc.Status.Code) - + return pc.Status.Code, err } - return nil + return oldPc.Status.Code, nil } func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error { From e9215c0676a504ee9dafeee6008a944c721bfbbb Mon Sep 17 00:00:00 2001 From: jba Date: Tue, 17 Mar 2015 11:27:33 +0100 Subject: [PATCH 3/5] move accept block to the update func --- .../resource_aws_vpc_peering_connection.go | 70 +++++++++++-------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index 0c8001c4d..a0ff9a331 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -74,8 +74,8 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error d.Id()) stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, - Target: "ready", - Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id()), + Target: "pending-acceptance", + Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), Timeout: 1 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -100,38 +100,26 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { pc := pcRaw.(*ec2.VPCPeeringConnection) - code := pc.Status.Code - if _, ok := d.GetOk("auto_accept"); ok { - updatedCode, err := resourceVpcPeeringConnectionAccept(ec2conn, pc, d.Id()) - if err != nil { - return fmt.Errorf("Error accepting vpc peering connection: %s", err) - } - - code = updatedCode - } - - d.Set("accept_status", code) - - d.Set("peer_owner_id", pc.AccepterVpcInfo.OwnerId) - d.Set("peer_vpc_id", pc.AccepterVpcInfo.VpcId) - d.Set("vpc_id", pc.RequesterVpcInfo.VpcId) - d.Set("tags", tagsToMap(pc.Tags)) + d.Set("accept_status", *pc.Status.Code) + d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID) + d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID) + d.Set("vpc_id", pc.RequesterVPCInfo.VPCID) + d.Set("tags", tagsToMapSDK(pc.Tags)) return nil } -func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, id string) (string, error) { - //func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, d *schema.ResourceData) error { - if oldPc.Status.Code == "pending-acceptance" { - log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id) - _, err := conn.AcceptVpcPeeringConnection(id) +func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error) { - pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, id)() - pc := pcRaw.(*ec2.VpcPeeringConnection) - return pc.Status.Code, err + log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id) + + req := &ec2.AcceptVPCPeeringConnectionRequest{ + VPCPeeringConnectionID: aws.String(id), } - return oldPc.Status.Code, nil + resp, err := conn.AcceptVPCPeeringConnection(req) + pc := resp.VPCPeeringConnection + return *pc.Status.Code, err } func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error { @@ -143,6 +131,32 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error d.SetPartial("tags") } + if _, ok := d.GetOk("auto_accept"); ok { + + pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() + + if err != nil { + return err + } + if pcRaw == nil { + d.SetId("") + return nil + } + pc := pcRaw.(*ec2.VPCPeeringConnection) + + if *pc.Status.Code == "pending-acceptance" { + + status, err := resourceVpcPeeringConnectionAccept(ec2conn, d.Id()) + + log.Printf( + "[DEBUG] Vpc Peering connection accept status %s", + status) + if err != nil { + return err + } + } + } + return resourceAwsVpcPeeringRead(d, meta) } @@ -181,6 +195,6 @@ func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r pc := resp.VPCPeeringConnections[0] - return pc, "ready", nil + return pc, *pc.Status.Code, nil } } From c50bcf29308439e271583365526579c453492151 Mon Sep 17 00:00:00 2001 From: jba Date: Tue, 17 Mar 2015 11:34:22 +0100 Subject: [PATCH 4/5] renaming function according to the aws struct --- .../resource_aws_vpc_peering_connection.go | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index a0ff9a331..f790087a6 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -13,10 +13,10 @@ import ( func resourceAwsVpcPeeringConnection() *schema.Resource { return &schema.Resource{ - Create: resourceAwsVpcPeeringCreate, - Read: resourceAwsVpcPeeringRead, - Update: resourceAwsVpcPeeringUpdate, - Delete: resourceAwsVpcPeeringDelete, + Create: resourceAwsVPCPeeringCreate, + Read: resourceAwsVPCPeeringRead, + Update: resourceAwsVPCPeeringUpdate, + Delete: resourceAwsVPCPeeringDelete, Schema: map[string]*schema.Schema{ "peer_owner_id": &schema.Schema{ @@ -48,8 +48,8 @@ func resourceAwsVpcPeeringConnection() *schema.Resource { } } -func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).ec2conn +func resourceAwsVPCPeeringCreate(d *schema.ResourceData, meta interface{}) error { + ec2conn := meta.(*AWSClient).awsEC2conn // Create the vpc peering connection createOpts := &ec2.CreateVPCPeeringConnectionInput{ @@ -57,8 +57,8 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)), VPCID: aws.String(d.Get("vpc_id").(string)), } - log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts) - resp, err := conn.CreateVPCPeeringConnection(createOpts) + log.Printf("[DEBUG] VPCPeeringCreate create config: %#v", createOpts) + resp, err := ec2conn.CreateVPCPeeringConnection(createOpts) if err != nil { return fmt.Errorf("Error creating vpc peering connection: %s", err) } @@ -66,7 +66,7 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error // Get the ID and store it rt := resp.VPCPeeringConnection d.SetId(*rt.VPCPeeringConnectionID) - log.Printf("[INFO] Vpc Peering Connection ID: %s", d.Id()) + log.Printf("[INFO] VPC Peering Connection ID: %s", d.Id()) // Wait for the vpc peering connection to become available log.Printf( @@ -75,7 +75,7 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: "pending-acceptance", - Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), + Refresh: resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), Timeout: 1 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -84,12 +84,12 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error d.Id(), err) } - return resourceAwsVpcPeeringUpdate(d, meta) + return resourceAwsVPCPeeringUpdate(d, meta) } -func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).ec2conn - pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())() +func resourceAwsVPCPeeringRead(d *schema.ResourceData, meta interface{}) error { + ec2conn := meta.(*AWSClient).awsEC2conn + pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() if err != nil { return err } @@ -109,9 +109,9 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error) { +func resourceVPCPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error) { - log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id) + log.Printf("[INFO] Accept VPC Peering Connection with id: %s", id) req := &ec2.AcceptVPCPeeringConnectionRequest{ VPCPeeringConnectionID: aws.String(id), @@ -122,8 +122,8 @@ func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error return *pc.Status.Code, err } -func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).ec2conn +func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error { + ec2conn := meta.(*AWSClient).awsEC2conn if err := setTagsSDK(conn, d); err != nil { return err @@ -133,7 +133,7 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error if _, ok := d.GetOk("auto_accept"); ok { - pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() + pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() if err != nil { return err @@ -146,10 +146,10 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error if *pc.Status.Code == "pending-acceptance" { - status, err := resourceVpcPeeringConnectionAccept(ec2conn, d.Id()) + status, err := resourceVPCPeeringConnectionAccept(ec2conn, d.Id()) log.Printf( - "[DEBUG] Vpc Peering connection accept status %s", + "[DEBUG] VPC Peering connection accept status %s", status) if err != nil { return err @@ -157,11 +157,11 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error } } - return resourceAwsVpcPeeringRead(d, meta) + return resourceAwsVPCPeeringRead(d, meta) } -func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).ec2conn +func resourceAwsVPCPeeringDelete(d *schema.ResourceData, meta interface{}) error { + ec2conn := meta.(*AWSClient).awsEC2conn _, err := conn.DeleteVPCPeeringConnection( &ec2.DeleteVPCPeeringConnectionInput{ @@ -170,9 +170,9 @@ func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error return err } -// resourceAwsVpcPeeringConnectionStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch -// a VpcPeeringConnection. -func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { +// resourceAwsVPCPeeringConnectionStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch +// a VPCPeeringConnection. +func resourceAwsVPCPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsInput{ @@ -182,7 +182,7 @@ func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" { resp = nil } else { - log.Printf("Error on VpcPeeringConnectionStateRefresh: %s", err) + log.Printf("Error on VPCPeeringConnectionStateRefresh: %s", err) return nil, "", err } } From 4b160dd28e66a61d375ef08dcbede656ab1591cb Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 5 May 2015 10:45:30 -0500 Subject: [PATCH 5/5] minor cleanups --- .../resource_aws_vpc_peering_connection.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index f790087a6..73d6c8879 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -49,7 +49,7 @@ func resourceAwsVpcPeeringConnection() *schema.Resource { } func resourceAwsVPCPeeringCreate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEC2conn + conn := meta.(*AWSClient).ec2conn // Create the vpc peering connection createOpts := &ec2.CreateVPCPeeringConnectionInput{ @@ -58,7 +58,7 @@ func resourceAwsVPCPeeringCreate(d *schema.ResourceData, meta interface{}) error VPCID: aws.String(d.Get("vpc_id").(string)), } log.Printf("[DEBUG] VPCPeeringCreate create config: %#v", createOpts) - resp, err := ec2conn.CreateVPCPeeringConnection(createOpts) + resp, err := conn.CreateVPCPeeringConnection(createOpts) if err != nil { return fmt.Errorf("Error creating vpc peering connection: %s", err) } @@ -75,7 +75,7 @@ func resourceAwsVPCPeeringCreate(d *schema.ResourceData, meta interface{}) error stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: "pending-acceptance", - Refresh: resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), + Refresh: resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id()), Timeout: 1 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -88,8 +88,8 @@ func resourceAwsVPCPeeringCreate(d *schema.ResourceData, meta interface{}) error } func resourceAwsVPCPeeringRead(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEC2conn - pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() + conn := meta.(*AWSClient).ec2conn + pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() if err != nil { return err } @@ -113,7 +113,7 @@ func resourceVPCPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error log.Printf("[INFO] Accept VPC Peering Connection with id: %s", id) - req := &ec2.AcceptVPCPeeringConnectionRequest{ + req := &ec2.AcceptVPCPeeringConnectionInput{ VPCPeeringConnectionID: aws.String(id), } @@ -123,7 +123,7 @@ func resourceVPCPeeringConnectionAccept(conn *ec2.EC2, id string) (string, error } func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEC2conn + conn := meta.(*AWSClient).ec2conn if err := setTagsSDK(conn, d); err != nil { return err @@ -133,7 +133,7 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error if _, ok := d.GetOk("auto_accept"); ok { - pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() + pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() if err != nil { return err @@ -146,7 +146,7 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error if *pc.Status.Code == "pending-acceptance" { - status, err := resourceVPCPeeringConnectionAccept(ec2conn, d.Id()) + status, err := resourceVPCPeeringConnectionAccept(conn, d.Id()) log.Printf( "[DEBUG] VPC Peering connection accept status %s", @@ -161,7 +161,7 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error } func resourceAwsVPCPeeringDelete(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEC2conn + conn := meta.(*AWSClient).ec2conn _, err := conn.DeleteVPCPeeringConnection( &ec2.DeleteVPCPeeringConnectionInput{