brikis98 / terraform-up-and-running-code

Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
http://www.terraformupandrunning.com/
MIT License
2.87k stars 1.92k forks source link

Simple webserver example is not working #25

Closed Ivasan7 closed 5 years ago

Ivasan7 commented 5 years ago

@brikis98 I am trying to run the example of a single webserver:

provider "aws" {
    region = "eu-west-3"
}

resource "aws_instance" "example" { 
    ami = "ami-03bca18cb3dc173c9"
    instance_type = "t2.micro"
    vpc_security_group_ids = ["${aws_security_group.instance.id}"]
    user_data = <<-EOF
                #!/bin/bash
                echo "Hello World">> index.html
                nohup busybox httpd -f -p "8080" &
                EOF
   tags {
        Name = "terraform-example"
    }
}

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

    ingress {
        from_port = 8080
        to_port = 8080
        protocol = "tcp"
        cidr_blocks = ["0.0.0.0/0"]
    }
}

output "public_ip" {
  value = "${aws_instance.example.public_ip}"
}

originally in the 2017 edition book the port number is without quotes (tried both options).

However still does not work. curl http://35.181.26.107:8080 curl: (7) Failed to connect to 35.181.26.107 port 8080: Connection refused Can you maybe take a look ?

Ivasan7 commented 5 years ago

The code works just fine. Firewall problem.