-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcompute.tf
More file actions
56 lines (47 loc) · 1.39 KB
/
compute.tf
File metadata and controls
56 lines (47 loc) · 1.39 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
# compute terraform file to deploy instances in created subnets
# search for the AMI ID based on the region, owner and name
data "aws_ami" "ubuntu" {
owners = ["099720109477"]
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
# deploy instances in the subnets
resource "aws_instance" "webserver" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
subnet_id = var.subnet_id
availability_zone = "${var.region}a"
vpc_security_group_ids = var.security_group_id
associate_public_ip_address = true
source_dest_check = false
key_name = var.ssh_key
connection {
host = self.public_ip
user = "ubuntu"
type = "ssh"
private_key = file(var.key_loc)
}
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y upgrade",
"sudo apt-get install -y apache2"
]
}
tags = {
Name = var.instance_name_tag
Type = "webserver"
Role = var.instance_role_tag
}
}
#outputs needed to later set up the transit gateway ip multicast in AWS CLI
output "instance_nic_id" {
value = aws_instance.webserver.primary_network_interface_id
}