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

Can't associate VPCs in second account with non-default route table #27

Closed
2stacks opened this issue Nov 16, 2020 · 9 comments
Closed
Labels

Comments

@2stacks
Copy link

2stacks commented Nov 16, 2020

Versions

terraform = v0.13.5
aws provider = v3.2.0
transit-gateway module = 1.3.0

Module settings

Account A

create_tgw = true 
share_tgw = true
ram_allow_external_principals = true
ram_principals = [<account_b>]
enable_default_route_table_association = false
enable_default_route_table_propagation = false

Account B

create_tgw = false 
share_tgw = true

vpc_attachments = {
  vpc-1 = {
    <snip>
    tgw_id = module.account_a.this_ec2_transit_gateway_id
    transit_gateway_route_table_id = module.account_a.this_ec2_transit_gateway_route_table_id
    transit_gateway_default_route_table_association = false
    transit_gateway_default_route_table_propagation = false
  }
}

For this to work, the VPC attachment needs to be created in Account B but the association/propagation or routes need to be created in Account A. The module tries to create all resources in Account B and fails.

module.account_b.aws_ec2_transit_gateway_route_table_association.this["vpc-1"]  will be created
module.account_b.aws_ec2_transit_gateway_route_table_propagation.this["vpc-1"] will be created
module.account_b.aws_ec2_transit_gateway_vpc_attachment.this["vpc-1"] will be created

Error messages;

Error: error associating EC2 Transit Gateway Route Table (tgw-rtb-<id>) association (tgw-attach-<id>): InvalidRouteTableID.NotFound: Transit Gateway Route Table tgw-rtb-<id> was deleted or does not exist.
        status code: 400, request id: <id>

Error: error associating EC2 Transit Gateway Route Table (tgw-rtb-<id>) association (tgw-attach-<id>): InvalidRouteTableID.NotFound: Transit Gateway Route Table tgw-rtb-<id> was deleted or does not exist.
        status code: 400, request id: <id>
@morp86
Copy link

morp86 commented Jun 2, 2021

Hey @2stacks, did you ever figure out this issue? Im bumping into the exact same problem.

As you mentioned, the VPC attachment needs to be created in Account B but the association/propagation or routes need to be created in Account A. The module tries to create all resources in Account B and fails.

Any help would be appreciated.

@2stacks
Copy link
Author

2stacks commented Jun 2, 2021 via email

@morp86
Copy link

morp86 commented Jun 2, 2021

Thanks for your quick reply. Id be mainly interested in the part you used to get the association / propagation working for attachments created in other accounts, if thats included in your code.

If you wouldn't mind sharing your TGW code, I might be able to figure out / pull the parts I need.

@ThisIsQasim
Copy link

ThisIsQasim commented Jun 28, 2021

Quite a few people are reporting this issue (including myself) @antonbabenko @tfhartmann can you take a look here? Any help would be appreciated.

@2stacks
Copy link
Author

2stacks commented Jun 28, 2021

Was there supposed to be a link? I plan to upload what I have for comment/collaboration. It's fairly opinionated so it may not make a good module but perhaps it can be used to improve the existing TGW module.

@morp86
Copy link

morp86 commented Jun 29, 2021

To close the loop here. I ended rewriting allot of the code as well. The way to get around creating the resources in the wrong account is by adding an addition config block to you TGW module section.

Section for TGW account:

module "transit_gateway" {
source = "../../"

#Takes care of sharing the TGW resource to other accounts using AWS RAM.
ram_resource_share_enabled = true
ram_principal = var.customer_account_numbers
allow_external_principals = true

providers = {
aws = aws.network
}

tags_name = "xxxxx"
description = "xxxxx"
tags_environment = "prod"

#Creates TGW in Networking account
create_transit_gateway = true
create_transit_gateway_route_table = true
default_route_table_association = "enable"
default_route_table_propagation = "disable"
create_transit_gateway_route_table_association = false
create_transit_gateway_route_table_propagation = true
existing_transit_gateway_route_table_id = module.transit_gateway.transit_gateway_shared_route_table_id
create_transit_gateway_route_table_association_and_propagation = false

#Create route table association and propagation for Customer VPC attachments
config = {

#  vpc-123456 = {                              <-- Please use VPC-ID for name.
#  vpc_id                            = null             <-- Can be set to null, as we arent create an attachment.
#  subnet_ids                        = null             <-- Can be set to null, as we arent create an attachment.
#  transit_gateway_vpc_attachment_id = module.account1234567890.transit_gateway_vpc_attachment_ids["vpc-123456"]   <-- Reuse attachment ID create by the Customer account module.
#},

#Module for attachment in customer account:

module "account1234567890" {
source = "../../"

providers = {
aws = aws.account1234567890
}

ram_resource_share_enabled = true
ram_principal = null
ram_resource_share_arn = module.transit_gateway.ram_resource_share_id
existing_transit_gateway_id = module.transit_gateway.transit_gateway_id
existing_transit_gateway_route_table_id = module.transit_gateway.transit_gateway_shared_route_table_id
create_transit_gateway = false
create_transit_gateway_route_table = false
create_transit_gateway_vpc_attachment = true
create_transit_gateway_route_table_association = false
create_transit_gateway_route_table_propagation = false
create_transit_gateway_route_table_association_and_propagation = false

config = {
vpc-123456 = {
vpc_id = "vpc-123456"
subnet_ids = ["subnet-11111111","subnet-2222222","subnet-3333333"]
transit_gateway_vpc_attachment_id = null # <-- this wont be used in module for customers.
accountnumber = "123456" # <--- Im using this for RAM sharing
}
}
}

Hope this helps!

@github-actions
Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label Jan 12, 2022
@github-actions
Copy link

This issue was automatically closed because of stale in 10 days

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants