// Aula 9 - Criando um cluster no AWS https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_configuration https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle // main.tf provider "aws" { region = "us-east-1" } variable "server_port" { description = "a porta do servidor web" type = number default = 80 } resource "aws_launch_configuration" "teste_servidor" { image_id = "ami-053b0d53c279acc90" instance_type = "t2.micro" security_groups = [aws_security_group.instance.id] user_data = <<-EOF #!/bin/bash sudo apt update -y sudo apt install apache2 -y sudo systemctl start apache2 sudo bash -c 'echo Hello World run on port ${var.server_port} > /var/www/html/index.html' EOF lifecycle { create_before_destroy = true } } data "aws_vpc" "default" { default = true } data "aws_subnets" "default" { filter { name = "vpc-id" values = [data.aws_vpc.default.id] } } resource "aws_autoscaling_group" "teste_servidor" { launch_configuration = aws_launch_configuration.teste_servidor.name vpc_zone_identifier = data.aws_subnets.default.ids min_size = 2 max_size = 4 tag { key = "Name" value = "terraform-asg-example" propagate_at_launch = true } } resource "aws_security_group" "instance" { name = "teste_servidor1" ingress { from_port = var.server_port to_port = var.server_port 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"] } }