Open julian-gamboa-ensino opened 9 months ago
Problema com um pacote da versão 8.2
provider "aws" { region = var.aws_region // Definido em variables.tf }
resource "aws_vpc" "test-env" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true enable_dns_support = true }
resource "aws_subnet" "subnet-uno" {
cidr_block = "${cidrsubnet(aws_vpc.test-env.cidr_block, 3, 1)}" vpc_id = "${aws_vpc.test-env.id}" availability_zone = "us-west-2a" }
resource "aws_security_group" "ingress-ssh-test" { name = "allow-ssh-sg" vpc_id = "${aws_vpc.test-env.id}"
ingress { cidr_blocks = [ "0.0.0.0/0" ]
from_port = 22
to_port = 22
protocol = "tcp"
}
egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } }
resource "aws_security_group" "web" { name_prefix = "web-sg-" description = "Allow HTTP traffic" vpc_id = "${aws_vpc.test-env.id}"
ingress { from_port = 8080 to_port = 8080 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_internet_gateway" "test-env-gw" { vpc_id = "${aws_vpc.test-env.id}" }
resource "aws_route_table" "route-table-test-env" { vpc_id = "${aws_vpc.test-env.id}"
route { cidr_block = "0.0.0.0/0" gateway_id = "${aws_internet_gateway.test-env-gw.id}" } }
resource "aws_route_table_association" "subnet-association" { subnet_id = "${aws_subnet.subnet-uno.id}" route_table_id = "${aws_route_table.route-table-test-env.id}" }
resource "aws_spot_instance_request" "web" {
ami = var.ami_id
spot_price = "0.009"
spot_type = "one-time"
instance_type = "t2.micro"
key_name = var.public_key
security_groups = ["${aws_security_group.ingress-ssh-test.id}",aws_security_group.web.id]
subnet_id = "${aws_subnet.subnet-uno.id}"
user_data = <<-EOF
sudo apt-get update
sudo apt-get install -y golang-go
EOF
tags = { Name = "web-server-spot" } }
resource "time_sleep" "wait_60_seconds" { depends_on = [aws_spot_instance_request.web] create_duration = "60s" }
resource "aws_eip" "ip-test-env" { instance = "${aws_spot_instance_request.web.spot_instance_id}" vpc = true depends_on = [time_sleep.wait_60_seconds] }
Usando o código terraform, pode-se criar uma instância EC2 (aws), com ubuntu 20.04 para instalar um exemplo simples de sistema laravel para login/regsitro :
Pode-se ver um exemplo no endereço
http://52.34.80.19/