clean code

This commit is contained in:
jba 2015-03-10 10:02:44 +01:00 committed by Clint Shryock
parent 11ba9b1042
commit 5658fd6122
1 changed files with 17 additions and 22 deletions

View File

@ -100,12 +100,18 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
pc := pcRaw.(*ec2.VPCPeeringConnection) pc := pcRaw.(*ec2.VPCPeeringConnection)
if d.Get("auto_accept").(bool) { code := pc.Status.Code
resourceVpcPeeringConnectionAccept(ec2conn, pc, d) if _, ok := d.GetOk("auto_accept"); ok {
} else { updatedCode, err := resourceVpcPeeringConnectionAccept(ec2conn, pc, d.Id())
d.Set("accept_status", pc.Status.Code) 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_owner_id", pc.AccepterVpcInfo.OwnerId)
d.Set("peer_vpc_id", pc.AccepterVpcInfo.VpcId) d.Set("peer_vpc_id", pc.AccepterVpcInfo.VpcId)
d.Set("vpc_id", pc.RequesterVpcInfo.VpcId) d.Set("vpc_id", pc.RequesterVpcInfo.VpcId)
@ -114,29 +120,18 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
return nil 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" { if oldPc.Status.Code == "pending-acceptance" {
log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", d.Id()) log.Printf("[INFO] Accept Vpc Peering Connection with id: %s", id)
_, err := conn.AcceptVpcPeeringConnection(d.Id()) _, err := conn.AcceptVpcPeeringConnection(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
}
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, id)()
pc := pcRaw.(*ec2.VpcPeeringConnection) 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 { func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error {