Skip to content

All of the setting up of workshops' infrastructure, small projects will go here

Notifications You must be signed in to change notification settings

FCJ-DNTU/gsp-infra-000006-autoscaling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deployment Configuration of Workshop 000006

In this section, we need to deploy

  • Infrastructure
  • Application (Server)

Requirements

  • Terraform CLI
  • Docker
  • Linux (in VM, WSL or Configure a EC2 Instance)

Note: you should configure another key-pair in aws_instance block. And configure ASG later, so we you destroy the infrastructure, please make you clean up ASG first.

Steps

1 - Deploy the infrastructure

First, you need to make a plan for deployment

terraform init

Result Logs:

Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Installing hashicorp/aws v5.68.0...
- Installed hashicorp/aws v5.68.0 (signed by HashiCorp)
...

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 apply

Result: 2024-10-04_140055

2 - Deploy application

Before we go to these steps, you should do something:

  • Copy your SSH private key (of EC2) to key directory.
  • Copy all of Terraform outputs in the previous test.

Change directory to 000006-auto-scaling, you need to change the environment variable in deploy.sh script first

2024-10-04_140139

Copy the content of deploy-application to the EC2 which is created.

chmod 400 key/key-name.pem
scp -i key/key-name.pem -r deploy-application ec2-user@"ec2-public-ipv4":/home/ec2-user

Result

2024-10-04_141914

Connect SSH to the EC2 Instance

2024-10-04_135821 2024-10-04_135838 2024-10-04_141944

Run the deploy.sh script

bash deploy.sh

Note: some packages require you allowing, so you should pay attention for them.

You'll be asked for DB Password, just type it and the deployment will be continute. PLEASE, TYPE CAREFULLY!!!

2024-10-04_145649

In the case you type the password incorrectly, you can use the script bellow.

mysql -h $DB_HOST -u $DB_USER $DB_NAME -p < init.sql

Note: replace values for these Environment Variables.

After the deployment is done, check the result

2024-10-04_143854

3 - Deploy Auto Scaling Group

First, you should copy values public_sg_id, target_group_arn, server_id and subnet ids in Infrastructure Output. Then go to deploy-asg/main.tf and replace corresponding values.

Change directory to deploy-asg, and use terraform to deploy ASG like the 2 step.

terraform init

Now we have to validate our configuration and plan it

terraform plan

Then tell Terraform apply the plan to deploy our infrastructure

terraform apply

3.1 - Create launch template

3.2 - Create ASG

4 - View result

Go back to Load Balancer console, enter the LB which is created before. Go to tab Resource map - new and check

image

You can see the target is health. Now copy public dns of Load Balancer, paste to address bar of browser, hit enter and see the result

image

5 - Clean up resources

Change directory to deploy-asg

terraform destroy

Result Logs

aws_autoscaling_group.asg: Destruction complete after 6m34s
aws_launch_template.my_launch_template: Destroying... [id=lt-06f65e37f1e2d88a3]
aws_launch_template.my_launch_template: Destruction complete after 0s
aws_ami_from_instance.instance_ami: Destroying... [id=ami-0b8965a8bb3b921da]
aws_ami_from_instance.instance_ami: Destruction complete after 5s

Destroy complete! Resources: 3 destroyed.

Change directory to deploy-infrastructure

terraform destroy

Result Logs

aws_subnet.private_subnet_2: Destruction complete after 0s
aws_subnet.private_subnet_3: Destruction complete after 0s
aws_security_group.db_sg: Destruction complete after 0s
aws_vpc.aslab: Destroying... [id=vpc-0e9713682d8f3d6ae]
aws_vpc.aslab: Destruction complete after 1s

Destroy complete! Resources: 32 destroyed.

About

All of the setting up of workshops' infrastructure, small projects will go here

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published