Setting Up an Apache Web Server on AWS using Terraform Provisioners

Infra as Code (IaC) | AWS Hero | Teacher | Mentor | Youtuber | -> Way to Cloud & MLOPS
Search for a command to run...

Infra as Code (IaC) | AWS Hero | Teacher | Mentor | Youtuber | -> Way to Cloud & MLOPS
No comments yet. Be the first to comment.
API (Application Programming Interface) security is critical for protecting sensitive data and maintaining the integrity of systems and applications. APIs are used to connect different systems and applications, and as a result, they can provide a gat...

Well after months of deep slumber, away from social media networks, I had to return to Pune and adapt to hybrid working. I was browsing through meetup.com and was intrigued by one event from AWS user group Pune. It is AWS Reinvent 2022 -Recap on 21st...

Episode 2

Simplify Access Control and Enhance Transparency Over Your ML Projects

Episode 1

In this hands-on lab, we'll be using a Terraform provisioner to custom bootstrap a VM in AWS and install a webserver on it, and then test that the webserver is working as expected.
Let us log in to the lab server using our credentials.
In a web browser, log in to the AWS Management Console using your credentials.
Clone the required code from the provided repository:
git clone https://github.com/samtechlab/content-hashicorp-certified-terraform-associate-foundations.git
Switch to the directory where the code is located:
cd content-hashicorp-certified-terraform-associate-foundations/section3-hol2/
List the files in the directory:
ls
The files in the directory should include main.tf, README.md, and setup.tf.
View the contents of the main.tf file using the cat command:
cat main.tf
Examine the code in the resource block and note the following:
Note: All of these resources are actually being created via the setup.tf file, which you can view if desired.
Examine the code in the provisioner block and note the following:
Initialize the Terraform working directory, and download the required providers:
terraform init
Validate the code to look for any errors in syntax, parameters, or attributes within Terraform resources that may prevent it from deploying correctly:
terraform validate
You should receive a notification that the configuration is valid.
Review the actions that will be performed when you deploy the Terraform code:
terraform plan
In this case, it will create 7 resources as configured in the Terraform code.
Deploy the code:
terraform apply
When prompted, type yes, and press Enter.
As the code is being deployed, you will notice that the Terraform provisioner tries to connect to the EC2 instance, and once that connection is established, it will run the bootstrapping that was configured in the provisioner block against the instance.
When complete, it will output the public IP for the Apache webserver as the Webserver-Public-IP value.
Copy the IP address, paste it in a new browser window or tab, and press Enter.
Verify that the web page displays as My Test Website With Help From Terraform Provisioner, validating that the provisioner within your code worked as intended. The commands configured in the provisioner code were issued and executed successfully on the EC2 instance that was created.
Congratulations — you've completed this hands-on lab!