From f4b6ad4b0f84037f2777fb930db63738d89fdc62 Mon Sep 17 00:00:00 2001 From: Raphael Neumann Date: Tue, 13 May 2025 13:14:57 -0300 Subject: [PATCH] feat: create nginx instance --- nginx.sh | 5 +++ raphaelneumann.tf | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 nginx.sh create mode 100644 raphaelneumann.tf diff --git a/nginx.sh b/nginx.sh new file mode 100644 index 0000000..ad8f753 --- /dev/null +++ b/nginx.sh @@ -0,0 +1,5 @@ +#!/bin/bash +apt-get update +apt-get install nginx -y +systemctl enable nginx +systemctl start nginx \ No newline at end of file diff --git a/raphaelneumann.tf b/raphaelneumann.tf new file mode 100644 index 0000000..e4f4970 --- /dev/null +++ b/raphaelneumann.tf @@ -0,0 +1,93 @@ +resource "aws_vpc" "main" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "rneumann_vpc" + } +} + +resource "aws_subnet" "main" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.1.0/24" + + tags = { + Name = "rneumann_subnet" + } +} + +resource "aws_internet_gateway" "gw" { + vpc_id = aws_vpc.main.id + + tags = { + Name = "rneumann_ig" + } +} + +resource "aws_route_table" "example" { + vpc_id = aws_vpc.main.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.gw.id + } + + tags = { + Name = "ig_default_route" + } +} + +resource "aws_route_table_association" "a" { + subnet_id = aws_subnet.main.id + route_table_id = aws_route_table.example.id +} + +data "aws_ami" "ubuntu" { + most_recent = true + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + owners = ["099720109477"] # Canonical +} + +resource "aws_instance" "web" { + ami = data.aws_ami.ubuntu.id + instance_type = "t3.micro" + subnet_id = aws_subnet.main.id + associate_public_ip_address = true + user_data = file("nginx.sh") + + vpc_security_group_ids = [aws_security_group.nginx.id] + tags = { + Name = "rneumann_nginx" + } +} + +resource "aws_security_group" "nginx" { + name = "sg_nginx" + vpc_id = aws_vpc.main.id + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } +} +