variable "http_port" {
 description = "Port to listen for HTTP requests on"
 default     = 8080
 type        = number
}

output "public_ip" {
 value       = aws_instance.cloudbuntu.public_ip
 description = "The public IP of our new cloudbuntu!"
}

provider "aws" {
 region = "us-east-2"
}

resource "aws_instance" "cloudbuntu" {
 ami           = "ami-0862be96e41dcbf74"
 instance_type = "t2.micro"
 vpc_security_group_ids = [aws_security_group.cloudwall.id]

 user_data     = <<-EOF
                    #!/bin/bash
                    echo "Hello, World! I'm $(hostname)!" > index.html
                    nohup busybox httpd -f -p ${var.http_port} &
                    EOF

 user_data_replace_on_change = true

 tags = {
  Name = "terraform-example"
 }
}

resource "aws_security_group" "cloudwall" {
 name = "terraform-example.instance"

 ingress {
  from_port   = var.http_port
  to_port     = var.http_port
  protocol    = "tcp"
  cidr_blocks = ["0.0.0.0/0"]
 }
}