Deploy Infrastructure and Configure SNS
Overview
In this part, we will learn how we can use Terraform to provision infrastructure using Terraform CLI.
- Now, open the folder that contains the Terraform source code using Visual Studio Code.

- You need to open the terminal in Visual Studio Code. Click on View and choose Terminal.

- After opening the terminal, you will notice that we are in the Deploy-Infrastructure folder.

- Let’s navigate to the terraform folder by typing the following command in the terminal. After you run the command, you are in the terraform folder right now.
cd .\terraform\

- Let’s begin by initializing your Terraform workspace. Running the following command in the terminal.
terraform init

- If you successfully run the command, you will see some output in the terminal as shown below. Addtionally, some folders and files will appear in the terraform folder. Terraform also creates a lock file named .terraform.lock.hcl which specifies the exact provider versions used, so that you can control when you want to update the providers used for your project.
Initializing the backend...
Initializing modules...
- Compute in ..\modules\Compute
- LoadBalancing in ..\modules\LoadBalancing
- Networking in ..\modules\Networking
Initializing provider plugins...
- Finding hashicorp/aws versions matching "5.43.0"...
- Finding latest version of hashicorp/http...
- Installing hashicorp/aws v5.43.0...
- Installed hashicorp/aws v5.43.0 (signed by HashiCorp)
- Installing hashicorp/http v3.4.2...
- Installed hashicorp/http v3.4.2 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

- Now, we need to validate our configuration. Use the following command in the terminal to do so.
terraform validate

- You will see the output like Success! The configuration is valid. in the terminal.

- Apply the configuration now with the terraform apply command. Terraform will print output similar to what is shown below.

- After you run the command, you will see the output in the terminal like this.

- In the end, you will see a question like “Enter a Value”. Enter yes so terraform can provision infrastructure.

- You will see a line Apply complete! Resources: 16 added, 0 changed, 0 destroyed.

- Remember to copy the value of alb_dns in the terminal. Let’s go to view each resource that Terraform has created.
Content
- Networking resources
- Compute resources
- Load Balancing resources
- Configure SNS and Auto Scaling Group