use the CloudPosse modules for ElasicBeanstalk environment

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-07-25 17:05:05 -04:00
parent 7b3a0eb812
commit 8f2b2974b5
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
7 changed files with 103 additions and 84 deletions

5
db.tf
View File

@ -1,8 +1,3 @@
resource "aws_key_pair" "admin" {
key_name = "admin-key"
public_key = "${file("files/admin.pub")}"
}
data "aws_ami" "ubuntu" {
filter {
name = "name"

13
main.tf
View File

@ -53,6 +53,13 @@ resource "gandi_domainattachment" "dap_ps" {
zone = "${gandi_zone.dap_ps_zone.id}"
}
/* ACCESS ---------------------------------------*/
resource "aws_key_pair" "admin" {
key_name = "admin-key"
public_key = "${file("files/admin.pub")}"
}
/* ENVIRONMENTS ---------------------------------*/
module "dev" {
@ -60,7 +67,9 @@ module "dev" {
name = "dev-dap-ps"
gandi_zone_id = "${gandi_zone.dap_ps_zone.id}"
dns_domain = "dap.ps"
dns_entry = "dev"
stage = "dev"
stack_name = "${var.stack_name}"
keypair_name = "${aws_key_pair.admin.key_name}"
}
module "prod" {
@ -68,7 +77,7 @@ module "prod" {
name = "prod-dap-ps"
gandi_zone_id = "${gandi_zone.dap_ps_zone.id}"
dns_domain = "dap.ps"
dns_entry = "@" /* just means use `dap.ps` */
dns_entry = "prod" /* just means use `dap.ps` */
}
/* MAIN SITE ------------------------------------*/

View File

@ -7,7 +7,7 @@ resource "aws_iam_group" "deploy" {
resource "aws_iam_user" "deploy" {
name = "${var.name}-deploy"
tags = {
Description = "User for deploying the ${var.dns_entry}.${var.dns_domain} Elastic Beanstalk app"
Description = "User for deploying the ${var.stage}.${var.dns_domain} Elastic Beanstalk app"
}
}
@ -25,37 +25,3 @@ resource "aws_iam_group_policy_attachment" "deploy" {
group = "${aws_iam_group.deploy.name}"
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkFullAccess"
}
/* ROLES ----------------------------------------*/
resource "aws_iam_instance_profile" "main" {
name = "${var.name}"
role = "${aws_iam_role.main.name}"
}
resource "aws_iam_role" "main" {
name = "${var.name}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "AWSElasticBeanstalkWebTier" {
name = "${var.name}-AWSElasticBeanstalkWebTier"
roles = ["${aws_iam_role.main.name}"]
policy_arn ="arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier"
}

View File

@ -1,28 +1,58 @@
/* RESOURCES ------------------------------------*/
resource "aws_elastic_beanstalk_application" "dev_dap_ps" {
name = "dev-dap-ps-app"
description = "dev.dap.ps application"
locals {
fqdn = "${var.stage}.${var.dns_domain}"
}
resource "aws_elastic_beanstalk_environment" "dev_dap_ps" {
name = "dev-dap-ps-app"
application = "${aws_elastic_beanstalk_application.dev_dap_ps.name}"
solution_stack_name = "64bit Amazon Linux 2018.03 v4.8.3 running Node.js"
data "aws_availability_zones" "available" {}
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "${aws_iam_instance_profile.main.name}"
}
module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=0.4.1"
namespace = ""
stage = "dev"
name = "test"
cidr_block = "10.0.0.0/16"
}
module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=0.12.0"
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
namespace = ""
stage = "${var.stage}"
name = "${local.fqdn}"
vpc_id = "${module.vpc.vpc_id}"
igw_id = "${module.vpc.igw_id}"
cidr_block = "${module.vpc.vpc_cidr_block}"
nat_gateway_enabled = "true"
}
module "eb_application" {
source = "git::https://github.com/cloudposse/terraform-aws-elastic-beanstalk-application.git?ref=0.1.6"
name = "${replace(var.dns_domain, ".", "-")}-eb-app"
description = "${local.fqdn} application"
stage = "${var.stage}"
namespace = ""
}
module "eb_environment" {
source = "git::https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment.git?ref=0.13.0"
description = "Dapp Discovery Store - ${local.fqdn}"
name = "${replace(var.dns_domain, ".", "-")}-eb-app"
stage = "${var.stage}"
namespace = ""
solution_stack_name = "${var.stack_name}"
keypair = "${var.keypair_name}"
app = "${module.eb_application.app_name}"
vpc_id = "${module.vpc.vpc_id}"
public_subnets = "${module.subnets.public_subnet_ids}"
private_subnets = "${module.subnets.private_subnet_ids}"
security_groups = ["${module.vpc.vpc_default_security_group_id}"]
}
/* DNS ------------------------------------------*/
resource "gandi_zonerecord" "dev_dap_ps_site" {
resource "gandi_zonerecord" "main" {
zone = "${var.gandi_zone_id}"
name = "${var.dns_entry}"
name = "${var.stage}"
type = "CNAME"
ttl = 3600
values = ["${aws_elastic_beanstalk_environment.dev_dap_ps.cname}."]
values = ["${module.eb_environment.elb_load_balancers}"]
}

View File

@ -2,6 +2,10 @@ variable "name" {
description = "Name of this environment to be used in all resources."
}
variable "stage" {
description = "Name of stage, used for DNS entry for this environment."
}
variable "gandi_zone_id" {
description = "ID of the zone in Gandi DNS registrar."
}
@ -10,6 +14,15 @@ variable "dns_domain" {
description = "Name of domain for this environment."
}
variable "dns_entry" {
description = "Name of DNS entry for this environment."
variable "stack_name" {
description = "Name of application stack for ElasticBeanstalk."
}
variable "keypair_name" {
description = "Name of the AWS key pair for SSH access."
}
variable "max_availability_zones" {
description = "Maximum number of availability zones that can be used in Subnet."
default = "2"
}

View File

@ -20,29 +20,29 @@ resource "aws_acm_certificate_validation" "prod" {
/* RESOURCES ------------------------------------*/
resource "aws_elastic_beanstalk_application" "dev_dap_ps" {
name = "dev-dap-ps-app"
description = "dev.dap.ps application"
}
resource "aws_elastic_beanstalk_environment" "dev_dap_ps" {
name = "dev-dap-ps-app"
application = "${aws_elastic_beanstalk_application.dev_dap_ps.name}"
solution_stack_name = "64bit Amazon Linux 2018.03 v4.8.3 running Node.js"
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "${aws_iam_instance_profile.main.name}"
}
}
//resource "aws_elastic_beanstalk_application" "dev_dap_ps" {
// name = "dev-dap-ps-app"
// description = "dev.dap.ps application"
//}
//
//resource "aws_elastic_beanstalk_environment" "dev_dap_ps" {
// name = "dev-dap-ps-app"
// application = "${aws_elastic_beanstalk_application.dev_dap_ps.name}"
// solution_stack_name = "64bit Amazon Linux 2018.03 v4.8.3 running Node.js"
//
// setting {
// namespace = "aws:autoscaling:launchconfiguration"
// name = "IamInstanceProfile"
// value = "${aws_iam_instance_profile.main.name}"
// }
//}
/* DNS ------------------------------------------*/
resource "gandi_zonerecord" "dev_dap_ps_site" {
zone = "${var.gandi_zone_id}"
name = "${var.dns_entry}"
type = "CNAME"
ttl = 3600
values = ["${aws_elastic_beanstalk_environment.dev_dap_ps.cname}."]
}
//resource "gandi_zonerecord" "dev_dap_ps_site" {
// zone = "${var.gandi_zone_id}"
// name = "${var.dns_entry}"
// type = "CNAME"
// ttl = 3600
// values = ["${aws_elastic_beanstalk_environment.dev_dap_ps.cname}."]
//}

View File

@ -56,6 +56,12 @@ variable ssh_user {
default = "ubuntu"
}
variable stack_name {
description = "Elastic Beanstalk stack, e.g. Docker, Go, Node, Java, IIS."
default = "64bit Amazon Linux 2018.03 v4.8.3 running Node.js"
/* http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html */
}
/* DEV Dap.ps -----------------------------------*/
variable dap_ps_app_bucket_name {