Skip to content

Commit

Permalink
update chatbot,eb minsize,codebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
coval3nte committed Nov 21, 2021
1 parent 548aa85 commit bef6cab
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugin "aws" {
enabled = true
}
2 changes: 1 addition & 1 deletion beanstalk/chatbot.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ resource "aws_codestarnotifications_notification_rule" "sellix-web-app-codestarn
"codepipeline-pipeline-manual-approval-succeeded",
]
target {
address = data.terraform_remote_state.sellix-web-app-chatbot-terraform-state.outputs.chatbot_arn
address = data.terraform_remote_state.sellix-web-app-chatbot-terraform-state.outputs["${var.aws_region}_chatbot-arn"]
}
}
2 changes: 1 addition & 1 deletion beanstalk/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data "aws_iam_policy_document" "sellix-web-app-service-sns-policy-document" {
"sns:Publish"
]
resources = [
data.terraform_remote_state.sellix-web-app-chatbot-terraform-state.outputs.chatbot_arn,
data.terraform_remote_state.sellix-web-app-chatbot-terraform-state.outputs["${var.aws_region}_chatbot-arn"],
"arn:aws:sns:eu-west-1:671586216466:ElasticBeanstalkNotifications*"
]
effect = "Allow"
Expand Down
21 changes: 10 additions & 11 deletions beanstalk/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ locals {
}
env = {
ELASTIC_BEANSTALK_PORT = 8080
DOMAIN = local.production ? "sellix.io" : "sellix.gg"
ENVIRONMENT = local.production ? "production" : "staging"
DOMAIN = var.is_production ? "sellix.io" : "sellix.gg"
ENVIRONMENT = var.is_production ? "production" : "staging"
}
production = contains(["prod"], substr(terraform.workspace, 0, 4)) ? true : false
notification_topic_arn = { for s in aws_elastic_beanstalk_environment.sellix-web-app-environment.all_settings :
s.name => s.value if s.namespace == "aws:elasticbeanstalk:sns:topics" && s.name == "Notification Topic ARN" }
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
Expand All @@ -30,7 +29,7 @@ locals {
{
namespace = "aws:ec2:vpc"
name = "Subnets"
value = join(",", sort(aws_subnet.sellix-web-app-private-subnet.*.id))
value = var.is_production ? join(",", sort(aws_subnet.sellix-web-app-private-subnet.*.id)) : aws_subnet.sellix-web-app-private-subnet[0].id
},
{
namespace = "aws:ec2:vpc"
Expand Down Expand Up @@ -166,7 +165,7 @@ locals {
value = "600"
},
]
traffic_splitting = local.production ? [
traffic_splitting = var.is_production ? [
{
namespace = "aws:elasticbeanstalk:trafficsplitting"
name = "EvaluationTime"
Expand Down Expand Up @@ -215,7 +214,7 @@ locals {
{
namespace = "aws:elbv2:listener:443"
name = "SSLCertificateArns"
value = local.production ? var.ssl_arn[var.aws_region]["production"] : var.ssl_arn[var.aws_region]["staging"]
value = var.is_production ? var.ssl_arn[var.aws_region]["production"] : var.ssl_arn[var.aws_region]["staging"]
},
{
namespace = "aws:elbv2:loadbalancer"
Expand All @@ -242,7 +241,7 @@ locals {
{
namespace = "aws:autoscaling:launchconfiguration"
name = "InstanceType"
value = local.production ? "m5.large" : "t3.micro"
value = var.is_production ? "m5.large" : "t3.micro"
},
{
namespace = "aws:autoscaling:launchconfiguration"
Expand All @@ -252,7 +251,7 @@ locals {
{
namespace = "aws:autoscaling:launchconfiguration"
name = "RootVolumeSize"
value = local.production ? "50" : "10"
value = var.is_production ? "50" : "10"
},
{
namespace = "aws:autoscaling:launchconfiguration"
Expand All @@ -279,17 +278,17 @@ locals {
{
namespace = "aws:autoscaling:asg"
name = "MinSize"
value = "2"
value = var.is_production ? "2" : "1"
},
{
namespace = "aws:autoscaling:asg"
name = "MaxSize"
value = local.production ? "10" : "5"
value = var.is_production ? "10" : "5"
},
{
namespace = "aws:autoscaling:updatepolicy:rollingupdate"
name = "RollingUpdateType"
value = local.production ? "Health" : "Immutable"
value = var.is_production ? "Health" : "Immutable"
},
{
namespace = "aws:autoscaling:updatepolicy:rollingupdate"
Expand Down
2 changes: 1 addition & 1 deletion beanstalk/pipeline.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ resource "aws_codebuild_project" "sellix-web-app" {
environment {
type = "LINUX_CONTAINER"
compute_type = "BUILD_GENERAL1_LARGE"
image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
image = "aws/codebuild/standard:5.0"
image_pull_credentials_type = "CODEBUILD"
privileged_mode = false
}
Expand Down
5 changes: 5 additions & 0 deletions beanstalk/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ variable "ssl_arn" {
variable "codestar_connection_arn" {
description = "CodeStar Connection ARN"
default = null
}

variable "is_production" {
description = "Environment Boolean"
default = true
}
16 changes: 8 additions & 8 deletions beanstalk/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource "aws_vpc" "sellix-web-app-vpc" {
}

resource "aws_eip" "sellix-web-app-eip" {
count = local.production ? length(local.availability_zones) : 1
count = var.is_production ? length(local.availability_zones) : 1
vpc = "true"
tags = merge({
"Name" = "${local.tags["Project"]}-eip-${element(local.availability_zones, count.index)}"
Expand All @@ -25,7 +25,7 @@ resource "aws_eip" "sellix-web-app-eip" {
}

resource "aws_subnet" "sellix-web-app-public-subnet" {
count = local.production ? length(local.availability_zones) : 1
count = length(local.availability_zones)
vpc_id = aws_vpc.sellix-web-app-vpc.id
availability_zone = element(local.availability_zones, count.index)
cidr_block = cidrsubnet(
Expand All @@ -42,7 +42,7 @@ resource "aws_subnet" "sellix-web-app-public-subnet" {
}

resource "aws_subnet" "sellix-web-app-private-subnet" {
count = local.production ? length(local.availability_zones) : 1
count = length(local.availability_zones)
vpc_id = aws_vpc.sellix-web-app-vpc.id
availability_zone = element(local.availability_zones, count.index)
cidr_block = cidrsubnet(
Expand All @@ -59,7 +59,7 @@ resource "aws_subnet" "sellix-web-app-private-subnet" {
}

resource "aws_nat_gateway" "sellix-web-app-nat-gateway" {
count = local.production ? length(local.availability_zones) : 1
count = var.is_production ? length(local.availability_zones) : 1
allocation_id = element(aws_eip.sellix-web-app-eip.*.id, count.index)
subnet_id = element(aws_subnet.sellix-web-app-public-subnet.*.id, count.index)
tags = merge({
Expand Down Expand Up @@ -95,7 +95,7 @@ resource "aws_route_table" "sellix-web-app-public-route-table" {
}

resource "aws_route_table" "sellix-web-app-private-route-table" {
count = local.production ? length(local.availability_zones) : 1
count = var.is_production ? length(local.availability_zones) : 1
vpc_id = aws_vpc.sellix-web-app-vpc.id
route {
cidr_block = "0.0.0.0/0"
Expand All @@ -118,13 +118,13 @@ resource "aws_route" "sellix-web-app-route" {
}

resource "aws_route_table_association" "sellix-web-app-public-route-table-association" {
count = local.production ? length(local.availability_zones) : 1
count = length(local.availability_zones)
subnet_id = element(aws_subnet.sellix-web-app-public-subnet.*.id, count.index)
route_table_id = aws_route_table.sellix-web-app-public-route-table.id
}

resource "aws_route_table_association" "sellix-web-app-private-route-table-association" {
count = local.production ? length(local.availability_zones) : 1
count = length(local.availability_zones)
subnet_id = element(aws_subnet.sellix-web-app-private-subnet.*.id, count.index)
route_table_id = local.production ? element(aws_route_table.sellix-web-app-private-route-table.*.id, count.index) : aws_route_table.sellix-web-app-private-route-table[0].id
route_table_id = var.is_production ? element(aws_route_table.sellix-web-app-private-route-table.*.id, count.index) : aws_route_table.sellix-web-app-private-route-table[0].id
}
9 changes: 8 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ provider "aws" {
secret_key = var.aws_secret_key
}

locals {
is_production = contains(["prod"], substr(terraform.workspace, 0, 4))
}

module "eu-west-1" {
source = "./beanstalk"
providers = {
Expand All @@ -43,9 +47,11 @@ module "eu-west-1" {
github_opts = var.github_opts
ssl_arn = var.ssl_arn
codestar_connection_arn = var.codestar_connection_arn
is_production = local.is_production
}

module "us-east-1" {
count = local.is_production ? 1 : 0
source = "./beanstalk"
providers = {
aws = aws.us-east-1
Expand All @@ -57,12 +63,13 @@ module "us-east-1" {
github_opts = var.github_opts
ssl_arn = var.ssl_arn
codestar_connection_arn = var.codestar_connection_arn
is_production = local.is_production
}

output "eu-west-1_eb-cname" {
value = module.eu-west-1.eb_cname
}

output "us-east-1_eb-cname" {
value = module.us-east-1.eb_cname
value = module.us-east-1.*.eb_cname
}

0 comments on commit bef6cab

Please sign in to comment.