Skip to content

Instantly share code, notes, and snippets.

@estenssoros
Last active September 20, 2023 10:08
Show Gist options
  • Save estenssoros/f08097597ec66ca86ea1b268fe121931 to your computer and use it in GitHub Desktop.
Save estenssoros/f08097597ec66ca86ea1b268fe121931 to your computer and use it in GitHub Desktop.
Docker, ECR, Elastic Beanstalk, & Terraform main.tf
locals {
app_env = {
ENV1 = "ENV1"
ENV2 = "ENV2"
ENV3 = "ENV3"
}
common_name = "${var.app_name}-${var.environment}"
}
resource "aws_elastic_beanstalk_application" "app" {
name = local.common_name
}
resource "aws_elastic_beanstalk_application_version" "app_version" {
name = "${local.common_name}-version"
application = aws_elastic_beanstalk_application.app.name
bucket = aws_s3_bucket.ebs.id
key = aws_s3_object.ebs_deployment.id
}
resource "aws_elastic_beanstalk_environment" "env" {
name = "${local.common_name}-env"
application = aws_elastic_beanstalk_application.app.name
version_label = aws_elastic_beanstalk_application_version.app_version.name
solution_stack_name = "64bit Amazon Linux 2023 v4.0.1 running Docker"
tier = "WebServer"
wait_for_ready_timeout = "10m"
setting {
name = "InstancePort"
namespace = "aws:cloudformation:template:parameter"
value = var.container_port
}
setting {
name = "IamInstanceProfile"
namespace = "aws:autoscaling:launchconfiguration"
value = aws_iam_instance_profile.beanstalk_iam_instance_profile.arn
}
setting {
name = "SecurityGroups"
namespace = "aws:autoscaling:launchconfiguration"
value = join(",", [
# additional security groups. e.g. database security group, etc.
])
}
setting {
name = "VPCId"
namespace = "aws:ec2:vpc"
value = var.vpc_id
}
setting {
name = "Subnets"
namespace = "aws:ec2:vpc"
value = join(",", var.public_subnet_ids)
}
setting {
name = "SSLCertificateId"
namespace = "aws:elb:loadbalancer"
value = aws_acm_certificate.cert.certificate_id
}
dynamic "setting" {
for_each = local.app_env
content {
namespace = "aws:elasticbeanstalk:application:environment"
name = setting.key
value = setting.value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment