terraform-tofu-labs/3-remote-states/code/main.tf

56 lines
1.2 KiB
Terraform
Raw Normal View History

2024-04-15 22:33:12 +00:00
provider "aws" {
2024-04-16 17:23:24 +00:00
region = "eu-west-1"
2024-04-15 22:33:12 +00:00
}
resource "aws_security_group" "web_server_sg_tf" {
name = "web-server-sg-tf"
description = "Allow HTTP to web server"
vpc_id = module.vpc.vpc_id
2024-04-16 17:23:24 +00:00
ingress {
description = "SSH ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
2024-04-15 22:33:12 +00:00
ingress {
description = "HTTP ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTPS ingress"
from_port = 443
to_port = 443
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_instance" "test_ami" {
ami = var.ami_id
2024-04-16 17:23:24 +00:00
instance_type = var.instance_size
2024-04-15 22:33:12 +00:00
associate_public_ip_address = true
2024-04-16 17:23:24 +00:00
subnet_id = module.vpc.public_subnets[0]
2024-04-15 22:33:12 +00:00
vpc_security_group_ids = [aws_security_group.web_server_sg_tf.id]
2024-04-16 17:23:24 +00:00
user_data = <<-EOF
#!/bin/bash
sudo dnf install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
EOF
2024-04-15 22:33:12 +00:00
}