terraform-aws-pre-base/README.md

51 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2024-05-17 23:46:50 +06:00
# Terraform AWS Pre-base Infrastructure
2023-11-06 17:16:36 +06:00
## Intro
This project deploys the basic resources necessary for running multi-user Terraform deployments on an AWS account.
- an s3 bucket for storing terraform states
- a dynamodb table for maintaining terraform locks
- an admin user intended for use in other IaC projects
- a kms key intended for securing other IaC project secrets
- a parameter store tree to keep outputs of this project for reference
This configuration is intended to be manually executed once at the beginning by the root user.
| ⚠️ | Re-deploying this project again after running other AWS IaC projects can be <u>*extremely destructive*</u>. |
|-|-|
## Usage
2024-05-17 23:46:50 +06:00
1. Install [terraform](https://terraform.io). The required version is stated in [`terraform.meta.tf`](./terraform.meta.tf). You can also use [tfenv](https://github.com/tofuutils/tenv) to automatically get a suitable version.
2023-11-06 17:16:36 +06:00
2024-05-17 23:46:50 +06:00
2. Insert backend config values in `terraform.backend.tfvars`. See [`terraform.backend.remote.tfvars.sample`](./terraform.backend.remote.tfvars.sample) for example, or configure your preferred backend.
3. *(optional)* Login to terraform cloud to use the remote backend:
```bash
terraform login
```
4. Install terraform dependencies and initiate the backend:
2023-11-06 17:16:36 +06:00
```bash
2024-05-17 23:46:50 +06:00
terraform init -backend-config=terraform.backend.tfvars
2023-11-06 17:16:36 +06:00
```
2024-05-17 23:46:50 +06:00
5. Insert deployment-specific values in `terraform.tfvars`. See [`terraform.tfvars.sample`](./terraform.tfvars.sample) for example.
2023-11-06 17:16:36 +06:00
2024-05-17 23:46:50 +06:00
6. Then execute as:
2023-11-06 17:16:36 +06:00
```bash
2024-05-17 23:46:50 +06:00
terraform apply -var-file=terraform.tfvars
2023-11-06 17:16:36 +06:00
```
## Notes
2024-05-17 23:46:50 +06:00
- ⚠️ **This project's state file should not be saved in the same AWS account where it is being deployed.**
- The terraform state is not saved in s3, because it is assumed that no s3 bucket for terraform states exists yet. Instead the [terraform cloud](https://app.terraform.io/) remote backend is used. You may need to setup an account there. Or use local or your preferred backend. You should ensure security of the state file.
2023-11-06 17:16:36 +06:00
2024-05-17 23:46:50 +06:00
- Generated outputs are also saved in a parameter store tree for future reference.