Terraform is used to create an ec2-instance in Amazon Web Services.
Create an ec2- instance using Terraform code.
Copy the AMI id from the AWS management console's launch Instance. It also specifies the instance type as t2.micro.
Also, here is the HTML script for showcasing the webpage on the instance mention the directory of the webpage. sh. Furthermore, the tag Ec2 Demo is mentioned.
Next step is to create a versions file which is available in
registry.terraform.io website
Mention the versions as per the latest or given once below
Also mentions the provider as aws and region in which we are creating Ec2- instance.
The final step is to write an HTML script for the instance.
We are directly creating an HTML script, so no file sharing services are required.
The html script below is directly added to the user data of the Ec2 instance.
Following completion of all steps, follow the instructions below to create an ec2 instance in AWS using Terraform.
To install all of the required plugins, run terraform init.
Type terraform validate to see if there are any semantic errors in the code.
To get a detailed output of the instance we're creating, type terraform plan.
To create an instance in AWS, enter terraform apply -auto-approve. The task will then be completed in a matter of seconds.
Now, open the AWS management console and copy the public IPv4 address to a new browser window.
Now enter /app1/index.html after the ip address of the
webpage then it will redirect to index.html page of the website
That's it; we've now created a webpage with Terraform.
Now, type terraform destroy -auto-approve to destroy the created instance; this will take a few seconds.