Skip to content

Latest commit

 

History

History
152 lines (101 loc) · 3.3 KB

README.md

File metadata and controls

152 lines (101 loc) · 3.3 KB

Configuration of Infrastructure with VPC, RDS, EC2

Requirements

  • Terraform CLI
  • AWS CLI

Note: you should use WSL.

Note

  • If you want to change something, you should look into deploy-infrastructure/terraform.tf. All of variables are setup in there. Pay attention to these local variables
locals {
  region = "ap-southeast-2"
  author = "FCJ-DNTU"
  network_root_name = "FCJ-Lab"
  compute_root_name = "FCJ-Lab"
  vpc_cidr = "10.0.0.0/16"
  db_username = "admin"
  db_password = "letmein12345"
  db_name = "fcjresbar"
  key_name = "general-use"
  service_discovery_namespace_name = "fcjresbar.internal"
  service_discovery_service_name = "backend"
}
  • You must have a user that is granted enough permissions.

Steps

1 - Deploy the infrastructure

Change current working directiry to deploy-infrastructure, you need to link modules in configuration with this command

terraform get

Result Logs:

- compute in modules/compute
- infrastructure in modules/infrastructure
- rds in modules/rds
- security in modules/security

Init terraform

terraform init

Result Logs:

Initializing the backend...
Initializing modules...
Initializing provider plugins...
...

Terraform has been successfully initialized!

...

Now we have to validate our configuration and plan it

terraform plan

Then tell Terraform apply the plan to deploy our infrastructure (Terraform will ask you, just say "yes").

terraform apply

Result:

2024-10-07_221831

2 - Insert Data

Next, we'll need to insert data into our Database. First, you need to get EC2 Public IPv4 in Management Console or in Terraform Output Deployment, then upload insert-data directory to EC2 Instance.

chmod 400 key/key-name.pem
scp -i key/key-name.pem -r insert-data ubuntu@"ec2-public-ipv4":/home/ubuntu

2024-10-07_222250

Connect to this EC2 Instance, check result and permission for script execution

chmod 700 deploy.sh

2024-10-07_222344

Replace RDS Endpoint in deploy.sh

2024-10-07_222801

Now, you should run deploy.sh

2024-10-07_222801

2024-10-07_223238

3 - Test result

Connect to MySQL Server in RDS

mysql -h "you-rds-endpoint" -u admin -p

2024-10-07_223518

Perform some query

USE fcjresbar;
SELECT * FROM Clients;
SELECT * FROM Tables;

2024-10-07_223558

4 - Clean up resources

Change directory to deploy-infrastructure

cd deploy-infrastructure/

Destroy resources (Terraform will ask you, just say "yes").

terraform destroy

2024-10-07_225053