93 lines
2.2 KiB
HCL
93 lines
2.2 KiB
HCL
resource "aws_key_pair" "titanium" {
|
|
key_name = "titanium"
|
|
public_key = file(var.ssh_public_key_file)
|
|
}
|
|
|
|
resource "aws_vpc" "outpost" {
|
|
# whatever
|
|
cidr_block = "172.32.0.0/16"
|
|
}
|
|
|
|
resource "aws_subnet" "outpost" {
|
|
vpc_id = aws_vpc.outpost.id
|
|
cidr_block = cidrsubnet(aws_vpc.outpost.cidr_block, 8, 1)
|
|
availability_zone = "us-west-2a"
|
|
}
|
|
|
|
resource "aws_internet_gateway" "outpost" {
|
|
vpc_id = aws_vpc.outpost.id
|
|
}
|
|
|
|
resource "aws_security_group" "outpost" {
|
|
vpc_id = aws_vpc.outpost.id
|
|
|
|
ingress {
|
|
from_port = 22
|
|
to_port = 22
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
egress {
|
|
from_port = 0
|
|
to_port = 0
|
|
protocol = "-1"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
}
|
|
|
|
resource "aws_route_table" "outpost" {
|
|
vpc_id = aws_vpc.outpost.id
|
|
|
|
route {
|
|
cidr_block = "0.0.0.0/0"
|
|
gateway_id = aws_internet_gateway.outpost.id
|
|
}
|
|
}
|
|
|
|
resource "aws_route_table_association" "outpost_assoc" {
|
|
subnet_id = aws_subnet.outpost.id
|
|
route_table_id = aws_route_table.outpost.id
|
|
}
|
|
|
|
resource "aws_network_interface" "outpost" {
|
|
subnet_id = aws_subnet.outpost.id
|
|
# Required for private_ip_list
|
|
private_ip_list_enabled = true
|
|
# private_ips aren't ordered meaning this NIC and its dependent resources may
|
|
# be re-created upon changing the number of IPs.
|
|
# private_ip_list, however, _is_ ordered, hence why we use it over private_ips
|
|
private_ip_list = [
|
|
for i in range(var.ip_count) : cidrhost(aws_subnet.outpost.cidr_block, i + 32)
|
|
]
|
|
security_groups = [aws_security_group.outpost.id]
|
|
}
|
|
|
|
resource "aws_instance" "outpost" {
|
|
ami = "ami-00c257e12d6828491"
|
|
instance_type = "t2.micro"
|
|
|
|
availability_zone = aws_subnet.outpost.availability_zone
|
|
key_name = aws_key_pair.titanium.key_name
|
|
|
|
network_interface {
|
|
network_interface_id = aws_network_interface.outpost.id
|
|
device_index = 0
|
|
}
|
|
|
|
tags = {
|
|
Name = "outpost-01"
|
|
}
|
|
}
|
|
|
|
resource "aws_eip" "eip" {
|
|
count = var.ip_count
|
|
}
|
|
|
|
resource "aws_eip_association" "eip_assoc" {
|
|
count = var.ip_count
|
|
network_interface_id = aws_network_interface.outpost.id
|
|
allocation_id = aws_eip.eip[count.index].id
|
|
private_ip_address = aws_network_interface.outpost.private_ip_list[count.index]
|
|
}
|