PySquirrel
PySquirrel

Reputation: 39

AWS web server refused to connect

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

provider "random" {}

resource "random_pet" "name" {}

resource "aws_instance" "web" {
  ami           = "ami-0022f774911c1d690"
  instance_type = "t2.micro"
  user_data     = file("init-script.sh")
  vpc_security_group_ids = [aws_security_group.web-sg.id]

  tags = {
    Name = random_pet.name.id
  }
}

resource "aws_security_group" "web-sg" {
  name = "${random_pet.name.id}-sg"
  ingress {
    from_port = 80
    to_port = 80
    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"]
  }
}

I am using Terraform to deploy a PHP web server. As shown, ingress and egress rules are defined and I should be able to connect. What am I doing wrong?

Also, I am following this tutorial:

https://learn.hashicorp.com/tutorials/terraform/resource?in=terraform/configuration-language

Upvotes: 0

Views: 78

Answers (1)

paulg
paulg

Reputation: 738

I cloned and ran this tutorial myself & it does not work for me either. Trying to connect gives me a timeout error.

1st observation - it's very old & not a great tutorial. The AMI it samples does not even exist anymore & I used the latest AMZN Default Linux 2 AMI instead.

2nd observation - no key pair is created or used with this EC2 Instance in the tutorial which makes troubleshooting difficult since you cannot connect & view logs.

3rd observation - ties in with my 1st one, chkconfig is used in the init-script & if you're using a newer AMI (centos, redhat or amzn linux image) they all likely use systemctl instead.

Conclusion: This tutorial really needs updating & I don't recommend using it since it's virtually unusable and very outdated.

Upvotes: 2

Related Questions