move accept block to the update func
This commit is contained in:
parent
5658fd6122
commit
e9215c0676
|
@ -74,8 +74,8 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
d.Id())
|
d.Id())
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: "ready",
|
Target: "pending-acceptance",
|
||||||
Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id()),
|
Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -100,38 +100,26 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
pc := pcRaw.(*ec2.VPCPeeringConnection)
|
pc := pcRaw.(*ec2.VPCPeeringConnection)
|
||||||
|
|
||||||
code := pc.Status.Code
|
d.Set("accept_status", *pc.Status.Code)
|
||||||
if _, ok := d.GetOk("auto_accept"); ok {
|
d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID)
|
||||||
updatedCode, err := resourceVpcPeeringConnectionAccept(ec2conn, pc, d.Id())
|
d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID)
|
||||||
if err != nil {
|
d.Set("vpc_id", pc.RequesterVPCInfo.VPCID)
|
||||||
return fmt.Errorf("Error accepting vpc peering connection: %s", err)
|
d.Set("tags", tagsToMapSDK(pc.Tags))
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, oldPc *ec2.VpcPeeringConnection, id string) (string, error) {
|
func resourceVpcPeeringConnectionAccept(conn *ec2.EC2, 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)
|
|
||||||
|
|
||||||
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, id)()
|
log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id)
|
||||||
pc := pcRaw.(*ec2.VpcPeeringConnection)
|
|
||||||
return pc.Status.Code, err
|
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 {
|
func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
@ -143,6 +131,32 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
d.SetPartial("tags")
|
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)
|
return resourceAwsVpcPeeringRead(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +195,6 @@ func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r
|
||||||
|
|
||||||
pc := resp.VPCPeeringConnections[0]
|
pc := resp.VPCPeeringConnections[0]
|
||||||
|
|
||||||
return pc, "ready", nil
|
return pc, *pc.Status.Code, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue