Skip to content

Commit

Permalink
setup shared environment
Browse files Browse the repository at this point in the history
  • Loading branch information
fideloper committed Sep 21, 2021
1 parent c2baa16 commit 9bd580c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
20 changes: 14 additions & 6 deletions modules/codebuild/main.tf
@@ -1,10 +1,18 @@
resource "aws_s3_bucket" "artifacts" {
bucket = "cloudcasts-${var.infra_env}-artifacts"
bucket = "cloudcasts-artifacts"
acl = "private"

tags = {
Name = "cloudcasts - Artifacts Bucket"
Environment = var.infra_env
Project = "cloudcasts"
Role = "build"
ManagedBy = "terraform"
}
}

resource "aws_iam_role" "this" {
name = "cloudcasts-${var.infra_env}-codebuild-role"
name = "cloudcasts-codebuild-role"

assume_role_policy = <<EOF
{
Expand Down Expand Up @@ -69,7 +77,7 @@ POLICY
}

resource "aws_codebuild_project" "this" {
name = "cloudcasts-${var.infra_env}-app-builder"
name = "cloudcasts-app-builder"
description = "Building CloudCasts Sample App"
service_role = aws_iam_role.this.arn

Expand All @@ -96,13 +104,13 @@ resource "aws_codebuild_project" "this" {

logs_config {
cloudwatch_logs {
group_name = "codebuild/cloudcasts/${var.infra_env}"
group_name = "codebuild/cloudcasts"
stream_name = "builds"
}

// s3_logs {
// status = "ENABLED"
// location = "${aws_s3_bucket.artifacts.id}/${var.infra_env}-build-log"
// location = "${aws_s3_bucket.artifacts.id}/build-log"
// }
}

Expand All @@ -114,7 +122,7 @@ resource "aws_codebuild_project" "this" {
}

tags = {
Name = "cloudcasts - ${var.infra_env} - App Builder"
Name = "cloudcasts - App Builder"
Environment = var.infra_env
Project = "cloudcasts"
Role = "build"
Expand Down
6 changes: 3 additions & 3 deletions modules/ec2/asg.tf
Expand Up @@ -7,9 +7,9 @@ resource "aws_autoscaling_group" "this" {
name = "cloudcasts-${var.infra_env}-${var.infra_role}-asg"
vpc_zone_identifier = var.asg_subnets

min_size = 0
max_size = 5
desired_capacity = 2
min_size = var.min_size # 0
max_size = var.max_size # 5
desired_capacity = var.desired_capacity # 2
termination_policies = ["OldestInstance"]

health_check_type = var.infra_role == "http" ? "ELB" : "EC2"
Expand Down
15 changes: 15 additions & 0 deletions modules/ec2/variables.tf
Expand Up @@ -71,4 +71,19 @@ variable "vpc_id" {
variable "artifact_bucket" {
type = string
description = "Application artifact bucket"
}

variable "min_size" {
type = number
description = "ASG minimum size"
}

variable "max_size" {
type = number
description = "ASG maximum size"
}

variable "desired_capacity" {
type = number
description = "ASG desired capacity"
}
8 changes: 4 additions & 4 deletions production/main.tf
Expand Up @@ -80,7 +80,7 @@ data "aws_ami" "app" {
# Resources
##
module "vpc" {
source = "./modules/vpc"
asource = "../modules/vpc"

infra_env = var.infra_env
vpc_cidr = "10.0.0.0/17"
Expand All @@ -90,7 +90,7 @@ module "vpc" {
}

module "autoscale_web" {
source = "./modules/ec2"
asource = "../modules/ec2"

ami = data.aws_ami.app.id
git_url = var.git_url
Expand All @@ -108,7 +108,7 @@ module "autoscale_web" {
}

module "autoscale_queue" {
source = "./modules/ec2"
asource = "../modules/ec2"

ami = data.aws_ami.app.id
git_url = var.git_url
Expand All @@ -125,7 +125,7 @@ module "autoscale_queue" {
}

module "deploy_app" {
source = "./modules/codedeploy"
asource = "../modules/codedeploy"

infra_env = var.infra_env
deploy_groups = {
Expand Down
8 changes: 4 additions & 4 deletions staging/main.tf
Expand Up @@ -80,7 +80,7 @@ data "aws_ami" "app" {
# Resources
##
module "vpc" {
source = "./modules/vpc"
asource = "../modules/vpc"

infra_env = var.infra_env
vpc_cidr = "10.0.0.0/17"
Expand All @@ -90,7 +90,7 @@ module "vpc" {
}

module "autoscale_web" {
source = "./modules/ec2"
asource = "../modules/ec2"

ami = data.aws_ami.app.id
git_url = var.git_url
Expand All @@ -108,7 +108,7 @@ module "autoscale_web" {
}

module "autoscale_queue" {
source = "./modules/ec2"
asource = "../modules/ec2"

ami = data.aws_ami.app.id
git_url = var.git_url
Expand All @@ -125,7 +125,7 @@ module "autoscale_queue" {
}

module "deploy_app" {
source = "./modules/codedeploy"
asource = "../modules/codedeploy"

infra_env = var.infra_env
deploy_groups = {
Expand Down

0 comments on commit 9bd580c

Please sign in to comment.