-
Notifications
You must be signed in to change notification settings - Fork 10
/
03-webapp.tf
61 lines (49 loc) · 1.37 KB
/
03-webapp.tf
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
resource "aws_key_pair" "olw_kp" {
key_name = "olw_kp"
public_key = file("./.pk/olw_pk.pub")
}
data "aws_ami" "ubuntu" {
most_recent = "true"
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"]
}
resource "aws_instance" "olw_web" {
count = var.SETTINGS.web_app.count
ami = data.aws_ami.ubuntu.id
instance_type = var.SETTINGS.web_app.instance_type
subnet_id = aws_subnet.olw_public_subnet[count.index].id
key_name = aws_key_pair.olw_kp.key_name
vpc_security_group_ids = [aws_security_group.olw_web_sg.id]
tags = {
Name = "olw_web_${count.index}"
Project = "olw"
}
}
resource "aws_eip" "olw_web_eip" {
count = var.SETTINGS.web_app.count
instance = aws_instance.olw_web[count.index].id
vpc = true
tags = {
Name = "olw_web_eip_${count.index}"
Project = "olw"
}
connection {
host = self.public_ip
type = "ssh"
user = "ubuntu"
private_key = file("./.pk/olw_pk.pem")
}
provisioner "remote-exec" {
inline = ["echo 'built server!'"]
}
provisioner "local-exec"{
command = "echo ${aws_eip.olw_web_eip[count.index].public_dns} > ansible/hosts"
}
}