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

Add "bug-test" VPC for testing bug 8874 #9101

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cidr-allocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
| :---------- | :--- | :------------------------ |
| 10.231.0.0 | /21 | LAB ONLY garden - general |
| 10.231.8.0 | /21 | LAB ONLY house - general |
| 10.231.16.0 | /21 | - |
| 10.231.16.0 | /21 | LAB ONLY bug - general |
| 10.231.24.0 | /21 | - |
| 10.231.32.0 | /21 | - |
| | | |
18 changes: 18 additions & 0 deletions environments-networks/bug-sandbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cidr": {
"subnet_sets": {
"general": {
"cidr": "10.231.16.0/21",
"accounts": []
}
}
},
"options": {
"bastion_linux": true,
"additional_cidrs": [],
"additional_endpoints": [],
"additional_private_zones": [],
"additional_vpcs": [],
"dns_zone_extend": []
}
}
7 changes: 7 additions & 0 deletions policies/networking/expected.rego
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ expected :=
"accounts": [
]
}
},
"bug-sandbox": {
"general": {
"cidr": "10.231.16.0/21",
"accounts": [
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ resource "aws_ram_principal_association" "transit_gateway_association" {
# Attach the VPC to the central Transit Gateway
module "vpc_attachment" {
depends_on = [
aws_ram_principal_association.transit_gateway_association
aws_ram_principal_association.transit_gateway_association,
module.vpc
]
for_each = toset(keys(local.vpcs[terraform.workspace]))
source = "../../modules/ec2-tgw-attachment"
Expand Down
23 changes: 21 additions & 2 deletions terraform/environments/core-vpc/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ locals {

modernisation-platform-domain = "modernisation-platform.service.justice.gov.uk"
modernisation-platform-internal-domain = "modernisation-platform.internal"

private_route_tables = merge([
for vpc_key, vpc_value in local.vpcs[terraform.workspace] : {
for route_table_key, route_table_id in module.vpc[vpc_key].private_route_tables :
"${vpc_key}-${route_table_key}" => route_table_id
}
]...)
}

module "vpc" {
for_each = local.vpcs[terraform.workspace]
source = "github.com/ministryofjustice/modernisation-platform-terraform-member-vpc?ref=1366ebe0812d4c129c0b31cfc5bf2a4b0540672c" # v3.1.0
source = "github.com/ministryofjustice/modernisation-platform-terraform-member-vpc?ref=bug/8874-tgw-circular-dependency"
additional_endpoints = each.value.options.additional_endpoints
subnet_sets = { for key, subnet in each.value.cidr.subnet_sets : key => subnet.cidr }
transit_gateway_id = data.aws_ec2_transit_gateway.transit-gateway.id

# VPC Flow Logs
vpc_flow_log_iam_role = aws_iam_role.vpc_flow_log.arn
Expand Down Expand Up @@ -359,4 +365,17 @@ module "r53_dns_firewall" {

tags_prefix = each.key
tags_common = local.tags
}

resource "aws_route" "transit_gateway" {

depends_on = [
module.vpc_attachment,
module.vpc
]

for_each = local.private_route_tables
route_table_id = each.value
destination_cidr_block = "0.0.0.0/0"
transit_gateway_id = data.aws_ec2_transit_gateway.transit-gateway.id
}