-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.tf
More file actions
31 lines (23 loc) · 728 Bytes
/
instance.tf
File metadata and controls
31 lines (23 loc) · 728 Bytes
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
# Use the local vars to create 2 (or more) instances in different subnets
locals {
subnet = concat([aws_subnet.public-a.id], [aws_subnet.public-b.id])
}
resource "aws_instance" "server" {
ami = var.AMI
instance_type = var.instance_type
# the counter for instances
count = var.instance_count
# the VPC subnet
subnet_id = element(local.subnet, count.index)
# the security group
vpc_security_group_ids = [aws_security_group.allow-challenge.id]
# the public SSH key
key_name = aws_key_pair.mykeypair.key_name
# Name of Server using the index count
tags = {
Name = "Server ${count.index}"
}
provisioner "local-exec" {
command = "echo ${self.public_ip} >> ansible/hosts"
}
}