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

[Issue 1037] Create non-default networking configuration #1044

Merged
merged 28 commits into from
Jan 24, 2024
Merged

Conversation

coilysiren
Copy link
Collaborator

@coilysiren coilysiren commented Jan 18, 2024

Summary

Fixes #1037

Time to review: 10 mins

Major Changes

  • Create a new VPC via the terraform-aws-modules/vpc/aws module
  • Updates the VPC endpoints (see vpc-endpoints.tf) to the latest pattern used by the Nava template, which puts them inside of modules/network/
  • Adds a staging networking terraform configuration file (infra/networks/staging.s3.tfbackend)

Warning

Potential Risk

Given the type of change being made here, its easily possible for terraform to get confused about what should be deployed where. That's why I've already had to make changes in advance of this one, to update the VPC / subnet selection logic. That was these changes:

Additional Context

Additionally, this PR is going to make it so that we are trying to deploy a new named VPC inside of the default networking configuration. In my opinion, that new VPC should be named dev. I will then follow-up later to create the prod VPC. Neither the dev nor the prod VPC will actually be used, not until I make another follow-up PR.

Yet More Context

To pull this off, I had to import the subnet backfill into the staging terraform state. The idea was that I didn't want to create duplicates of the subnet backfills. To do that, I had to run these commands:

terraform init -backend-config=staging.s3.tfbackend -reconfigure
terraform import  -var="environment_name=staging" 'aws_eip.backfill_private["us-east-1b"]' 'eipalloc-0bb8c35bf764c3bb4'
terraform import  -var="environment_name=staging" 'aws_eip.backfill_private["us-east-1c"]' 'eipalloc-0fe1a378791710d16'
terraform import  -var="environment_name=staging" 'aws_eip.backfill_private["us-east-1a"]' 'eipalloc-04e82fbd2ffc46760'
terraform import  -var="environment_name=staging" 'aws_subnet.backfill_private["us-east-1a"]' 'subnet-0eaabb77c8a4cb36f'
terraform import  -var="environment_name=staging" 'aws_subnet.backfill_private["us-east-1b"]' 'subnet-0d07d20186586955c'
terraform import  -var="environment_name=staging" 'aws_route_table.backfill_private["us-east-1a"]' 'rtb-0c3f83c55ed80ced1'
terraform import  -var="environment_name=staging" 'aws_route_table.backfill_private["us-east-1b"]' 'rtb-03f37f2f0041d2e10'
terraform import  -var="environment_name=staging" 'aws_route_table.backfill_private["us-east-1c"]' 'rtb-0204f7ff0aafd3fde'
terraform import  -var="environment_name=staging" 'aws_subnet.backfill_private["us-east-1c"]' 'subnet-030ca9f9cb581f502'
terraform import  -var="environment_name=staging" 'aws_nat_gateway.backfill_private_1' 'nat-016521ed99f539813'
terraform import  -var="environment_name=staging" 'aws_nat_gateway.backfill_private_0' 'nat-079ce3476c4199f63'
terraform import  -var="environment_name=staging" 'aws_nat_gateway.backfill_private_2' 'nat-074c4ad21b794f3c2'
terraform import  -var="environment_name=staging" 'aws_route_table_association.backfill_private["us-east-1c"]' 'rtbassoc-024a59ee23cba1e93'
terraform import  -var="environment_name=staging" 'aws_route_table_association.backfill_private["us-east-1b"]' 'rtbassoc-01800a6a80ac53ec7'
terraform import  -var="environment_name=staging" 'aws_route_table_association.backfill_private["us-east-1a"]' 'rtbassoc-0001ddfac545921c9'
terraform import  -var="environment_name=staging" 'aws_route.backfill_private_0' 'rtb-0c3f83c55ed80ced1_0.0.0.0/0'
terraform import  -var="environment_name=staging" 'aws_route.backfill_private_1' 'rtb-03f37f2f0041d2e10_0.0.0.0/0'
terraform import  -var="environment_name=staging" 'aws_route.backfill_private_2' 'rtb-0204f7ff0aafd3fde_0.0.0.0/0'

@coilysiren coilysiren changed the title Create Staging VPC [Issue 1037] Create Staging VPC Jan 22, 2024
@coilysiren coilysiren changed the title [Issue 1037] Create Staging VPC [Issue 1037] Create non-default networking configuration Jan 23, 2024
@coilysiren coilysiren changed the title [Issue 1037] Create non-default networking configuration [Issue 1037] Create non-default networking configuration (for staging) Jan 23, 2024
@coilysiren coilysiren changed the title [Issue 1037] Create non-default networking configuration (for staging) [Issue 1037] Create non-default networking configuration Jan 23, 2024
@coilysiren coilysiren self-assigned this Jan 23, 2024
@coilysiren coilysiren marked this pull request as ready for review January 24, 2024 00:01
Copy link
Collaborator

@jamesbursa jamesbursa left a comment

Choose a reason for hiding this comment

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

Thanks for implementing!

Comment on lines +20 to +22
# S3 and DynamoDB use Gateway VPC endpoints. All other services use Interface VPC endpoints
interface_vpc_endpoints = toset([for aws_service in local.aws_service_integrations : aws_service if !contains(["s3", "dynamodb"], aws_service)])
gateway_vpc_endpoints = toset([for aws_service in local.aws_service_integrations : aws_service if contains(["s3", "dynamodb"], aws_service)])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Untested idea:

Suggested change
# S3 and DynamoDB use Gateway VPC endpoints. All other services use Interface VPC endpoints
interface_vpc_endpoints = toset([for aws_service in local.aws_service_integrations : aws_service if !contains(["s3", "dynamodb"], aws_service)])
gateway_vpc_endpoints = toset([for aws_service in local.aws_service_integrations : aws_service if contains(["s3", "dynamodb"], aws_service)])
# S3 and DynamoDB use Gateway VPC endpoints. All other services use Interface VPC endpoints
gateway_services = ["s3", "dynamodb"]
interface_vpc_endpoints = setsubtract(local.aws_service_integrations, local.gateway_services)
gateway_vpc_endpoints = setintersection(local.aws_service_integrations, local.gateway_services)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would try that, but this file is a straight copy from the Nava template, and I kinda wanna keep it that way.

This is a good suggestion for the Nava template though! => https://github.com/navapbc/template-infra/blob/main/infra/modules/network/vpc-endpoints.tf

@coilysiren coilysiren merged commit 88f9405 into main Jan 24, 2024
7 checks passed
@coilysiren coilysiren deleted the staging-net branch January 24, 2024 17:54
coilysiren added a commit that referenced this pull request Jan 24, 2024
## Summary

**_Creates_** but does not _**use**_ the non-defaults for dev and prod.

Rolls up to, but does't resolve,
#1051

### Time to review: __1 mins__

## Changes proposed

- Creates a prod networking configuration
- Renames the "default" networking configuration to "dev"

## Deployment

```bash
$ cd infra/networks
$ terraform init -backend-config=dev.s3.tfbackend -reconfigure # this used to be "default"
$ terraform apply -var="environment_name=dev"
```

```bash
$ cd infra/networks
$ terraform init -backend-config=prod.s3.tfbackend -reconfigure
$ terraform apply -var="environment_name=prod"
```

## Yet More Context

Similarly to #1044, I had
to import the subnet backfill into the prod terraform state. The
commands for that were:

```bash
terraform import  -var="environment_name=prod" 'aws_eip.backfill_private["us-east-1b"]' 'eipalloc-0bb8c35bf764c3bb4'
terraform import  -var="environment_name=prod" 'aws_eip.backfill_private["us-east-1c"]' 'eipalloc-0fe1a378791710d16'
terraform import  -var="environment_name=prod" 'aws_eip.backfill_private["us-east-1a"]' 'eipalloc-04e82fbd2ffc46760'
terraform import  -var="environment_name=prod" 'aws_subnet.backfill_private["us-east-1a"]' 'subnet-0eaabb77c8a4cb36f'
terraform import  -var="environment_name=prod" 'aws_subnet.backfill_private["us-east-1b"]' 'subnet-0d07d20186586955c'
terraform import  -var="environment_name=prod" 'aws_route_table.backfill_private["us-east-1a"]' 'rtb-0c3f83c55ed80ced1'
terraform import  -var="environment_name=prod" 'aws_route_table.backfill_private["us-east-1b"]' 'rtb-03f37f2f0041d2e10'
terraform import  -var="environment_name=prod" 'aws_route_table.backfill_private["us-east-1c"]' 'rtb-0204f7ff0aafd3fde'
terraform import  -var="environment_name=prod" 'aws_subnet.backfill_private["us-east-1c"]' 'subnet-030ca9f9cb581f502'
terraform import  -var="environment_name=prod" 'aws_nat_gateway.backfill_private_1' 'nat-016521ed99f539813'
terraform import  -var="environment_name=prod" 'aws_nat_gateway.backfill_private_0' 'nat-079ce3476c4199f63'
terraform import  -var="environment_name=prod" 'aws_nat_gateway.backfill_private_2' 'nat-074c4ad21b794f3c2'
```

```bash
terraform import  -var="environment_name=prod" 'aws_route.backfill_private_0' 'rtb-0c3f83c55ed80ced1_0.0.0.0/0'
terraform import  -var="environment_name=prod" 'aws_route.backfill_private_1' 'rtb-03f37f2f0041d2e10_0.0.0.0/0'
terraform import  -var="environment_name=prod" 'aws_route.backfill_private_2' 'rtb-0204f7ff0aafd3fde_0.0.0.0/0'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Create staging networking configuration in terraform
2 participants