Skip to content
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

New Resource: aws_vpc_peering_connection_options #3909

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented Mar 25, 2018

Fixes #3069, #3676 and #3850.

Add a new resource aws_vpc_peering_connection_options that manages VPC peering connection options.
This resource decouples management of the connection options from management of the connection and allows options to be set correctly in cross-account scenarios:

provider "aws" {
  # Requester's credentials.
}

provider "aws" {
  alias = "peer"

  # Accepter's credentials.
}

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"

  enable_dns_support   = true
  enable_dns_hostnames = true
}

resource "aws_vpc" "peer" {
  provider   = "aws.peer"
  cidr_block = "10.1.0.0/16"

  enable_dns_support   = true
  enable_dns_hostnames = true
}

data "aws_caller_identity" "peer" {
  provider = "aws.peer"
}

# Requester's side of the connection.
resource "aws_vpc_peering_connection" "peer" {
  vpc_id        = "${aws_vpc.main.id}"
  peer_vpc_id   = "${aws_vpc.peer.id}"
  peer_owner_id = "${data.aws_caller_identity.peer.account_id}"
  auto_accept   = false

  tags {
    Side = "Requester"
  }
}

# Accepter's side of the connection.
resource "aws_vpc_peering_connection_accepter" "peer" {
  provider                  = "aws.peer"
  vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
  auto_accept               = true

  tags {
    Side = "Accepter"
  }
}

# As options can't be set until the connection has been accepted
# create an explicit dependency on the accepter.

resource "aws_vpc_peering_connection_options" "requester" {
  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  requester {
    allow_remote_vpc_dns_resolution = true
  }
}

resource "aws_vpc_peering_connection_options" "accepter" {
  provider                  = "aws.peer"
  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  accepter {
    allow_remote_vpc_dns_resolution = true
  }
}
terraform apply
data.aws_caller_identity.peer: Refreshing state...
aws_vpc.peer: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.1.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.main: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.0.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.main: Creation complete after 5s (ID: vpc-11111111)
aws_vpc.peer: Creation complete after 5s (ID: vpc-22222222)
aws_vpc_peering_connection.peer: Creating...
  accept_status: "" => "<computed>"
  accepter.#:    "" => "<computed>"
  auto_accept:   "" => "false"
  peer_owner_id: "" => "999999999999"
  peer_region:   "" => "us-west-2"
  peer_vpc_id:   "" => "vpc-22222222"
  requester.#:   "" => "<computed>"
  tags.%:        "" => "1"
  tags.Side:     "" => "Requester"
  vpc_id:        "" => "vpc-11111111"
aws_vpc_peering_connection.peer: Creation complete after 2s (ID: pcx-33333333)
aws_vpc_peering_connection_accepter.peer: Creating...
  accept_status:             "" => "<computed>"
  accepter.#:                "" => "<computed>"
  auto_accept:               "" => "true"
  peer_owner_id:             "" => "<computed>"
  peer_region:               "" => "<computed>"
  peer_vpc_id:               "" => "<computed>"
  requester.#:               "" => "<computed>"
  tags.%:                    "" => "1"
  tags.Side:                 "" => "Accepter"
  vpc_id:                    "" => "<computed>"
  vpc_peering_connection_id: "" => "pcx-33333333"
aws_vpc_peering_connection_accepter.peer: Creation complete after 2s (ID: pcx-33333333)
aws_vpc_peering_connection_options.accepter: Creating...
  accepter.#:                                           "" => "1"
  accepter.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  accepter.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  accepter.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  requester.#:                                          "" => "<computed>"
  vpc_peering_connection_id:                            "" => "pcx-33333333"
aws_vpc_peering_connection_options.requester: Creating...
  accepter.#:                                            "" => "<computed>"
  requester.#:                                           "" => "1"
  requester.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  requester.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  requester.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  vpc_peering_connection_id:                             "" => "pcx-33333333"
aws_vpc_peering_connection_options.requester: Creation complete after 0s (ID: pcx-33333333)
aws_vpc_peering_connection_options.accepter: Creation complete after 1s (ID: pcx-33333333)

Apply complete! Resources: 6 added, 0 changed, 0 destroyed.

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 25, 2018
@ewbankkit
Copy link
Contributor Author

Acceptance and regression tests:

aws_vpc_peering_connection_options resource

make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSVpcPeeringConnectionOptions_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSVpcPeeringConnectionOptions_ -timeout 120m
=== RUN   TestAccAWSVpcPeeringConnectionOptions_importBasic
--- PASS: TestAccAWSVpcPeeringConnectionOptions_importBasic (33.04s)
=== RUN   TestAccAWSVpcPeeringConnectionOptions_basic
--- PASS: TestAccAWSVpcPeeringConnectionOptions_basic (32.53s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	65.581s

aws_vpc_peering_connection data source

 make testacc TEST=./aws/ TESTARGS='-run=TestAccDataSourceAwsVpcPeeringConnection_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccDataSourceAwsVpcPeeringConnection_ -timeout 120m
=== RUN   TestAccDataSourceAwsVpcPeeringConnection_basic
--- PASS: TestAccDataSourceAwsVpcPeeringConnection_basic (33.33s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	33.349s

aws_vpc_peering_connection resource

make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSVPCPeeringConnection_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSVPCPeeringConnection_ -timeout 120m
=== RUN   TestAccAWSVPCPeeringConnection_importBasic
--- PASS: TestAccAWSVPCPeeringConnection_importBasic (31.08s)
=== RUN   TestAccAWSVPCPeeringConnection_basic
--- PASS: TestAccAWSVPCPeeringConnection_basic (29.34s)
=== RUN   TestAccAWSVPCPeeringConnection_plan
--- PASS: TestAccAWSVPCPeeringConnection_plan (28.83s)
=== RUN   TestAccAWSVPCPeeringConnection_tags
--- PASS: TestAccAWSVPCPeeringConnection_tags (29.90s)
=== RUN   TestAccAWSVPCPeeringConnection_options
--- PASS: TestAccAWSVPCPeeringConnection_options (50.88s)
=== RUN   TestAccAWSVPCPeeringConnection_failedState
--- PASS: TestAccAWSVPCPeeringConnection_failedState (18.77s)
=== RUN   TestAccAWSVPCPeeringConnection_peerRegionAndAutoAccept
--- PASS: TestAccAWSVPCPeeringConnection_peerRegionAndAutoAccept (16.53s)
=== RUN   TestAccAWSVPCPeeringConnection_region
--- PASS: TestAccAWSVPCPeeringConnection_region (31.98s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	237.328s

@@ -24,6 +23,12 @@ func resourceAwsVpcPeeringConnection() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added timeout configuration options and set defaults to the values in the existing code - 1 minute in all cases.


pcRaw, status, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this code and removed cases that couldn't be reached.

@radeksimko radeksimko added new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. labels Mar 26, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 26, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ewbankkit! Thanks for your contribution here. I think architecturally this is going to be the best approach to fix the ordering issues. Can you see my below comments and let me know if you have any questions? It's looking pretty good so far.

if err != nil {
return err
return errwrap.Wrapf("Error reading VPC Peering Connection: {{err}}", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We do not need errwrap for returning simple messages -- fmt.Errorf() is just fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this and other calls to errwrap.Wrapf() to use fmt.Errorf().

// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
return nil, "", err
}

pc := resp.VpcPeeringConnections[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have nil/len() checks for resp, resp.VpcPeeringConnections, and pc.Status to prevent panics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@@ -432,3 +381,7 @@ func checkVpcPeeringConnectionAvailable(conn *ec2.EC2, id string) error {
}
return nil
}

func isNoSuchVpcPeeringConnectionErr(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We prefer to not introduce indirection in such simple cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


d.Set("vpc_peering_connection_id", pc.VpcPeeringConnectionId)

if pc.AccepterVpcInfo.PeeringOptions != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have nil checks for pc.AccepterVpcInfo and pc.RequesterVpcInfo to prevent crashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Provides a resource to manage a VPC peering connection.

~> **NOTE on VPC Peering Connections and VPC Peering Connection Options:** Terraform provides
both a standalone [VPC Peering Connection Options](vpc_peering_options) and a VPC Peering Connection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link needs to be fixed 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# create an explicit dependency on the accepter.

resource "aws_vpc_peering_connection_options" "requester" {
vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be "${aws_vpc_peering_connection.peer.id}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it should be aws_vpc_peering_connection_accepter.peer.id.
The comment above

As options can't be set until the connection has been accepted
create an explicit dependency on the accepter.

is meant to explain why - We don't want to create the requester's options until the accepter has accepted.
I'll move the comment onto the line above the code.


```hcl
provider "aws" {
# Requester's credentials.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to very explicitly alias these as alias = "requester" and alias = "accepter" so the resources are very explicit as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that the new text works as expected:

$ terraform apply
data.aws_caller_identity.peer: Refreshing state...
aws_vpc.peer: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.1.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.main: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.0.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.main: Creation complete after 5s (ID: vpc-48684831)
aws_vpc.peer: Creation complete after 6s (ID: vpc-876343fe)
aws_vpc_peering_connection.peer: Creating...
  accept_status: "" => "<computed>"
  accepter.#:    "" => "<computed>"
  auto_accept:   "" => "false"
  peer_owner_id: "" => "000000000000"
  peer_region:   "" => "<computed>"
  peer_vpc_id:   "" => "vpc-876343fe"
  requester.#:   "" => "<computed>"
  tags.%:        "" => "1"
  tags.Side:     "" => "Requester"
  vpc_id:        "" => "vpc-48684831"
aws_vpc_peering_connection.peer: Creation complete after 2s (ID: pcx-47b7a92e)
aws_vpc_peering_connection_accepter.peer: Creating...
  accept_status:             "" => "<computed>"
  accepter.#:                "" => "<computed>"
  auto_accept:               "" => "true"
  peer_owner_id:             "" => "<computed>"
  peer_region:               "" => "<computed>"
  peer_vpc_id:               "" => "<computed>"
  requester.#:               "" => "<computed>"
  tags.%:                    "" => "1"
  tags.Side:                 "" => "Accepter"
  vpc_id:                    "" => "<computed>"
  vpc_peering_connection_id: "" => "pcx-47b7a92e"
aws_vpc_peering_connection_accepter.peer: Creation complete after 3s (ID: pcx-47b7a92e)
aws_vpc_peering_connection_options.accepter: Creating...
  accepter.#:                                           "" => "1"
  accepter.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  accepter.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  accepter.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  requester.#:                                          "" => "<computed>"
  vpc_peering_connection_id:                            "" => "pcx-47b7a92e"
aws_vpc_peering_connection_options.requester: Creating...
  accepter.#:                                            "" => "<computed>"
  requester.#:                                           "" => "1"
  requester.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  requester.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  requester.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  vpc_peering_connection_id:                             "" => "pcx-47b7a92e"
aws_vpc_peering_connection_options.requester: Creation complete after 1s (ID: pcx-47b7a92e)
aws_vpc_peering_connection_options.accepter: Creation complete after 1s (ID: pcx-47b7a92e)

Apply complete! Resources: 6 added, 0 changed, 0 destroyed.


# aws_vpc_peering_connection_options

Provides a resource to manage VPC peering connection options.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to mention the ordering problem here to explain why you'd want to use this resource over the arguments in the original resources. Same vice-versa.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.
I'll use text from this PR's description:

Using a VPC Peering Connection Options resource decouples management of the connection options from
management of the VPC Peering Connection and allows options to be set correctly in cross-account scenarios.

@bflad bflad self-assigned this Apr 23, 2018
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Apr 23, 2018
@ewbankkit
Copy link
Contributor Author

Sure, I should be able to get to these changes this week.

@ewbankkit ewbankkit force-pushed the add-aws-vpc-peering-connection-options-resource branch from 5afea8d to 45c82fa Compare April 27, 2018 12:34
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Apr 27, 2018
@ewbankkit
Copy link
Contributor Author

ewbankkit commented Apr 27, 2018

Made suggested changes, rebased to fix conflicts and re-ran tests:

make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSVpcPeeringConnectionOptions_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSVpcPeeringConnectionOptions_ -timeout 120m
=== RUN   TestAccAWSVpcPeeringConnectionOptions_importBasic
--- PASS: TestAccAWSVpcPeeringConnectionOptions_importBasic (34.00s)
=== RUN   TestAccAWSVpcPeeringConnectionOptions_basic
--- PASS: TestAccAWSVpcPeeringConnectionOptions_basic (31.98s)
PASS
make testacc TEST=./aws/ TESTARGS='-run=TestAccDataSourceAwsVpcPeeringConnection_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccDataSourceAwsVpcPeeringConnection_ -timeout 120m
=== RUN   TestAccDataSourceAwsVpcPeeringConnection_basic
--- PASS: TestAccDataSourceAwsVpcPeeringConnection_basic (44.29s)
PASS
make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSVPCPeeringConnection_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSVPCPeeringConnection_ -timeout 120m
=== RUN   TestAccAWSVPCPeeringConnection_importBasic
--- PASS: TestAccAWSVPCPeeringConnection_importBasic (31.67s)
=== RUN   TestAccAWSVPCPeeringConnection_basic
--- PASS: TestAccAWSVPCPeeringConnection_basic (28.86s)
=== RUN   TestAccAWSVPCPeeringConnection_plan
--- PASS: TestAccAWSVPCPeeringConnection_plan (29.02s)
=== RUN   TestAccAWSVPCPeeringConnection_tags
--- PASS: TestAccAWSVPCPeeringConnection_tags (31.61s)
=== RUN   TestAccAWSVPCPeeringConnection_options
--- PASS: TestAccAWSVPCPeeringConnection_options (58.48s)
=== RUN   TestAccAWSVPCPeeringConnection_failedState
--- PASS: TestAccAWSVPCPeeringConnection_failedState (18.15s)
=== RUN   TestAccAWSVPCPeeringConnection_peerRegionAndAutoAccept
--- PASS: TestAccAWSVPCPeeringConnection_peerRegionAndAutoAccept (16.08s)
=== RUN   TestAccAWSVPCPeeringConnection_region
--- PASS: TestAccAWSVPCPeeringConnection_region (36.07s)
PASS

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Apr 27, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @ewbankkit! Let's get this in. 🚀

@bflad
Copy link
Contributor

bflad commented May 2, 2018

This has been released in version 1.17.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@7rack
Copy link

7rack commented Nov 28, 2018

@ewbankkit i cannot enable remote vpc dns resolution,when create Inter-Region VPC Peering in the same account with Terraform v0.11.10 + provider.aws v1.41.0.

resource "aws_vpc_peering_connection" "peer" {
  vpc_id      = "${module.vpc.vpc_id}"
  peer_region = "ap-northeast-1"
  peer_vpc_id = "vpc-1c77767e"
  auto_accept = false

  tags {
    Name = "demo-pcx"
    Side = "Requester"
  }
}

resource "aws_vpc_peering_connection_accepter" "peer" {
  provider                  = "aws.peer"
  vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
  auto_accept               = true

  tags {
    Side = "Accepter"
  }
}

resource "aws_vpc_peering_connection_options" "requester" {
  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  requester {
    allow_remote_vpc_dns_resolution = true
  }
}

resource "aws_vpc_peering_connection_options" "accepter" {
  provider                  = "aws.peer"
  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  accepter {
    allow_remote_vpc_dns_resolution = true
  }
}

run apply get errors:

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_vpc_peering_connection_options.requester: Creating...
  accepter.#:                                            "" => "<computed>"
  requester.#:                                           "" => "1"
  requester.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  requester.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  requester.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  vpc_peering_connection_id:                             "" => "pcx-0699c559e000e56e8"
aws_vpc_peering_connection_options.accepter: Creating...
  accepter.#:                                           "" => "1"
  accepter.1102046665.allow_classic_link_to_remote_vpc: "" => "false"
  accepter.1102046665.allow_remote_vpc_dns_resolution:  "" => "true"
  accepter.1102046665.allow_vpc_to_remote_classic_link: "" => "false"
  requester.#:                                          "" => "<computed>"
  vpc_peering_connection_id:                            "" => "pcx-0699c559e000e56e8"
Releasing state lock. This may take a few moments...

Error: Error applying plan:

2 error(s) occurred:

* aws_vpc_peering_connection_options.requester: 1 error(s) occurred:

* aws_vpc_peering_connection_options.requester: Error modifying VPC Peering Connection Options: OperationNotPermitted: Modifying VPC peering connection options AllowEgressFromLocalClassicLinkToRemoteVpc, AllowEgressFromLocalVpcToRemoteClassicLink is not supported for cross-region VPC peering connections
        status code: 400, request id: 6dab72db-4ee2-40d9-a301-1959980996a7
* aws_vpc_peering_connection_options.accepter: 1 error(s) occurred:

* aws_vpc_peering_connection_options.accepter: Error modifying VPC Peering Connection Options: OperationNotPermitted: Modifying VPC peering connection options AllowEgressFromLocalClassicLinkToRemoteVpc, AllowEgressFromLocalVpcToRemoteClassicLink is not supported for cross-region VPC peering connections
        status code: 400, request id: b8341931-ce7a-43cc-9972-1fe19ac139ba

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

@ewbankkit
Copy link
Contributor Author

@7rack The [AWS documentation] states that ClassicLink options can't be set cross-region but DNS options can so it looks like we need to be smarter here; I'll take a look. Thanks.

@JoeyG1973
Copy link

JoeyG1973 commented Jan 15, 2019

@ewbankkit Any idea when this will be fixed? I just ran into this issue on cross-region peering.

Terraform v0.11.10
...
aws_vpc_peering_connection_options.accepter: Creating...
accepter.#: "" => "1"
accepter.3244290774.allow_classic_link_to_remote_vpc: "" => "false"
accepter.3244290774.allow_remote_vpc_dns_resolution: "" => "false"
accepter.3244290774.allow_vpc_to_remote_classic_link: "" => "false"
requester.#: "" => ""
vpc_peering_connection_id: "" => "pcx-040b19335e8f34783"
aws_vpc_peering_connection_options.requester: Creating...
accepter.#: "" => ""
requester.#: "" => "1"
requester.3244290774.allow_classic_link_to_remote_vpc: "" => "false"
requester.3244290774.allow_remote_vpc_dns_resolution: "" => "false"
requester.3244290774.allow_vpc_to_remote_classic_link: "" => "false"
vpc_peering_connection_id: "" => "pcx-040b19335e8f34783"

...

Error applying plan:

2 error(s) occurred:

  • aws_vpc_peering_connection_options.accepter: 1 error(s) occurred:

  • aws_vpc_peering_connection_options.accepter: Error modifying VPC Peering Connection Options: OperationNotPermitted: Modifying VPC peering connection options AllowEgressFromLocalClassicLinkToRemoteVpc, AllowEgressFromLocalVpcToRemoteClassicLink is not supported for cross-region VPC peering connections
    status code: 400, request id: df45a19f-3cf5-4183-87bd-f1f5ff22cddd

  • aws_vpc_peering_connection_options.requester: 1 error(s) occurred:

  • aws_vpc_peering_connection_options.requester: Error modifying VPC Peering Connection Options: OperationNotPermitted: Modifying VPC peering connection options AllowEgressFromLocalClassicLinkToRemoteVpc, AllowEgressFromLocalVpcToRemoteClassicLink is not supported for cross-region VPC peering connections
    status code: 400, request id: 0dd27e13-adc6-4905-8f18-c77e622b269f

@JoeyG1973
Copy link

The above is happening, but I realized I didn't need the options section in my TF file and that fixed my issue for now.

@hegyre
Copy link

hegyre commented Aug 7, 2019

Hi there,

I have the same issue with Terraform v0.11.11

@davidjamartin
Copy link

How does this help in the situation where you don't have control in the accepters account? My use case is that I want to enable allow_remote_vpc_dns_resolution, which cannot be done until the peering connection has been accepted.

My current workaround is to have a condition on the resource and run the apply twice, the second apply is run with the flag set to true after the accepter has accepted:

resource "aws_vpc_peering_connection_options" "accepter" {
  count                     = "${var.peer_accepted == true ? 1 : 0}"
  vpc_peering_connection_id = "${aws_vpc_peering_connection.peer2transit.id}"
  depends_on                = ["aws_vpc_peering_connection.peer2accepter"]
  requester {
    allow_remote_vpc_dns_resolution = true
  }
}

Ideally, I would like to be able to run this without having to change any parameters.

@ghost
Copy link

ghost commented Nov 1, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't set allow_remote_vpc_dns_resolution = true for aws_vpc_peering_connection
7 participants