elastic beanstalk woes, I need a helping hand

838 views
Skip to first unread message

gitted

unread,
Feb 9, 2017, 3:42:33 PM2/9/17
to Terraform
Hello,

Very excited about building out my first Terraform repo for AWS.  Really love this toolkit! :)

I'm trying to setup my Elastic Beanstalk app, but I keep getting the same error message:

>>The EC2 instances failed to communicate with AWS Elastic Beanstalk, either because of configuration problems with the VPC or a failed EC2 instance. Check your VPC configuration and >>try launching the environment again.

>>Stack named 'awseb-e-xxxx-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBInstanceLaunchWaitCondition].

Hoping someone experienced in VPC and EB can figure out what is wrong with my setup, I can't figure it out!
Any glaring issues with the below?

provider "aws" {
  region = "${var.region}"
}

###########
##  VPC
###########
module "vpc" {

  name = "my-vpc"

  cidr            = "10.0.0.0/16"
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = "true"

  azs = ["us-east-2a", "us-east-2b", "us-east-2c"]

  tags {
    "Terraform"   = "true"
    "Environment" = "${var.environment}"
  }
}

resource "aws_security_group" "web" {
  name        = "${var.prefix}-SG_WEB-${var.environment}"
  description = "SG web allow incoming http connections"

  vpc_id = "${module.vpc.vpc_id}"

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

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

  ingress {
    from_port   = -1
    to_port     = -1
    protocol    = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
    self        = true
  }

  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  # NTP clock sync
  egress {
    from_port   = 123
    to_port     = 123
    protocol    = "udp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags {
    Name = "${var.prefix}"
  }
}

resource "aws_security_group" "db" {
  name        = "${var.prefix}-SG_DB-${var.environment}"
  description = "DB SG for database"

  vpc_id = "${module.vpc.vpc_id}"

  ingress {
    from_port       = 5432
    to_port         = 5432
    protocol        = "tcp"
    security_groups = ["${aws_security_group.web.id}"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags {
    Name = "${var.prefix}"
  }
}

###########
##  EB
###########

resource "aws_elastic_beanstalk_application" "app_web" {
  name = "EB-${var.prefix}-${var.app_web}"
}

resource "aws_elastic_beanstalk_environment" "app_web-prod" {
  name                = "EB-${var.prefix}-${var.app_web}-prod"
  application         = "${aws_elastic_beanstalk_application.app_web.name}"
  tier                = "WebServer"
  solution_stack_name = "64bit Amazon Linux 2016.09 v2.3.1 running Ruby 2.3 (Puma)"

  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name      = "IamInstanceProfile"
    value     = "aws-elasticbeanstalk-ec2-role"
  }

  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name      = "InstanceType"
    value     = "t2.small"
  }

  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name      = "SecurityGroups"
    value     = "${aws_security_group.web.id}"
  }

  setting {
    namespace = "aws:elasticbeanstalk:environment"
    name      = "ServiceRole"
    value     = "aws-elasticbeanstalk-service-role"
  }

  setting {
    namespace = "aws:ec2:vpc"
    name      = "VPCId"
    value     = "${module.vpc.vpc_id}"
  }

  setting {
    namespace = "aws:ec2:vpc"
    name      = "Subnets"

    # value     = "${module.vpc.public_subnets}" 
    value = "subnet-xxx"  # this from the module public subnet 
  }

  setting {
    namespace = "aws:ec2:vpc"
    name      = "ELBSubnets"

    # value     = "${module.vpc.public_subnets}" 
    value = "subnet-xxx"  # this from the module public subnet
  }

  setting {
    namespace = "aws:ec2:vpc"
    name      = "ELBScheme"
    value     = "external"
  }

  setting {
    namespace = "aws:ec2:vpc"
    name      = "AssociatePublicIpAddress"
    value     = "true"
  }

}

gitted

unread,
Feb 10, 2017, 5:19:50 PM2/10/17
to Terraform
Doesn't anything look glaringly wrong to anyone?

Much appreciated!
Reply all
Reply to author
Forward
0 new messages