-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Implementing vpc_peering_connection_accept
#6843
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
builtin/providers/aws/resource_aws_vpc_peering_connection_accept.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsVpcPeeringConnectionAccept() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsVPCPeeringAcceptCreate, | ||
Read: resourceAwsVPCPeeringAcceptRead, | ||
Delete: resourceAwsVPCPeeringAcceptDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"peering_connection_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"accept_status": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsVPCPeeringAcceptCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
if cur, ok := d.Get("accept_status").(string); ok && cur == ec2.VpcPeeringConnectionStateReasonCodeActive { | ||
// already accepted | ||
return nil | ||
} | ||
|
||
status, err := resourceVPCPeeringConnectionAccept(conn, d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
d.Set("accept_status", status) | ||
|
||
// TODO: should we poll until this resolves? VpcPeeringConnectionStateReasonCodePendingAcceptance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it didn't work for me until after I added:
|
||
|
||
if status != ec2.VpcPeeringConnectionStateReasonCodeActive { | ||
return fmt.Errorf("Error accepting connection, state: %s", status) | ||
} | ||
return nil | ||
} | ||
|
||
func resourceAwsVPCPeeringAcceptRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
_, status, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() | ||
if err != nil { | ||
return err | ||
} | ||
d.Set("accept_status", status) | ||
d.SetId(d.Get("peering_connection_id").(string)) | ||
return nil | ||
} | ||
|
||
func resourceAwsVPCPeeringAcceptDelete(d *schema.ResourceData, meta interface{}) error { | ||
return nil | ||
} |
69 changes: 69 additions & 0 deletions
69
builtin/providers/aws/resource_aws_vpc_peering_connection_accept_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestAccAWSVPCPeeringConnectionAccept_basic(t *testing.T) { | ||
var connection ec2.VpcPeeringConnection | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
if os.Getenv("AWS_ACCOUNT_ID") == "" { | ||
t.Fatal("AWS_ACCOUNT_ID must be set") | ||
} | ||
}, | ||
|
||
IDRefreshName: "aws_vpc_peering_connection.foo", | ||
IDRefreshIgnore: []string{"auto_accept"}, | ||
|
||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccVpcPeeringAcceptConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &connection), | ||
testAccCheckAWSVpcPeeringConnectionAccepted(&connection), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSVpcPeeringConnectionAccepted(conn *ec2.VpcPeeringConnection) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if conn.Status == nil { | ||
return fmt.Errorf("No vpc peering connection status") | ||
} | ||
if *conn.Status.Code != ec2.VpcPeeringConnectionStateReasonCodeActive { | ||
return fmt.Errorf("Vpc peering connection not accepted: %s", conn.Status.Code) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
const testAccVpcPeeringAcceptConfig = ` | ||
resource "aws_vpc" "foo" { | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
|
||
resource "aws_vpc" "bar" { | ||
cidr_block = "10.1.0.0/16" | ||
} | ||
|
||
resource "aws_vpc_peering_connection" "foo" { | ||
vpc_id = "${aws_vpc.foo.id}" | ||
peer_vpc_id = "${aws_vpc.bar.id}" | ||
auto_accept = false | ||
} | ||
|
||
resource "aws_vpc_peering_connection_accept" "foo" { | ||
peering_connection_id = "${aws_vpc_peering_connection.foo.id}" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
website/source/docs/providers/aws/r/vpc_peering_accept.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_vpc_peering_connection_accept" | ||
sidebar_current: "docs-aws-resource-vpc-peering-accept" | ||
description: |- | ||
Provides a VPC Peering Connection Accept resource. | ||
--- | ||
|
||
# aws\_vpc\_peering\_connection\_accept | ||
|
||
Provides a VPC Peering Connection Accept resource. | ||
|
||
## Example Usage | ||
|
||
Basic usage: | ||
|
||
``` | ||
resource "aws_vpc" "main" { | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
provider "aws" { | ||
// another AWS account creds | ||
access_key = "..." | ||
secret_key = "..." | ||
alias = "peer" | ||
} | ||
resource "aws_vpc" "peer" { | ||
provider = "aws.peer" | ||
cidr_block = "10.1.0.0/16" | ||
} | ||
resource "aws_vpc_peering_connection" "peer" { | ||
vpc_id = "${aws_vpc.main.id}" | ||
peer_vpc_id = "${aws_vpc.peer.id}" | ||
auto_accept = false | ||
} | ||
resource "aws_vpc_peering_connection_accept" "peer" { | ||
provider = "aws.peer" | ||
peering_connection_id = "${aws_vpc_peering_connection.peer.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `peering_connection_id` - (Required) The VPC Peering Connection ID to accept. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of the VPC Peering Connection. | ||
* `accept_status` - The Status of the VPC peering connection request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The d.Id() was not immediately available for me, I had to assign it explicitly:
d.SetId(d.Get("peering_connection_id").(string))