|
1 |
| -package aws |
2 |
| - |
3 |
| -import ( |
4 |
| - "fmt" |
5 |
| - "github.com/aws/aws-sdk-go/service/ec2" |
6 |
| - "github.com/hashicorp/terraform/helper/schema" |
7 |
| -) |
8 |
| - |
9 |
| -func resourceAwsVpcPeeringConnectionAccept() *schema.Resource { |
10 |
| - return &schema.Resource{ |
11 |
| - Create: resourceAwsVPCPeeringAcceptCreate, |
12 |
| - Read: resourceAwsVPCPeeringAcceptRead, |
13 |
| - Update: resourceAwsVPCPeeringAcceptUpdate, |
14 |
| - Delete: resourceAwsVPCPeeringAcceptDelete, |
15 |
| - |
16 |
| - Schema: map[string]*schema.Schema{ |
17 |
| - "peering_connection_id": &schema.Schema{ |
18 |
| - Type: schema.TypeString, |
19 |
| - Required: true, |
20 |
| - ForceNew: true, |
21 |
| - }, |
22 |
| - }, |
23 |
| - } |
24 |
| -} |
25 |
| - |
26 |
| -func resourceAwsVPCPeeringAcceptCreate(d *schema.ResourceData, meta interface{}) error { |
27 |
| - return resourceAwsVPCPeeringAcceptUpdate(d, meta) |
28 |
| -} |
29 |
| - |
30 |
| -func resourceAwsVPCPeeringAcceptRead(d *schema.ResourceData, meta interface{}) error { |
31 |
| - conn := meta.(*AWSClient).ec2conn |
32 |
| - _, state, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() |
33 |
| - if err != nil { |
34 |
| - return err |
35 |
| - } |
36 |
| - d.Set("state", state) |
37 |
| - d.SetId(d.Get("peering_connection_id")) |
38 |
| - return nil |
39 |
| -} |
40 |
| - |
41 |
| -func resourceAwsVPCPeeringAcceptUpdate(d *schema.ResourceData, meta interface{}) error { |
42 |
| - conn := meta.(*AWSClient).ec2conn |
43 |
| - |
44 |
| - if cur, ok := d.Get("state").(string); ok && cur == ec2.VpcPeeringConnectionStateReasonCodeActive { |
45 |
| - // already accepted |
46 |
| - return nil |
47 |
| - } |
48 |
| - |
49 |
| - state, err := resourceVPCPeeringConnectionAccept(conn, d.Id()) |
50 |
| - if err != nil { |
51 |
| - return err |
52 |
| - } |
53 |
| - d.Set("state", state) |
54 |
| - |
55 |
| - // TODO: should we poll until this resolves? VpcPeeringConnectionStateReasonCodePendingAcceptance |
56 |
| - |
57 |
| - if state != ec2.VpcPeeringConnectionStateReasonCodeActive { |
58 |
| - return fmt.Errorf("Error accepting connection, state: %s", state) |
59 |
| - } |
60 |
| - return nil |
61 |
| -} |
62 |
| - |
63 |
| -func resourceAwsVPCPeeringAcceptDelete(d *schema.ResourceData, meta interface{}) error { |
64 |
| - return nil |
65 |
| -} |
| 1 | +package aws |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/aws/aws-sdk-go/service/ec2" |
| 6 | + "github.com/hashicorp/terraform/helper/schema" |
| 7 | +) |
| 8 | + |
| 9 | +func resourceAwsVpcPeeringConnectionAccept() *schema.Resource { |
| 10 | + return &schema.Resource{ |
| 11 | + Create: resourceAwsVPCPeeringAcceptCreate, |
| 12 | + Read: resourceAwsVPCPeeringAcceptRead, |
| 13 | + Update: resourceAwsVPCPeeringAcceptUpdate, |
| 14 | + Delete: resourceAwsVPCPeeringAcceptDelete, |
| 15 | + |
| 16 | + Schema: map[string]*schema.Schema{ |
| 17 | + "peering_connection_id": &schema.Schema{ |
| 18 | + Type: schema.TypeString, |
| 19 | + Required: true, |
| 20 | + ForceNew: true, |
| 21 | + }, |
| 22 | + }, |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func resourceAwsVPCPeeringAcceptCreate(d *schema.ResourceData, meta interface{}) error { |
| 27 | + return resourceAwsVPCPeeringAcceptUpdate(d, meta) |
| 28 | +} |
| 29 | + |
| 30 | +func resourceAwsVPCPeeringAcceptRead(d *schema.ResourceData, meta interface{}) error { |
| 31 | + conn := meta.(*AWSClient).ec2conn |
| 32 | + _, state, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() |
| 33 | + if err != nil { |
| 34 | + return err |
| 35 | + } |
| 36 | + d.Set("state", state) |
| 37 | + d.SetId(d.Get("peering_connection_id").(string)) |
| 38 | + return nil |
| 39 | +} |
| 40 | + |
| 41 | +func resourceAwsVPCPeeringAcceptUpdate(d *schema.ResourceData, meta interface{}) error { |
| 42 | + conn := meta.(*AWSClient).ec2conn |
| 43 | + |
| 44 | + if cur, ok := d.Get("state").(string); ok && cur == ec2.VpcPeeringConnectionStateReasonCodeActive { |
| 45 | + // already accepted |
| 46 | + return nil |
| 47 | + } |
| 48 | + |
| 49 | + state, err := resourceVPCPeeringConnectionAccept(conn, d.Id()) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + d.Set("state", state) |
| 54 | + |
| 55 | + // TODO: should we poll until this resolves? VpcPeeringConnectionStateReasonCodePendingAcceptance |
| 56 | + |
| 57 | + if state != ec2.VpcPeeringConnectionStateReasonCodeActive { |
| 58 | + return fmt.Errorf("Error accepting connection, state: %s", state) |
| 59 | + } |
| 60 | + return nil |
| 61 | +} |
| 62 | + |
| 63 | +func resourceAwsVPCPeeringAcceptDelete(d *schema.ResourceData, meta interface{}) error { |
| 64 | + return nil |
| 65 | +} |
0 commit comments