- Terraform CLI
- AWS CLI
Note: you should use WSL.
- 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.
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:
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
Connect to this EC2 Instance, check result and permission for script execution
chmod 700 deploy.sh
Replace RDS Endpoint in deploy.sh
Now, you should run deploy.sh
Connect to MySQL Server in RDS
mysql -h "you-rds-endpoint" -u admin -p
Perform some query
USE fcjresbar;
SELECT * FROM Clients;
SELECT * FROM Tables;
Change directory to deploy-infrastructure
cd deploy-infrastructure/
Destroy resources (Terraform will ask you, just say "yes").
terraform destroy