-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathsample
68 lines (60 loc) · 1.63 KB
/
sample
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
resource "aws_s3_bucket" "mys3prod" {
bucket = "tf-dean-bucket-prod"
acl = "public-read-write"
tags = {
Name = "bucket"
Environment = "Prod"
}
}
resource "aws_instance" "ec2-prod" {
ami = data.aws_ami.ami.id
instance_type = "t2.micro"
availability_zone = "us-east-2b"
key_name = aws_key_pair.ssh.key_name
vpc_security_group_ids = [aws_security_group.testmysg.id]
}
resource "aws_instance" "ec2-prod2" {
ami = data.aws_ami.ami.id
instance_type = "t2.micro"
availability_zone = "us-east-2b"
key_name = aws_key_pair.ssh.key_name
vpc_security_group_ids = [aws_security_group.testmysg.id]
}
resource "aws_security_group" "testmysg" {
name = "testmysg2222"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_key_pair" "ssh" {
key_name = "testpubkey"
public_key = file("~/testec2.pub")
tags = {
env = "prod"
}
}
resource "null_resource" "provisioner" {
triggers = {
public_ip = aws_instance.ec2-prod.public_ip
public_ip = aws_instance.ec2-prod2.public_ip
}
connection {
type = "ssh"
host = aws_instance.ec2-prod.public_ip
user = "ec2-user"
agent = false
private_key = file("~/testec2.pem")
}
provisioner "remote-exec" {
inline = ["sudo yum -y update", "sudo yum install -y httpd", "sudo service httpd start", "echo '<!doctype html><html><body><h1>CONGRATS!!..You have configured successfully your remote exec provisioner!</h1></body></html>' | sudo tee /var/www/html/index.html"]
}
}