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"
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"
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
}
ingress {
from_port = -1
to_port = -1
protocol = "icmp"
self = true
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
}
# NTP clock sync
egress {
from_port = 123
to_port = 123
protocol = "udp"
}
egress {
from_port = 5432
to_port = 5432
protocol = "tcp"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
}
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"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
}
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"
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"
}
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"
}
}