AWS Hands-On Lab -> Terraform Set Up Apache Web Server
AWS Learning Path for Cloud and DevOps Engineers
Table of contents
📝Introduction
This post demonstrates using a Terraform provisioner to custom bootstrap a VM in AWS, install a webserver on it, and then test that the webserver is working as expected.
📝Log in to the AWS Management Console
Using your credentials, make sure you're using the right Region. In my case, I chose us-east-1
.
Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.
You can use link1 and link2 for it.
📝GitHub repository
Go to the GitHub repo to fork the files used in this Lab on this link.
📝Configure the AWS CLI and generate an RSA key
Configure your AWS CLI:
aws configure
When prompted for your AWS Access Key ID, copy and paste in the Access Key created previously by you.
When prompted for your AWS Secret Access Key, copy and paste in the Secret Access Key created previously by you.
Add your default region and press Enter, then press Enter again to accept the default output.
To generate an RSA key, run the default command in your terminal:
ssh-keygen
📝Review configuration files from Git repo Terraform_Set_Up_Apache_Web_Server
View the contents of the directory:
ls
Go into the
Terraform_Set_Up_Apache_Web_Server
directory:cd Terraform_Set_Up_Apache_Web_Server
View the contents of the
Terraform_Set_Up_Apache_Web_Server
directory:ls
Open the
main.tf
file:vim
main.tf
Review the contents of the file, and then enter
:q!
to exit the file.Open the
setup.tf
file:vim
setup.tf
Review the contents of the file, and then enter
:q!
to exit the file.
📝Deploy the Code and Access the Bootstrapped Webserver
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
Note: 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
Note: 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 will run the bootstrapping.
When complete, it will output the public IP for the Apache webserver as the
Webserver-Public-IP
value.Copy the IP address, paste it into a new browser window or tab, and press Enter.
Verify that the web page displays the index.html info, validating that the provisioner worked as intended.
📝Destroy deployment
To destroy all the resources created in this Hands-On Lab, run the command:
terraform destroy
Note: Do not forget to do it, otherwise, you will receive a considerable charge.
📝Video Step-by-Step of Hands-On Lab
Congratulations — you have completed this hands-on lab covering the basic use of Terraform provisioner to custom bootstrap a VM in AWS, install a webserver on it, and then test that the webserver is working as expected.
Thank you for reading. I hope you were able to understand and learn something helpful from my blog.
Please follow me on CloudDevOpsToLearn and LinkedIn franciscojblsouza