Skip to content

Commit 079e02e

Browse files
chore: Update Terraform versions and required providers in modules
1 parent 1d3030b commit 079e02e

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

live/common-infra/README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,64 @@
1212

1313
## Prerequisites
1414

15+
- [Direnv](https://direnv.net/) for loading environment variables.
1516
- [Terraform](https://www.terraform.io/downloads.html) for infrastructure provisioning.
1617
- [TFswitch](https://tfswitch.warrensbox.com/) to switch between Terraform versions easily.
1718

1819
## Setup
1920

20-
1. **Set Terraform Version:**
21+
1. **Change Directory:**
22+
23+
Navigate to the directory containing the Terraform configuration:
24+
25+
```sh
26+
cd live/common-infra
27+
```
28+
29+
2. **Create .envrc file:**
30+
31+
Create a new `.envrc` file in this directory by copying the `.envrc.example` file:
32+
33+
```sh
34+
cp .envrc.example .envrc
35+
```
36+
37+
Then, update the `.envrc` file with the values for your environment!
38+
39+
3. **Load Environment Variables:**
40+
41+
Load the environment variables using `direnv`:
42+
43+
```sh
44+
direnv allow
45+
```
46+
47+
4. **Set Terraform Version:**
2148

2249
Ensure you are using the correct Terraform version:
2350

2451
```sh
2552
tfswitch
2653
```
2754

28-
2. **Initialize Terraform:**
55+
5. **Initialize Terraform:**
2956

3057
Initialize the working directory with the required providers and modules:
3158

3259
```sh
33-
terraform init -backend-config="./configs/prod-backend.tfvars"
60+
terraform init -backend-config="./configs/${ENVIRONMENT}-backend.tfvars"
3461
```
3562

36-
3. **Workspace Management:**
63+
6. **Workspace Management:**
3764

3865
Select or create a new workspace tailored to your deployment environment:
3966

4067
```sh
4168
# Select an existing workspace
42-
terraform workspace select prod
69+
terraform workspace select "${TF_WORKSPACE}"
4370

44-
# Create a new workspace if it doesn't exist
45-
# and select it
46-
terraform workspace new prod
47-
terraform workspace select prod
71+
# Create a new workspace if it doesn't exist and select it
72+
terraform workspace new "${TF_WORKSPACE}"
4873
```
4974
5075
## Deploy
@@ -56,15 +81,15 @@
5681
Review and verify the deployment plan:
5782
5883
```sh
59-
terraform plan -var-file ./configs/prod.tfvars -out prod.tfplan
84+
terraform plan -var-file "./configs/${ENVIRONMENT}.tfvars" -out "${ENVIRONMENT}.tfplan"
6085
```
6186
6287
2. **Execute the Plan:**
6388
6489
Apply the planned configuration to provision the infrastructure:
6590
6691
```sh
67-
terraform apply "prod.tfplan"
92+
terraform apply "${ENVIRONMENT}.tfplan"
6893
```
6994
7095
## Post Deployment Steps
@@ -139,12 +164,10 @@ These steps will help you verify the successful setup of the database and ensure
139164
140165
## Destroy
141166
142-
💣 **NOTE:** In this example, we are using the `prod` environment and the `us-west-2` region. Modify these values according to your environment and region.
143-
144167
To destroy the infrastructure, run the following command:
145168
146169
```sh
147-
terraform destroy -var-file ./configs/prod.tfvars
170+
terraform destroy -var-file "./configs/${ENVIRONMENT}.tfvars"
148171
```
149172
150173
## Module Documentation

live/common-infra/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ provider "aws" {
55
tags = merge(module.label.tags, {
66
ManagedBy = "terraform"
77
Owner = "NaNLABS"
8+
Project = "[Project Name]"
89
Repository = "https://github.com/nanlabs/terraform-aws-starter"
910
RepositoryPath = "live/common-infra"
1011
})

live/common-infra/vpc.tf

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,43 @@ variable "core_networking_ssm_parameter_prefix" {
33
type = string
44
}
55

6+
variable "bastion_security_group_name" {
7+
description = "The name of the bastion security group"
8+
type = string
9+
}
10+
11+
locals {
12+
vpc_id = data.aws_ssm_parameter.vpc_id.value
13+
private_subnets = split(",", data.aws_ssm_parameter.private_subnets.value)
14+
public_subnets = split(",", data.aws_ssm_parameter.public_subnets.value)
15+
}
16+
617
data "aws_ssm_parameter" "vpc_id" {
718
name = "${var.core_networking_ssm_parameter_prefix}/vpc_id"
819
}
920

10-
data "aws_ssm_parameter" "app_subnets" {
11-
name = "${var.core_networking_ssm_parameter_prefix}/app_subnets"
21+
data "aws_ssm_parameter" "private_subnets" {
22+
name = "${var.core_networking_ssm_parameter_prefix}/private_subnets"
23+
}
24+
25+
data "aws_ssm_parameter" "public_subnets" {
26+
name = "${var.core_networking_ssm_parameter_prefix}/public_subnets"
27+
}
28+
29+
data "aws_security_group" "default" {
30+
vpc_id = local.vpc_id
31+
32+
filter {
33+
name = "group-name"
34+
values = ["default"]
35+
}
1236
}
1337

14-
data "aws_ssm_parameter" "database_subnets" {
15-
name = "${var.core_networking_ssm_parameter_prefix}/database_subnets"
38+
data "aws_vpc" "vpc" {
39+
id = local.vpc_id
1640
}
1741

18-
data "aws_ssm_parameter" "database_subnet_group" {
19-
name = "${var.core_networking_ssm_parameter_prefix}/database_subnet_group"
42+
data "aws_security_group" "bastion_security_group" {
43+
name = var.bastion_security_group_name
44+
vpc_id = local.vpc_id
2045
}

0 commit comments

Comments
 (0)