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

Update documentation to clarify support for multiple AWS accounts and multiple applications #589

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
0a15153
Add documentation for multiple AWS accounts
rocketnova Apr 25, 2024
6931f1e
Reword for multiple AWS accounts
rocketnova Apr 25, 2024
d58024f
Fix typos
rocketnova Apr 25, 2024
1dfb115
Add documentation for configuring apps
rocketnova Apr 25, 2024
c75a43d
Make READMEs less circular
rocketnova Apr 25, 2024
f9fe792
Remove brittle next step
rocketnova Apr 25, 2024
87bd8dd
Fix headings and use consistent prereq terminology
rocketnova Apr 25, 2024
ce9ff9e
Use consistent prereq terminology
rocketnova Apr 25, 2024
594dee0
Fix link name
rocketnova Apr 25, 2024
ba38e6a
Make markdown list notation consistent
rocketnova Apr 25, 2024
392f5c3
Add high level notes on what the doc covers
rocketnova Apr 25, 2024
fc5b686
Change instruction format
rocketnova Apr 25, 2024
42c1a97
Modify network instructions
rocketnova Apr 25, 2024
352193c
Start working on network docs
rocketnova Apr 25, 2024
e329a98
Modify network docs. Make custom domains actually optional.
rocketnova Apr 25, 2024
83ceda9
WIP
rocketnova Apr 25, 2024
705dacf
Wordsmith
rocketnova Apr 25, 2024
28286fa
WIP
rocketnova Apr 26, 2024
6210dac
Fix set-up-networks plural
rocketnova Apr 26, 2024
da50ed2
WIP
rocketnova Apr 26, 2024
6396ff4
Continue to refine multi-* language
rocketnova Apr 26, 2024
4ea13f1
Rework build repository docs
rocketnova Apr 26, 2024
39a8023
Address app-service
rocketnova Apr 26, 2024
27b3c87
Work on monitoring
rocketnova Apr 26, 2024
162799c
Work on custom domains
rocketnova Apr 26, 2024
e4e196b
Adjust indentation
rocketnova Apr 26, 2024
3d1ca31
Wordsmith
rocketnova Apr 30, 2024
eee2a24
Add more clarity
rocketnova Apr 30, 2024
b28fea5
Consistency
rocketnova Apr 30, 2024
a397335
Consistency
rocketnova Apr 30, 2024
ab98d66
Consistency. Clarity
rocketnova Apr 30, 2024
1604742
Fix typo
rocketnova Apr 30, 2024
c460330
Clarify
rocketnova Apr 30, 2024
082ffd9
Clarity
rocketnova Apr 30, 2024
96af1c5
Fix typo
rocketnova Apr 30, 2024
e6316ac
Clarity
rocketnova Apr 30, 2024
f92c48a
Wrong syntax
rocketnova Apr 30, 2024
36248f4
Rename for consistency
rocketnova Apr 30, 2024
c4fd3a8
Fix typos
rocketnova Apr 30, 2024
f3061c8
Update network docs
rocketnova Apr 30, 2024
aea6984
Update CI/CD
rocketnova Apr 30, 2024
4b58d92
Add docs and script for installing multiple apps
rocketnova May 2, 2024
a3496fb
Add script comments
rocketnova May 2, 2024
73b076c
Suppress script verbosity
rocketnova May 2, 2024
aa1b3d4
Link to new docs
rocketnova May 2, 2024
6263e12
Update update-template.sh
rocketnova May 3, 2024
8f3ec62
Add WIP
rocketnova May 3, 2024
9f64936
WIP update
rocketnova May 3, 2024
070ac8f
Fix target types
rocketnova May 4, 2024
08917f5
Add more documentation
rocketnova May 4, 2024
831ed9e
Refactor. Update docs
rocketnova May 4, 2024
f8f8c28
Remove feature flag infra changes
rocketnova May 7, 2024
b2a7d06
Remove network infra changes
rocketnova May 7, 2024
ec0d699
Improve technical writing
rocketnova May 7, 2024
f74f890
Improve technical writing
rocketnova May 7, 2024
12ed368
Improve technical writing
rocketnova May 7, 2024
ddf9324
Improve technical writing
rocketnova May 7, 2024
b72f33f
Improve technical writing
rocketnova May 7, 2024
70afcb3
Improve technical writing
rocketnova May 7, 2024
84662b9
Improve technical writing
rocketnova May 7, 2024
d0463bc
Improve technical writing
rocketnova May 7, 2024
24d12f6
Improve technical writing
rocketnova May 7, 2024
2bf687d
Consistently capitalize 'Terraform'
rocketnova May 7, 2024
fc1d704
Make setup lists and prereq lists consistent
rocketnova May 7, 2024
7fe9315
Improve technical writing
rocketnova May 7, 2024
fa18d90
Improve technical writing
rocketnova May 7, 2024
4ba3e60
Improve technical writing
rocketnova May 7, 2024
3341ed4
Improve technical writing
rocketnova May 7, 2024
7bbe2d1
Improve technical writing
rocketnova May 7, 2024
460aac5
Improve technical writing
rocketnova May 7, 2024
bf5466e
Improve technical writing
rocketnova May 7, 2024
5c3f37d
Improve technical writing
rocketnova May 7, 2024
156ff85
Improve technical writing
rocketnova May 7, 2024
ea81834
Improve technical writing
rocketnova May 7, 2024
44486a1
Improve technical writing
rocketnova May 7, 2024
a820bf5
Improve technical writing
rocketnova May 7, 2024
98df1cb
Improve technical writing
rocketnova May 7, 2024
e4aadc5
Use relative links
rocketnova May 7, 2024
1c263f6
Fix prereq
rocketnova May 7, 2024
8310979
Add stronger warnings
rocketnova May 7, 2024
754621d
Add link to release notes
rocketnova May 7, 2024
a6691b2
Add missing documentation
rocketnova May 7, 2024
d0ee3a3
Merge branch 'main' into rocket/multi-app
rocketnova May 8, 2024
c836634
Consistency
rocketnova May 8, 2024
5fd5b3b
Address shellcheck
rocketnova May 16, 2024
63d57c1
Alternate app update to avoid no-index where possible
rocketnova May 16, 2024
2d6c3e7
Address shellcheck
rocketnova May 16, 2024
9003c84
Update template-only CI/CD
rocketnova May 16, 2024
8ec917a
Move auth with AWS into prereqs instead of step 1
rocketnova May 16, 2024
0b2170a
Merge branch 'main' into rocket/multi-app
rocketnova May 16, 2024
71f2cd4
Update command execution docs for consistency
rocketnova May 16, 2024
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 .github/workflows/template-only-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Update infra template
working-directory: project-repo
run: ../template-infra/template-only-bin/update-template.sh
run: ../template-infra/template-only-bin/update-template.sh app

- name: Push changes to project repo
working-directory: project-repo
Expand Down
62 changes: 25 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,51 @@

## Overview

This is a template repository to set up foundational infrastructure for your application in AWS. It is part of a collection of interoperable [Platform templates](https://github.com/navapbc/platform).
This template sets up foundational infrastructure for applications hosted on Amazon Web Services (AWS). It belongs to a collection of interoperable [Platform templates](https://github.com/navapbc/platform).

This template includes setup for:
This template includes:

* **Team workflows** - templates for pull requests (PRs), architecture decision records (ADRs), and Makefiles.
* **Account level foundational infrastructure** - infrastructure for terraform backends, including an S3 bucket and DynamoDB table for storing and managing terraform state files.
* **Application infrastructure** - the infrastructure you need to set up a basic web app, such as a image container repository, load balancer, web service, and database.
* **CI for infra** - GitHub action that performs infra code checks, including linting, validation, and security compliance checks.
* **CD / Deployments** - infrastructure for continuous deployment, including: AWS account access for Github actions, scripts for building and publishing release artifacts, and a Github action for automated deployments from the main branch.
* **Documentation** - technical documentation for the decisions that went into all the defaults that come with the template.
* **Team workflows** - templates for pull requests (PRs), architecture decision records (ADRs), and Makefiles
* **Account level foundational infrastructure** - infrastructure for Terraform backends, including an S3 bucket and DynamoDB table for storing and managing Terraform state files
* **Application infrastructure** - the infrastructure you need to set up a basic web app, including container image repository, load balancer, web service, and database
* **Continuous integration (CI) for infrastructure** - GitHub action that performs infrastructre code checks, including linting, validation, and security compliance checks
* **Continous deployment (CD)** - infrastructure for continuous deployment, including AWS account access for Github actions, scripts for building and publishing release artifacts, and a Github action for automated deployments from the main branch
* **Documentation** - technical documentation for the decisions that went into all the defaults that come with the template

The system architecture will look like this (see [system architecture documentation](/docs/system-architecture.md) for more information):
By default, the system architecture looks like this (for more information, see [system architecture documentation](/docs/system-architecture.md)):
![System architecture](https://lucid.app/publicSegments/view/e5a36152-200d-4d95-888e-4cdbdab80d1b/image.png)

## Application Requirements

This template assumes that you have an application to deploy. See [application requirements](./template-only-docs/application-requirements.md) for more information on what is needed to use the infrastructure template. If you're using one of the [Platform application templates](https://github.com/navapbc/platform?tab=readme-ov-file#platform-templates), these requirements are already met.
Applications must meet [these requirements](/template-only-docs/application-requirements.md) to be used with this template. If you're using a [Platform application template](https://github.com/navapbc/platform?tab=readme-ov-file#platform-templates), these requirements are already met.

### Multiple Applications

You can use this template with multiple applications. By default, this template assumes your project has one application named `app`. However, it's straightforward to [add additional applications](/template-only-docs/multiple-applications.md).

## Installation

To get started using the infrastructure template on your project, run the following command in your project's directory to execute the [download and install script](https://github.com/navapbc/template-infra/tree/main/template-only-bin/download-and-install-template.sh), which clones the template repository, copies the template files to your repository, and removes any files that are only relevant to the template itself:
This template assumes that you already have an application to deploy.

To install this template to your project, run the following command in your project's root directory:

```bash
curl https://raw.githubusercontent.com/navapbc/template-infra/main/template-only-bin/download-and-install-template.sh | bash -s
```

The [download and install script](/template-only-bin/download-and-install-template.sh) clones this template repository, copies the template files to your repository, and removes files that are only relevant to the template itself.

Now you're ready to set up the various pieces of your infrastructure.

## Setup

After downloading and installing the template into your project:
After downloading and installing this template into your project, take the following steps to complete setup:

1. Follow the steps in [infra/README.md](/infra/README.md) to setup the infrastructure for your application.
1. After setting up AWS resources, you can [set up GitHub Actions workflows](./template-only-docs/set-up-ci.md).
1. After configuring GitHub Actions, you can [set up continuous deployment](./template-only-docs/set-up-cd.md).
1. At any point, [set up your team workflow](./template-only-docs/set-up-team-workflow.md).
1. Follow the "First time initialization" steps in [infra/README.md](/infra/README.md).
2. [Set up continuous integration](./template-only-docs/set-up-ci.md).
3. [Set up continuous deployment](./template-only-docs/set-up-cd.md).
4. At any point, [set up your team workflow](./template-only-docs/set-up-team-workflow.md).

## Updates

There are multiple ways to receive template updates on your project. For most updates, you can simply run the [update-template.sh](/template-only-bin/update-template.sh) script

```bash
curl https://raw.githubusercontent.com/navapbc/template-infra/main/template-only-bin/update-template.sh | bash -s
```

If the update fails the simplest option may be to re-run the installation script above and manually review the changes.

**Remember:** Make sure to read the release notes in case there are breaking changes you need to address.

### Renamed applications

If you renamed your application from `infra/app` to something else like `infra/foo`, then first rename your app back to `infra/app` before applying the updates e.g.

```bash
mv foo app
mv infra/foo infra/app
curl https://raw.githubusercontent.com/navapbc/template-infra/main/template-only-bin/update-template.sh | bash -s
mv infra/app infra/foo
mv app foo
```
This template includes a script to update your project to a newer version of the template. To update your project to a newer version of this template, follow the [update template instructions](/template-only-docs/update-template.md).
2 changes: 1 addition & 1 deletion docs/infra/database-access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The master user password is managed by Amazon RDS and Secrets Manager. Managing RDS master user passwords with Secrets Manager provides the following security benefits:

* RDS rotates database credentials regularly, without requiring application changes.
* Secrets Manager secures database credentials from human access and plain text view. The master password is not even in the terraform state file.
* Secrets Manager secures database credentials from human access and plain text view. The master password is not even in the Terraform state file.

For more information about the benefits, see [Benefits of managing master user passwords with Secrets Manager](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-secrets-manager.html#rds-secrets-manager-benefits).

Expand Down
6 changes: 3 additions & 3 deletions docs/infra/destroy-infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To destroy everything you'll need to undeploy all the infrastructure in reverse
$ terraform destroy -var-file=dev.tfvars
```

2. Then to destroy the backends, first you'll need to add `force_destroy = true` to the S3 buckets, and update the lifecycle block to set `prevent_destroy = false`. Then run `terraform apply` from within the `infra/accounts` directory. The reason we need to do this is because S3 buckets by default are protected from destruction to avoid loss of data. See [Terraform: Destroy/Replace Buckets](https://medium.com/interleap/terraform-destroy-replace-buckets-cf9d63d0029d) for a more in-depth explanation.
2. Then to destroy the backends, first you'll need to add `force_destroy = true` to the S3 buckets, and update the lifecycle block to set `prevent_destroy = false`. Then run `terraform apply` from within the `/infra/accounts` directory. The reason we need to do this is because S3 buckets by default are protected from destruction to avoid loss of data. See [Terraform: Destroy/Replace Buckets](https://medium.com/interleap/terraform-destroy-replace-buckets-cf9d63d0029d) for a more in-depth explanation.

```terraform
# infra/modules/modules/terraform-backend-s3/main.tf
Expand Down Expand Up @@ -46,13 +46,13 @@ To destroy everything you'll need to undeploy all the infrastructure in reverse
}2
```

4. Then run the following from within the `infra/accounts` directory to copy the `tfstate` back to a local `tfstate` file:
4. Then run the following from within the `/infra/accounts` directory to copy the `tfstate` back to a local `tfstate` file:

```bash
terraform init -force-copy
```

5. Finally, you can run `terraform destroy` within the `infra/accounts` directory.
5. Finally, you can run `terraform destroy` within the `/infra/accounts` directory.

```bash
terraform destroy
Expand Down
40 changes: 0 additions & 40 deletions docs/infra/https-support.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/infra/intro-to-terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `terraform destroy` command is a convenient way to destroy all remote object

⚠️ WARNING! ⚠️ This is a destructive command! As a best practice, it's recommended that you comment out resources in non-development environments rather than running this command. `terraform destroy` should only be used as a way to clean up a development environment. e.g. a developer's workspace after they are done with it.

For more information about terraform commands follow the link below:
For more information about Terraform commands follow the link below:

- [Basic CLI Features](https://www.terraform.io/cli/commands)

Expand Down
8 changes: 4 additions & 4 deletions docs/infra/making-infra-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Requirements

First read [Module Architecture](./module-architecture.md) to understand how the terraform modules are structured.
First read [Module Architecture](./module-architecture.md) to understand how the Terraform modules are structured.

## Using make targets (recommended)

Expand Down Expand Up @@ -34,9 +34,9 @@ TF_CLI_ARGS_apply='-input=false -auto-approve' make infra-update-app-service APP
TF_CLI_ARGS_apply='-var=image_tag=abcdef1' make infra-update-app-service APP_NAME=app ENVIRONMENT=dev
```

## Using terraform CLI wrapper scripts
## Using Terraform CLI wrapper scripts

An alternative to using the Makefile is to directly use the terraform wrapper scripts that the Makefile uses:
An alternative to using the Makefile is to directly use the Terraform wrapper scripts that the Makefile uses:

```bash
project-root$ ./bin/terraform-init.sh app/service dev
Expand All @@ -48,7 +48,7 @@ Look in the script files for more details on usage.

## Using Terraform CLI directly

Finally, if the wrapper scripts don't meet your needs, you can always run `terraform` directly from the root module directory. You may need to do this if you are running terraform commands other than `terraform plan` and `terraform apply`, such as `terraform import`, `terraform taint`, etc. To do this, you'll need to pass in the appropriate `tfvars` and `tfbackend` files to `terraform init` and `terraform apply`. For example, to make changes to the application's service resources in the dev environment, cd to the `infra/app/service` directory and run:
Finally, if the wrapper scripts don't meet your needs, you can always run `terraform` directly from the root module directory. You may need to do this if you are running Terraform commands other than `terraform plan` and `terraform apply`, such as `terraform import`, `terraform taint`, etc. To do this, you'll need to pass in the appropriate `.tfbackend` files to `terraform init` and `terraform apply`. For example, to make changes to the application's service resources in the dev environment, change to the `/infra/app/service` directory and run:

```bash
infra/app/service$ terraform init -backend-config=dev.s3.tfbackend
Expand Down
2 changes: 1 addition & 1 deletion docs/infra/module-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ When deciding which layer to put an infrastructure resource in, follow the follo

* **Consider policy constraints on what resources the project team is authorized to manage:** Different categories of resources may have different requirements on who is allowed to create and manage those resources. Resources that the project team are not allowed to manage directly should not be mixed with resources that the project team needs to manage directly.

* **Consider out-of-band dependencies:** Put infrastructure resources that require steps outside of terraform to be completed configured in layers that are upstream to resources that depend on those completed resources. For example, after creating a database cluster, the database schemas, roles, and privileges need to be configured before they can be used by a downstream service. Therefore database resources should be separate from the service layer so that the database can be configured fully before attempting to create the service layer resources.
* **Consider out-of-band dependencies:** Put infrastructure resources that require steps outside of Terraform to be completed configured in layers that are upstream to resources that depend on those completed resources. For example, after creating a database cluster, the database schemas, roles, and privileges need to be configured before they can be used by a downstream service. Therefore database resources should be separate from the service layer so that the database can be configured fully before attempting to create the service layer resources.

## Making changes to infrastructure

Expand Down
41 changes: 14 additions & 27 deletions docs/infra/service-command-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,44 @@ The infrastructure supports developer access to a running application's service

## Prerequisites

* You'll need to have [set up infrastructure tools](./set-up-infrastructure-tools.md), like Terraform, AWS CLI, and AWS authentication
* You'll need to have set up the [app environments](./set-up-app-env.md)
* You'll need to have [installed the Session Manager plugin for the AWS CLI](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html)
* You have [set up infrastructure tools](./set-up-infrastructure-tools.md), like Terraform, AWS CLI, and AWS authentication.
* You are [authenticated into the AWS account](./set-up-infrastructure-tools.md#authenticate-with-aws) you want to configure.
* You have [set up the application service](./set-up-app-service.md).
* You have [installed the Session Manager plugin for the AWS CLI](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html).

## Instructions

### 1. Make sure you're authenticated into the AWS account that the ECS container is running in

This takes effect in whatever account you're authenticated into. To see which account that is, run

```bash
aws sts get-caller-identity
```

To see a more human readable account alias instead of the account, run

```bash
aws iam list-account-aliases
```

### 2. Enable service execution access
### 1. Enable service execution access

Within the `app-config` directory (e.g. `infra/<APP_NAME>/app-config`), each environment has its own config file named after the environment. For example, if the application has three environments `dev`, `staging`, and `prod`, it should have corresponding `dev.tf`, `staging.tf`, and `prod.tf` files.

In the environment config file for the environment that you want to enable service access, set `enable_command_execution` to `true`.

### 3. Update the network
### 2. Update the network

To enable service execution access, the VPC requires an additional VPC endpoint. Update the network by running
The VPC requires an additional VPC endpoint. To update the network, run:

```bash
make infra-update-network NETWORK_NAME=<NETWORK_NAME>
```

`ENVIRONMENT` needs to be the name of the network that the application environment is running in.
`<NETWORK_NAME>` must be the name of the network that the application is running in.

### 4. Update the application service
### 3. Update the application service

To enable service execution access, some configuration changes need to be applied to the ECS Task Definition. Update the service by running
To update the ECS Task Definition to allow command execution, run:

```bash
make infra-update-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT>
```

`APP_NAME` needs to be the name of the application folder within the `infra` folder.
`<APP_NAME>` must be the name of the application folder within the `/infra` folder.

`ENVIRONMENT` needs to be the name of the environment to update.
`<ENVIRONMENT>` must be the name of the environment to update.

### 5. Execute commands
### 4. Execute commands

To create an interactive shell, run
To create an interactive shell, run:

```bash
aws ecs execute-command --cluster <CLUSTER_NAME> \
Expand Down
Loading
Loading