Description: In the previous topic, I have explained, How to create a blank EC2 instance using Terraform. In this topic, I am creating an EC2 instance with a Pre-installed Apache package with the instance.
- First I am creating an apache install shell script for Linux with the name install-apache.sh as follow and save it on the project folder
# installl-apache.sh #!/bin/bash -xe cd /tmp yum update -y yum install -y httpd echo "Hello from the EC2 instance $(hostname -f)." > /var/www/html/index.html systemctl start httpd
- After creating the script file, Now I am creating terraform project file to create EC2 Instance as follow
provider "aws" { access_key = "AKIAU4DZPCIQVSO67EPG" secret_key = "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" region = "us-east-1" } resource "aws_instance" "Webserver" { ami = "ami-0d5eff06f840b45e9" instance_type = "t2.micro" tags = { Name = "Web server" } vpc_security_group_ids = [ "sg-01df6b2fc0470ce65" ] user_data = "${file("install_apache.sh")}" key_name = "Ansible" }
- Now, I am going to run terraform project using terraform terminal as follow
# terraform init
Great Thnx for this article
ReplyDeleteThank you for this article
ReplyDeleteThanks for EC2 instance using Terraform knowledge
ReplyDeleteGood article
ReplyDeleteGreat 5 minutes read and very much useful information..thank you for writing and sharing your article.
ReplyDeleteNice
ReplyDeleteExcellent article in easy steps
ReplyDeleteThis will be quick and helpful for anyone.
ReplyDelete