tempmc/src/network.tf.etlua

113 lines
2.4 KiB
Plaintext

<% local secrets = require "secrets" %>
<% local config = require "config" %>
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
tags = {
Name = "vpc"
}
}
resource "aws_security_group" "sg" {
name = "allow_traffic"
description = "Allow traffic to the machines"
vpc_id = aws_vpc.vpc.id
ingress {
description = "to vpc"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "from vpc"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "security group"
}
}
resource "aws_subnet" "subnet" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = "<%- config.aws_region %>a"
tags = {
Name = "subnet"
}
}
<% local private_ip = 10 %>
<% for name, info in pairs(config.machines) do %>
<% assert(name ~= "internal", "config.machines may contain a machine named 'internal'") %>
resource "aws_network_interface" "<%- name %>" {
subnet_id = aws_subnet.subnet.id
private_ips = ["10.0.0.<%- private_ip %>"]
<% private_ip = private_ip + 1 %>
security_groups = [aws_security_group.sg.id]
source_dest_check = false
tags = {
Name = "<%- name %> network interface"
}
}
resource "aws_eip" "<%- name %>" {
vpc = true
network_interface = aws_network_interface.<%- name %>.id
associate_with_private_ip = "10.0.0.<%- private_ip - 1 %>"
tags = {
Name = "<%- name %> ip"
}
}
<% end %>
resource "aws_main_route_table_association" "main" {
vpc_id = aws_vpc.vpc.id
route_table_id = aws_route_table.rt.id
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "Internet gateway"
}
}
resource "aws_route_table" "rt" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "Route table"
}
}
resource "aws_route53_zone" "main" {
name = "<%- config.domain %>"
}
resource "aws_route53_record" "www" {
zone_id = aws_route53_zone.main.zone_id
name = "<%- config.domain %>"
type = "A"
ttl = 300
records = [aws_eip.sidecar.public_ip]
}
resource "aws_route53_record" "mc" {
zone_id = aws_route53_zone.main.zone_id
name = "<%- string.format(config.subdomain_fmt, 'mc') %>"
type = "A"
ttl = 300
records = [aws_eip.main.public_ip]
}
resource "namecheap_domain_records" "my-domain2-com" {
domain = "<%- config.domain %>"
mode = "OVERWRITE"
nameservers = aws_route53_zone.main.name_servers
}