add the auto_accecpt option

This commit is contained in:
jba 2015-03-09 09:59:52 +01:00 committed by Clint Shryock
parent c2695ba528
commit 11ba9b1042
2 changed files with 46 additions and 6 deletions

View File

@ -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 {

View File

@ -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