-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
87 lines (70 loc) · 1.76 KB
/
main.tf
File metadata and controls
87 lines (70 loc) · 1.76 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
provider "aws" {
region = "us-east-1"
version = "~> 2.35"
}
terraform {
backend "s3" {
bucket = "terraform-state-remote-storage2"
key = "helloworld"
region = "us-east-1"
}
}
data "aws_ami" "prod_ami" {
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-2.0.20201126.0-x86_64-gp2"]
}
owners = ["amazon"] # Canonical
}
resource "aws_instance" "prod_1" {
ami = data.aws_ami.prod_ami.id
instance_type = "t3.micro"
key_name = "MyUSE1KP"
security_groups = [ "launch-wizard-3" ]
tags = {
Name = "PROD_1"
}
}
resource "aws_instance" "prod_2" {
ami = data.aws_ami.prod_ami.id
instance_type = "t3.micro"
key_name = "MyUSE1KP"
security_groups = [ "launch-wizard-3" ]
tags = {
Name = "PROD_2"
}
}
resource "aws_instance" "prod_3" {
ami = data.aws_ami.prod_ami.id
instance_type = "t3.micro"
key_name = "MyUSE1KP"
security_groups = [ "launch-wizard-3" ]
tags = {
Name = "PROD_3"
}
}
resource "null_resource" "delay" {
depends_on = [aws_instance.prod_1, aws_instance.prod_2, aws_instance.prod_3]
provisioner "local-exec" {
command = <<EOD
cat <<EOF > hosts
[webservers]
${aws_instance.prod_1.private_ip}
${aws_instance.prod_2.private_ip}
${aws_instance.prod_3.private_ip}
EOF
aws ec2 wait instance-status-ok --instance-ids ${aws_instance.prod_1.id} && aws ec2 wait instance-status-ok --instance-ids ${aws_instance.prod_2.id} && aws ec2 wait instance-status-ok --instance-ids ${aws_instance.prod_3.id}
aws s3 cp hosts s3://ramgopkeys
EOD
}
}
output "PUB_1" {
value = aws_instance.prod_1.public_ip
}
output "PUB_2" {
value = aws_instance.prod_2.public_ip
}
output "PUB_3" {
value = aws_instance.prod_3.public_ip
}