|
| 1 | +# Understanding the infra setup |
| 2 | + |
| 3 | +The infrastructure code is modularized and a bit abstracted for greater re-use. |
| 4 | +It can be overwhelming at first to fit how it's all connected in your head. The |
| 5 | +[/infra/README.md](/infra/README.md) doc has a lot of good overview info. This |
| 6 | +doc aims to provide a little better connective tissue between the architectural |
| 7 | +concepts and the concrete things you'll interact with. |
| 8 | + |
| 9 | +If you want deeper background rational for the current setup: |
| 10 | + |
| 11 | +- [/docs/decisions/infra/2023-05-09-separate-terraform-backend-configs-into-separate-config-files.md](/docs/decisions/infra/2023-05-09-separate-terraform-backend-configs-into-separate-config-files.md) |
| 12 | +- [/docs/decisions/infra/2023-09-07-consolidate-infra-config-from-tfvars-files-into-config-module.md](/docs/decisions/infra/2023-09-07-consolidate-infra-config-from-tfvars-files-into-config-module.md) |
| 13 | +- [/docs/decisions/infra/2023-09-11-separate-app-infrastructure-into-layers.md](/docs/decisions/infra/2023-09-11-separate-app-infrastructure-into-layers.md) |
| 14 | + |
| 15 | +TL;DR for the why: group resources with a similar lifecycle and scope, reduce |
| 16 | +code duplication and drift between environments, help streamline receiving |
| 17 | +updates from upstream |
| 18 | + |
| 19 | +It's important to understand most of the actual resource code [lives in |
| 20 | +re-usable modules under `/infra/modules/`](/docs/infra/module-architecture.md). |
| 21 | +Everything else largely exists to call that re-usable code with the correct |
| 22 | +parameters at the correct time, [in a well structured |
| 23 | +way](/docs/infra/module-dependencies.md). That "everything else" can be broken |
| 24 | +down into three high-level "slices" (some with further internal divisions). |
| 25 | + |
| 26 | +One last bit of exposition, as yet more new terminology has been introduced with |
| 27 | +"slice". If you've read other documentation already you'll have likely seen |
| 28 | +references to infrastructure "layers", but there are some conceptual |
| 29 | +psuedo-layers that for clarity that this document calls a "slice". Some slices |
| 30 | +directly correspond to a layer, other slices correspond to multiple layers. In |
| 31 | +summary: |
| 32 | + |
| 33 | +- Slice: Conceptual or organizational grouping, it does not directly correspond |
| 34 | + to infrastructure resources itself, though may be expressed in the file |
| 35 | + structure. |
| 36 | +- Layer: Corresponds to root modules and actual resources. |
| 37 | + |
| 38 | + |
| 40 | + |
| 41 | +([visualization source](https://lucid.app/lucidchart/19108167-39ee-48fb-b9ac-85465ce4403a/edit), note there are multiple image layers that can be toggled) |
| 42 | + |
| 43 | +Specifics are shown in the above visualization and will be given in the sections |
| 44 | +to follow, but _in general_ there are make targets to interact with different |
| 45 | +bits of this, following the pattern of: |
| 46 | + |
| 47 | +``` |
| 48 | +make infra-<action>-<layer> |
| 49 | +``` |
| 50 | + |
| 51 | +## Account Layer/Slice |
| 52 | + |
| 53 | +After initial set up of an account, you'll likely rarely need to deal with this. |
| 54 | + |
| 55 | +The layer's source code is under `/infra/accounts/`. And primary config at |
| 56 | +`/infra/project-config/main.tf`. |
| 57 | + |
| 58 | +For each account in your project, there will be an `<account name>.<account |
| 59 | +id>.<terraform backend type>.tfbackend` file under `/infra/accounts/`. |
| 60 | + |
| 61 | +Common make targets to interact with it: |
| 62 | + |
| 63 | +- `make infra-set-up-account ACCOUNT_NAME=<ACCOUNT_NAME>` |
| 64 | +- `make infra-update[-current]-account [ACCOUNT_NAME=<ACCOUNT_NAME>]` |
| 65 | + |
| 66 | +Set up docs: |
| 67 | +[/docs/infra/set-up-aws-account.md](/docs/infra/set-up-aws-account.md) |
| 68 | + |
| 69 | +## Network Layer/Slice |
| 70 | + |
| 71 | +After initial set up, you'll less frequently need to deal with this, only when |
| 72 | +there are network/cross-application resource changes. |
| 73 | + |
| 74 | +The layer's source code is under `/infra/networks/`. And primary config at |
| 75 | +`/infra/project-config/networks.tf`. |
| 76 | + |
| 77 | +For each network in your project, there will be an `<network name>.<terraform |
| 78 | +backend type>.tfbackend` file under `/infra/networks/`. |
| 79 | + |
| 80 | +Common make targets to interact with it: |
| 81 | + |
| 82 | +- `make infra-configure-network NETWORK_NAME=<NETWORK_NAME>` |
| 83 | +- `make infra-update-network NETWORK_NAME=<NETWORK_NAME>` |
| 84 | + |
| 85 | +Set up docs: [/docs/infra/set-up-network.md](/docs/infra/set-up-network.md) |
| 86 | + |
| 87 | +## App Slice |
| 88 | + |
| 89 | +*This is where you'll spend most of your time as a developer.* |
| 90 | + |
| 91 | +This slice is composed of a layer, a build repository, and another slice, the |
| 92 | +application environment. |
| 93 | + |
| 94 | +- `build-repository` layer for AWS, holds resources for the container build of |
| 95 | + the application code. After initial setup, you probably won't deal with this. |
| 96 | +- Application Environments |
| 97 | + |
| 98 | +Of these, `build-repository` is they only one that exists at the bare app slice, |
| 99 | +the others exist in an environment, discussed next. This is because the |
| 100 | +applications build repo is shared across all environments and accounts that run |
| 101 | +the application. |
| 102 | + |
| 103 | +The slice's "source code" is under `/infra/<APP_NAME>/`. And primary config at |
| 104 | +`/infra/<APP_NAME>/app-config/main.tf`. |
| 105 | + |
| 106 | +### Build repository layer |
| 107 | + |
| 108 | +The layer's source code is under `/infra/<APP_NAME>/build-repository/`. And |
| 109 | +primary config at `/infra/<APP_NAME>/app-config/build_repository.tf`. |
| 110 | + |
| 111 | +Common make targets to interact with it: |
| 112 | + |
| 113 | +- `infra-configure-app-build-repository APP_NAME=<APP_NAME>` |
| 114 | +- `infra-update-app-build-repository APP_NAME=<APP_NAME>` |
| 115 | + |
| 116 | +Set up docs: [/docs/infra/set-up-build-repository.md](/docs/infra/set-up-build-repository.md) |
| 117 | + |
| 118 | +Note, this layer does not exist in the Azure template. |
| 119 | + |
| 120 | +### Environment Slice |
| 121 | + |
| 122 | +The environment slice encompasses a couple layers: |
| 123 | + |
| 124 | +- `service` for the application code, storage, monitoring, etc. **This is likely |
| 125 | + where you'll be doing the most work.** |
| 126 | +- `database` for the application's database |
| 127 | + |
| 128 | +The slice's "source code" is under `/infra/<APP_NAME>/(service,database)/`. And |
| 129 | +primary config at `/infra/<APP_NAME>/app-config/<ENV_NAME>.tf`. |
| 130 | + |
| 131 | +#### Service layer |
| 132 | + |
| 133 | +The layer's source code is under `/infra/<APP_NAME>/service/`. And primary config |
| 134 | +at `/infra/<APP_NAME>/app-config/env-config/*.tf`. |
| 135 | + |
| 136 | +For each environment for the app, there will be an `<ENV_NAME>.<terraform |
| 137 | +backend type>.tfbackend` file under `/infra/<APP_NAME>/service/`. |
| 138 | + |
| 139 | +Common make targets to interact with it: |
| 140 | + |
| 141 | +- `infra-configure-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 142 | +- `infra-update-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 143 | + |
| 144 | +Set up docs: [/docs/infra/set-up-app-env.md](/docs/infra/set-up-app-env.md) |
| 145 | + |
| 146 | +#### Database layer |
| 147 | + |
| 148 | +The layer's source code is under `/infra/<APP_NAME>/database/`. And primary |
| 149 | +config at `/infra/<APP_NAME>/app-config/env-config/database.tf`. |
| 150 | + |
| 151 | +The resources in this layer may or may not exist for a given app, generally |
| 152 | +controlled by the `has_database` setting in the app slice or app environment |
| 153 | +slice config. |
| 154 | + |
| 155 | +For each environment for the app (that has a database), there will be an |
| 156 | +`<ENV_NAME>.<terraform backend type>.tfbackend` file under |
| 157 | +`/infra/<APP_NAME>/database/`. |
| 158 | + |
| 159 | +Common make targets to interact with it: |
| 160 | + |
| 161 | +- `infra-configure-app-database APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 162 | +- `infra-update-app-database APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 163 | +- `infra-update-app-database-roles APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 164 | +- `infra-check-app-database-roles APP_NAME=<APP_NAME> ENVIRONMENT=<ENV_NAME>` |
| 165 | + |
| 166 | +Set up docs: [/docs/infra/set-up-database.md](/docs/infra/set-up-database.md) |
0 commit comments