dev.metalisp.survey/main.tf

86 lines
2.1 KiB
Terraform
Raw Permalink Normal View History

2024-09-17 20:56:50 +02:00
resource "aws_vpc" "mlsurvey_vpc" {
2024-07-07 19:39:42 +02:00
cidr_block = "10.0.0.0/16"
2024-06-26 17:29:56 +02:00
enable_dns_hostnames = true
enable_dns_support = true
tags = {
2024-07-08 17:52:37 +02:00
Name = "ml-survey-vpc"
2024-06-26 17:29:56 +02:00
}
}
2024-06-27 17:55:21 +02:00
2024-09-17 20:56:50 +02:00
resource "aws_subnet" "mlsurvey_public_subnet" {
vpc_id = aws_vpc.mlsurvey_vpc.id
2024-07-07 19:39:42 +02:00
cidr_block = "10.0.1.0/24"
2024-06-27 17:55:21 +02:00
map_public_ip_on_launch = true
2024-09-17 20:56:50 +02:00
availability_zone = "eu-central-1a"
2024-06-27 17:55:21 +02:00
tags = {
2024-07-08 17:52:37 +02:00
Name = "ml-survey-public"
2024-06-27 17:55:21 +02:00
}
}
2024-09-17 20:56:50 +02:00
resource "aws_internet_gateway" "mlsurvey_internet_gateway" {
vpc_id = aws_vpc.mlsurvey_vpc.id
tags = {
Name = "ml-survey-igw"
}
}
resource "aws_route_table" "mlsurvey_public_rt" {
vpc_id = aws_vpc.mlsurvey_vpc.id
tags = {
Name = "ml-survey-rt"
}
}
resource "aws_route" "mlsurvey_default_route" {
route_table_id = aws_route_table.mlsurvey_public_rt.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.mlsurvey_internet_gateway.id
}
resource "aws_route_table_association" "mlsurvey_public_assoc" {
subnet_id = aws_subnet.mlsurvey_public_subnet.id
route_table_id = aws_route_table.mlsurvey_public_rt.id
}
resource "aws_security_group" "mlsurvey_sg" {
name = "ml-survey-sg"
description = "ml-survey security group"
vpc_id = aws_vpc.mlsurvey_vpc.id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
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_key_pair" "mlsurvey_auth" {
key_name = "ml-survey-key"
public_key = file("~/.ssh/ml-survey-key.pub")
}
resource "aws_instance" "dev_node" {
2025-01-12 12:05:58 +01:00
instance_type = "t2.micro"
ami = data.aws_ami.server_ami.id
key_name = aws_key_pair.mlsurvey_auth.id
vpc_security_group_ids = [aws_security_group.mlsurvey_sg.id]
subnet_id = aws_subnet.mlsurvey_public_subnet.id
user_data = data.cloudinit_config.config.rendered
user_data_replace_on_change = true
2024-09-17 20:56:50 +02:00
tags = {
Name = "dev-node"
}
}
2025-01-12 12:05:58 +01:00
output "dev_node_public_ip" {
value = aws_instance.dev_node.public_ip
}