Skip to content

Commit 9ffed51

Browse files
chore: Update RDS instance connection retrieval and output in example-rds-instance.tf
1 parent 3cb6393 commit 9ffed51

File tree

19 files changed

+543
-116
lines changed

19 files changed

+543
-116
lines changed

.github/workflows/tf-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Render terraform docs inside modules
2525
uses: terraform-docs/[email protected]
2626
with:
27-
working-dir: modules/amplify-app,modules/bastion,modules/mongodb,modules/rds,modules/rds-aurora,modules/vpc,live/terraform-backend,live/common-infra
27+
working-dir: modules/amplify-app,modules/bastion,modules/mongodb,modules/rds,modules/rds-aurora,modules/vpc,live/terraform-backend,live/core-networking,live/common-infra,live/terraform-backend
2828
output-file: docs/MODULE.md
2929
output-method: replace
3030
git-push: "true"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ It is recommended to create a separate directory for each domain that you want t
7272

7373
| Module | Description |
7474
| :-------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- |
75-
| [Common Infrastructure](./live/common-infra/README.md) | Terraform module for managing common infrastructure components such as VPC, subnets, security groups, and RDS instances. |
7675
| [Terraform Backend Configuration](./live/terraform-backend/README.md) | Terraform module for setting up the S3 backend. |
76+
| [Core Networking](./live/core-networking/README.md) | Terraform module for managing core networking components such as VPC, subnets, and security groups. |
77+
| [Common Infrastructure](./live/common-infra/README.md) | Terraform module for managing common infrastructure components such as RDS instances, S3 buckets, and IAM roles. |
7778

7879
## Terraform Modules
7980

live/common-infra/README.md

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
- ✨ Comprehensive Root Terraform module for quick deployment.
88
- 🗄️ Configured to use an external S3 bucket for Terraform state management with a DynamoDB table for state locking.
9-
- 🌐 Highly available VPC setup with public and private subnets across multiple availability zones.
10-
- 🔒 Configured security groups for bastion hosts and databases.
11-
- 🔑 Bastion host setup for secure access to internal services.
129
- 🐘 RDS Postgres setup for reliable database services.
1310
- 🔒 Utilization of AWS Secrets Manager for secure storage of database credentials.
1411
- 🔧 Use of SSM Parameter Store for managing network and service parameters.
@@ -91,74 +88,7 @@
9188
9289
After successfully deploying the infrastructure, follow these steps to test the deployment and ensure everything is working as expected:
9390
94-
### Accessing the Parameter Store
95-
96-
Retrieve stored values, such as the VPC ID, using the AWS Parameter Store:
97-
98-
```bash
99-
# Retrieve the parameter value from the AWS Parameter Store
100-
vpc_id_parameter_name=$(terraform output -json | jq -r '.ssm_parameter_vpc_id.value')
101-
vpc_id=$(aws ssm get-parameter --name "$vpc_id_parameter_name" --query 'Parameter.Value' --output text)
102-
103-
# Print the value
104-
echo "VPC ID: $vpc_id"
105-
```
106-
107-
### Connecting to the Bastion Host
108-
109-
To establish a secure connection with the bastion host, follow these steps:
110-
111-
#### Obtain Required Information
112-
113-
First, you need to gather some essential information:
114-
115-
- Bastion SSH Parameter Name
116-
- Bastion Instance ID
117-
118-
You can retrieve these values using Terraform:
119-
120-
```bash
121-
bastion_ssh_parameter_name=$(terraform output -json | jq -r '.ssm_parameter_bastion_ssh_key.value')
122-
bastion_instance_id=$(terraform output -json | jq -r '.bastion_instance_id.value')
123-
```
124-
125-
#### Generate .pem file with the ssh key
126-
127-
```bash
128-
aws ssm get-parameter --name "$bastion_ssh_parameter_name" --with-decryption --query 'Parameter.Value' --output text > /tmp/ssh_key.pem
129-
chmod 400 /tmp/ssh_key.pem
130-
```
131-
132-
#### Retrieve bastion's public IP
133-
134-
```bash
135-
bastion_public_ip=$(aws ec2 describe-instances --instance-ids "$bastion_instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress' --output text | tr '.' '-')
136-
137-
# Print the value
138-
echo "Bastion IP: $bastion_public_ip"
139-
```
140-
141-
#### Connect to Bastion Host
142-
143-
```bash
144-
ssh -i "/tmp/ssh_key.pem" ubuntu@ec2-"$bastion_public_ip".compute.amazonaws.com
145-
```
146-
147-
Ensure that you can access the database from the bastion host and verify that Docker is functioning correctly.
148-
149-
#### Testing Docker and Internet Access
150-
151-
To verify internet access and Docker functionality, execute the following commands:
152-
153-
```bash
154-
# Test Internet Access
155-
ping -c 3 google.com
156-
157-
# Test Docker
158-
docker run -it --rm hello-world
159-
```
160-
161-
#### Connecting to the Database
91+
### Connecting to the Database
16292
16393
To connect to the database from the bastion host, retrieve the connection information from AWS Secrets Manager. Follow these steps:
16494

live/common-infra/configs/prod.tfvars

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ tags = {
99
"Environment" = "prod"
1010
}
1111

12-
# AWS settings
12+
# Core Networking settings
1313

14-
vpc_cidr_block = "10.0.0.0/16"
15-
enable_bastion = false
14+
core_networking_ssm_parameter_prefix = "/nan-core-networking-prod"
1615

1716
# RDS Database settings
1817

live/common-infra/configs/staging.tfvars

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ tags = {
99
"Environment" = "prod"
1010
}
1111

12-
# AWS settings
12+
# Core Networking settings
1313

14-
vpc_cidr_block = "10.0.0.0/16"
15-
enable_bastion = false
14+
core_networking_ssm_parameter_prefix = "/nan-core-networking-staging"
1615

1716
# RDS Database settings
1817

live/common-infra/vpc.tf

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
1-
variable "vpc_cidr_block" {
2-
description = "CIDR block for the VPC"
1+
variable "core_networking_ssm_parameter_prefix" {
2+
description = "The SSM parameter prefix for core networking parameters"
33
type = string
4-
default = "10.0.0.0/16"
54
}
65

7-
module "vpc" {
8-
source = "../../modules/vpc"
9-
name = module.label.id
10-
vpc_cidr_block = var.vpc_cidr_block
11-
tags = module.label.tags
12-
enable_nat_gateway = true
13-
single_nat_gateway = true
6+
data "aws_ssm_parameter" "vpc_id" {
7+
name = "${var.core_networking_ssm_parameter_prefix}/vpc_id"
148
}
159

16-
output "ssm_parameter_vpc_id" {
17-
description = "name of the ssm parameter for the vpc id"
18-
value = module.vpc.ssm_parameter_vpc_id
10+
data "aws_ssm_parameter" "app_subnets" {
11+
name = "${var.core_networking_ssm_parameter_prefix}/app_subnets"
1912
}
2013

21-
output "ssm_parameter_public_subnets" {
22-
description = "name of the ssm parameter for the public subnets"
23-
value = module.vpc.ssm_parameter_public_subnets
24-
}
25-
26-
output "ssm_parameter_private_subnets" {
27-
description = "name of the ssm parameter for the private subnets"
28-
value = module.vpc.ssm_parameter_private_subnets
29-
}
30-
31-
output "ssm_parameter_database_subnets" {
32-
description = "name of the ssm parameter for the database subnets"
33-
value = module.vpc.ssm_parameter_database_subnets
34-
}
35-
36-
output "ssm_parameter_app_subnets" {
37-
description = "name of the ssm parameter for the app subnets"
38-
value = module.vpc.ssm_parameter_app_subnets
39-
}
40-
41-
output "ssm_parameter_app_security_group" {
42-
description = "name of the ssm parameter for the app security group"
43-
value = module.vpc.ssm_parameter_app_security_group
14+
data "aws_ssm_parameter" "database_subnets" {
15+
name = "${var.core_networking_ssm_parameter_prefix}/database_subnets"
4416
}

live/core-networking/.terraform.lock.hcl

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)