-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_ec2.tf
60 lines (49 loc) · 1.48 KB
/
aws_ec2.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
provider "aws" {
region = "us-west-2"
}
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"] # Canonical
}
resource "aws_instance" "master" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "Master"
}
provisioner "remote-exec" {
inline = [
"sudo apt install -y docker",
"systemctl start docker",
"docker pull laobiz/master",
"docker run laobiz/master",
]
}
}
resource "aws_instance" "slave" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "Slave"
}
provisioner "remote-exec" {
inline = [
"sudo apt install -y docker",
"systemctl start docker",
"docker pull laobiz/slave",
"docker run laobiz/slave -e MASTER_IP=${aws_instance.master.public_ip}",
]
}
}
resource "aws_key_pair" "deployer" {
key_name = "deployer-key"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"
}