Skip to content

Commit

Permalink
Redefine variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-pedro committed Mar 9, 2024
1 parent 2900be8 commit 264d9b4
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions env/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,44 @@ provider "aws" {

data "aws_availability_zones" "available" {}

data "aws_ecr_repository" "repository" {
name = local.ecs_container_name
}

locals {
app_name = "aluraflix"

# VPC
vpc_id = module.vpc.vpc_id
vpc_cidr = "10.0.0.0/16"
subnets = module.vpc.subnets
azs = slice(data.aws_availability_zones.available.names, 0, 2)

vpc_subnets = module.vpc.subnets
vpc_azs = slice(data.aws_availability_zones.available.names, 0, 2)

# Security Groups
sg_allow_http = module.vpc.sg_allow_http_id
sg_dafault = module.vpc.sg_default_id


# Auto Scalling
asg_arn = module.ec2.asg_arn

# Load Balancer
lb_target_group = module.ec2.lb_target_group
}

# Define ECS values
locals {
ecs_cluster_name = "cluster-${local.app_name}"
ecs_image_name = "aluraflix-api"
ecs_image_version = "latest"
ecs_image_repository = "590183733571.dkr.ecr.us-east-2.amazonaws.com"
ecs_image = "${local.ecs_image_repository}/${local.ecs_image_name}:${local.ecs_image_version}"
ecs_cluster_name = "cluster-${local.app_name}"
ecs_service_name = "service-${local.app_name}"
ecs_capacity_name = "capacity-provider-${local.app_name}"
ecs_container_name = "${local.app_name}-api"
ecs_image = "${data.aws_ecr_repository.repository.repository_url}:${data.aws_ecr_repository.repository.most_recent_image_tags[0]}"
}

module "vpc" {
source = "../../infra/vpc"

name = local.app_name
cidr = local.vpc_cidr
azs = local.azs
azs = local.vpc_azs
qtd_subnets = 2

tags = {
Expand All @@ -60,7 +68,7 @@ module "ec2" {
key = "ecs-prod"
instance_image = "ami-0017b31c3b5cc98fb"
vpc_id = local.vpc_id
subnets = local.subnets
subnets = local.vpc_subnets
sg_allow_http = local.sg_allow_http
sg_default = local.sg_dafault
cluster_name = local.ecs_cluster_name
Expand All @@ -77,11 +85,13 @@ module "ecs" {

name = local.app_name
image = local.ecs_image
container_name = local.ecs_image_name
container_name = local.ecs_container_name
cluster_name = local.ecs_cluster_name
service_name = local.ecs_service_name
capacity_name = local.ecs_capacity_name
asg_arn = local.asg_arn
lb_target_group = local.lb_target_group
subnets = local.subnets
subnets = local.vpc_subnets

tags = {
Terraform = "true"
Expand Down

0 comments on commit 264d9b4

Please sign in to comment.