Skip to content

Commit

Permalink
root level tf and example refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-singh1 committed Nov 27, 2024
1 parent 4888bfe commit f3cfff7
Show file tree
Hide file tree
Showing 26 changed files with 262 additions and 1,047 deletions.
110 changes: 0 additions & 110 deletions .terraform.lock.hcl

This file was deleted.

3 changes: 3 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "aws_security_group" "proxy" {
id = var.proxy_security_group
}
2 changes: 1 addition & 1 deletion example/container/container_definition.json.tftpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "${service_name_full}",
"name": "${service_name}",
"image": "${repository_name}:${environment}",
"essential": true,
"portMappings": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:GetParameters"
],
"Resource": "*"
}
]
}
# this will contain a sample policy to be attached to task role in json format, for example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:GetParameters"
],
"Resource": "*"
}
]
}
5 changes: 2 additions & 3 deletions example/locals.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
locals {
cluster_name_full = "${var.cluster_name}-${var.environment}"
service_name_full = "${var.service_name}-${var.environment}"
sqs_queue_name_full = "${var.sqs_queue_name}-${var.environment}"
cluster_name_full = "${var.ecs.cluster_name}-${var.environment}"
service_name_full = "${var.ecs.service_name}-${var.environment}"
}
60 changes: 26 additions & 34 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
## defaults
################################################################################
terraform {
required_version = ">= 1.3, < 2.0.0"
required_version = ">= 1.4, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
version = ">= 4.0, < 6.0"
}
}
}
Expand All @@ -21,7 +21,7 @@ module "tags" {
version = "1.2.3"

environment = var.environment
project = var.project_name
project = var.project

extra_tags = {
Example = "True"
Expand All @@ -42,62 +42,54 @@ module "ecs" {
proxy_security_group = data.aws_security_group.group.id

ecs = {
cluster_name = var.cluster_name
service_name = var.service_name
service_name_short = var.service_name_short
repository_name = var.repository_name
cluster_name = var.ecs.cluster_name
service_name = var.ecs.service_name
repository_name = var.ecs.repository_name
}

task = {
tasks_desired = var.tasks_desired_min

container_port = var.container_port
container_health_check_path = var.container_health_check_path

container_vcpu = 1024
container_memory = 2048
tasks_desired = var.task.tasks_desired
container_vcpu = var.task.container_vcpu
container_memory = var.task.container_memory
container_port = var.task.container_port
container_definition = var.task.container_definition

environment_variables = {
PORT = var.container_port
URL_EXPIRE_SECONDS = "3600"
PORT = var.task.container_port
}

container_definition = "container/container_definition.json.tftpl"
}

alb = {
name = "service-alb-${var.environment}"
listener_port = var.alb_port
deregistration_delay = var.deregistration_delay
name = var.alb.name
listener_port = var.alb.alb_port
deregistration_delay = var.alb.deregistration_delay
}

autoscaling = {
metric_name = "CPUUtilization"
minimum_capacity = var.tasks_desired_min
maximum_capacity = var.tasks_desired_max
metric_name = var.autosclaing.metric_name
minimum_capacity = var.autosclaing.tasks_desired_min
maximum_capacity = var.autosclaing.tasks_desired_min

dimensions = {
ClusterName = local.cluster_name_full
ServiceName = local.service_name_full
}

scale_up = {
threshold = "85"
cooldown = "60"
threshold = var.autoscaling.scale_up.threshold
cooldown = var.autoscaling.scale_up.cooldown
step_adjustment = [{
metric_interval_lower_bound = 0
scaling_adjustment = 1
metric_interval_lower_bound = var.autoscaling.scale_up.step_adjustment.metric_interval_lower_bound
scaling_adjustment = var.autoscaling.scale_up.step_adjustment.scaling_adjustment
}]
}
scale_down = {
threshold = "20"
cooldown = "60"
threshold = var.autoscaling.scale_down.threshold
cooldown = var.autoscaling.scale_down.cooldown
step_adjustment = [{
metric_interval_lower_bound = 0
scaling_adjustment = -1
metric_interval_lower_bound = var.autoscaling.scale_down.step_adjustment.metric_interval_lower_bound
scaling_adjustment = var.autoscaling.scale_down.step_adjustment.scaling_adjustment
}]
}
}

tags = module.tags.tags
}
95 changes: 58 additions & 37 deletions example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,75 @@ variable "project" {
description = "The project to use"
}

variable "service_name" {
type = string
description = "The base name of the service (basically service name minus the environment)"
}

variable "cluster_name" {
type = string
description = "The base name of the cluster"
}

variable "region" {
type = string
description = "The region being deployed to"
default = "us-east-1"
}

variable "container_port" {
type = number
description = "The port proxy-hydrator listen on in the container"
}

variable "container_health_check_path" {
type = string
description = "The path that the ALB should use to conduct a health check"
}

variable "repository_name" {
type = string
description = "The repository to use for the hydrator image"
# ECS-specific variables
variable "ecs" {
type = object({
cluster_name = string
service_name = string
service_name_short = string
service_name_tag = string
repository_name = string
})
description = "The ECS-specific values to use such as cluster, service, and repository names."
}

variable "alb_port" {
type = number
description = "The port the ALB will listen on"
# Task-specific variables
variable "task" {
type = object({
tasks_desired = optional(number)
container_vcpu = optional(number)
container_memory = optional(number)
container_port = number
container_health_check_path = optional(string)
container_definition = optional(string)
environment_variables = optional(map(string))
task_execution_role = optional(string)
})
description = "Task-related information (vCPU, memory, # of tasks, port, and health check info.)"
}

variable "deregistration_delay" {
type = number
description = "The amount of time to wait before changing the status of a target from draining to unused"
# Autoscaling parameters
variable "autoscaling" {
type = object({
namespace = optional(string)
scale_up = object({
evaluation_periods = optional(string)
period = optional(string)
threshold = string
comparison_operator = optional(string)
statistic = optional(string)
cooldown = string
step_adjustment = list(map(number))
})
scale_down = object({
evaluation_periods = optional(string)
period = optional(string)
threshold = string
comparison_operator = optional(string)
statistic = optional(string)
cooldown = string
step_adjustment = list(map(number))
})
dimensions = map(string)
metric_name = optional(string)
minimum_capacity = number
maximum_capacity = number
})
}

variable "tasks_desired_min" {
type = number
description = "The minimum number of tasks desired"
# Load balancer
variable "alb" {
type = object({
name = string
listener_port = number
deregistration_delay = optional(number)
})
description = "ALB-related information (listening port, internal, and deletion protection.)"
}

variable "tasks_desired_max" {
type = number
description = "The maximum number of tasks desired"
}

Loading

0 comments on commit f3cfff7

Please sign in to comment.