-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEC2-UserData
46 lines (38 loc) · 1.23 KB
/
EC2-UserData
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
cat c2-ec2instance.tf:
resource "aws_instance" "myec2vm" {
ami = "ami-00dfe2c7ce89a450b"
key_name = "newkipi123"
instance_type = "t2.micro"
user_data = file("${path.module}/app1-install.sh")
tags = {
"Name" = "EC2 Demo"
}
}
----
cat app1-install.sh
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd
sudo systemctl enable httpd
sudo service httpd start
sudo echo '<h1>Welcome to StackSimplify - APP-1</h1>' | sudo tee /var/www/html/index.html
sudo mkdir /var/www/html/app1
sudo echo '<!DOCTYPE html> <html> <body style="background-color:rgb(250, 210, 210);"> <h1>Welcome to Stack Simplify - APP-1</h1> <p>Terraform Demo</p> <p>Application Version: V1</p> </body></html>' | sudo tee /var/www/html/app1/index.html
sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html
----
cat c1-versions.tf
# Terraform Block
terraform {
required_version = "~> 1.0.6" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
# Provider Block
provider aws {
region = "us-east-2"
}
/> terraform destroy -target=aws_instance.myec2vm