Coder Social home page Coder Social logo

terraform-recipe-managing-auto-scaling-groups-and-load-balancers's Introduction

terraform-recipe-managing-auto-scaling-groups-and-load-balancers's People

Contributors

andreivmaksimov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terraform-recipe-managing-auto-scaling-groups-and-load-balancers's Issues

No aws_instance?

Hi why there is no aws_instance? is it because this is managed by the aws_autoscaling_group?

Having issues with port in EC2 not open? But defined in security group?

variable "ami" {
  description = "The AMI ID"
  default = "ami-87848ee3"
}

variable "public_ip" {
  description = "Public IP"
  //    default = "52.62.107.101"
  default = ""

}

data "external" "whatismyip" {
  program = [
    "${path.module}/whatismyip.sh"]
}

resource "aws_security_group" "aws1" {
  name = "Default Security Group"
  description = "Allows all traffic"

  ingress {
    from_port = 15672
    protocol = "tcp"
    to_port = 15672
    cidr_blocks = [
     "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 8883
    protocol = "tcp"
    to_port = 8883
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 5672
    protocol = "tcp"
    to_port = 5672
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = "${var.ssh_port}"
    to_port = "${var.ssh_port}"
    protocol = "tcp"
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = "${var.icmp_port}"
    protocol = "icmp"
    to_port = 0
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 0
    to_port = 0
    protocol = "-1"
    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_key_pair" "auth" {
  key_name = "tls_public_key"
  public_key = "${file("~/.ssh/debian9KeyPair.pub")}"
}

resource "aws_instance" "launch_instance" {
  ami = "${lookup(var.aws_amis, var.aws_region)}"

  instance_type = "t2.micro"
  key_name = "${aws_key_pair.auth.id}"

  vpc_security_group_ids = ["${aws_security_group.aws1.id}"]

  //	public_ip = "${var.public_ip}"
  # This EC2 Instance has a public IP and will be accessible directly from the public Internet
  associate_public_ip_address = true

  tags {
    Name = "${var.instance_name}-public"
  }
}

ssh admin@variable "ami" {
  description = "The AMI ID"
  default = "ami-87848ee3"
}

variable "public_ip" {
  description = "Public IP"
  //    default = "52.62.107.101"
  default = ""

}

data "external" "whatismyip" {
  program = [
    "${path.module}/whatismyip.sh"]
}

resource "aws_security_group" "aws1" {
  name = "Default Security Group"
  description = "Allows all traffic"

  ingress {
    from_port = 15672
    protocol = "tcp"
    to_port = 15672
    cidr_blocks = [
     "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 8883
    protocol = "tcp"
    to_port = 8883
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 5672
    protocol = "tcp"
    to_port = 5672
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = "${var.ssh_port}"
    to_port = "${var.ssh_port}"
    protocol = "tcp"
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = "${var.icmp_port}"
    protocol = "icmp"
    to_port = 0
    cidr_blocks = [
      "${data.external.whatismyip.result["internet_ip"]}/32"]
  }

  ingress {
    from_port = 0
    to_port = 0
    protocol = "-1"
    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_key_pair" "auth" {
  key_name = "tls_public_key"
  public_key = "${file("~/.ssh/debian9KeyPair.pub")}"
}

resource "aws_instance" "launch_instance" {
  ami = "${lookup(var.aws_amis, var.aws_region)}"

  instance_type = "t2.micro"
  key_name = "${aws_key_pair.auth.id}"

  vpc_security_group_ids = ["${aws_security_group.aws1.id}"]

  //	public_ip = "${var.public_ip}"
  # This EC2 Instance has a public IP and will be accessible directly from the public Internet
  associate_public_ip_address = true

  tags {
    Name = "${var.instance_name}-public"
  }
}

Then ssh into EC2 debian:

ssh [email protected]

$ netstat  -tunlp
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -    

Don't see the ports 5672, 8883, 15672?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.