-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance.tf
83 lines (68 loc) · 1.97 KB
/
instance.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ec2 instance AMI
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
// Create ec2 instances
resource "aws_instance" "public_instance_a" {
ami = data.aws_ami.ubuntu.id
instance_type = var.public_ec2_instance_type
subnet_id = aws_subnet.public_a.id
security_groups = [aws_security_group.public_sg.id]
key_name = var.key_name
tags = {
Name = "public_instance_a"
}
}
resource "aws_instance" "public_instance_b" {
ami = data.aws_ami.ubuntu.id
instance_type = var.public_ec2_instance_type
subnet_id = aws_subnet.public_b.id
security_groups = [aws_security_group.public_sg.id]
key_name = var.key_name
tags = {
Name = "public_instance_b"
}
}
resource "aws_instance" "private_instance_a" {
ami = data.aws_ami.ubuntu.id
instance_type = var.private_ec2_instance_type
subnet_id = aws_subnet.private_a.id
security_groups = [aws_security_group.sg_private.id]
key_name = "newKey"
user_data = <<-EOF
#!/bin/bash
apt-get update
apt-get install -y nginx
systemctl start nginx
systemctl enable nginx
EOF
tags = {
Name = "private_instance_a"
}
}
resource "aws_instance" "private_instance_b" {
ami = data.aws_ami.ubuntu.id
instance_type = var.private_ec2_instance_type
security_groups = [aws_security_group.sg_private.id]
subnet_id = aws_subnet.private_b.id
key_name = var.key_name
user_data = <<-EOF
#!/bin/bash
apt-get update
apt-get install -y nginx
systemctl start nginx
systemctl enable nginx
EOF
tags = {
Name = "private_instance_b"
}
}