Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jlkan committed May 28, 2024
1 parent ea0b59e commit bae357d
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
85 changes: 85 additions & 0 deletions examples/ecs-app/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions examples/ecs-app/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
resource "random_id" "example" {
byte_length = 4

prefix = "ec2-"
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 4.0"

name = random_id.example.hex
cidr = "10.0.0.0/16"

azs = ["eu-central-1a", "eu-central-1b"]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]

single_nat_gateway = true
enable_nat_gateway = false
enable_vpn_gateway = false
}

module "cluster" {
source = "../../modules/ecs-cluster"

context = {
namespace = "selleo"
stage = "dev"
name = "example"
}

name_prefix = random_id.example.hex
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnets
instance_type = "t3.nano"
lb_security_group_id = module.lb.security_group_id

autoscaling_group = {
min_size = 1
max_size = 5
desired_capacity = 1
}
}

module "lb" {
source = "Selleo/backend/aws//modules/load-balancer"
version = "0.23.0"

name = random_id.example.hex
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnets
force_https = false
}

module "service" {
source = "../../modules/ecs-service"

context = {
namespace = "selleo"
stage = "dev"
name = "example"
}

name = random_id.example.hex
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnets
cluster_id = module.cluster.id
desired_count = 1
secrets = ["/example/staging/api/terraform"]

port = 3000
depends_on = [module.secrets]
}

resource "aws_alb_listener" "http" {
load_balancer_arn = module.lb.id
port = 80
protocol = "HTTP"

default_action {
target_group_arn = module.service.lb_target_group_id
type = "forward"
}
}

module "secrets" {
source = "Selleo/ssm/aws//modules/parameters"
version = "0.4.0"

context = {
namespace = "example"
stage = "staging"
name = "api"
}

secrets = {
APP_ENV = "staging"
}
}

output "lb_dns" {
value = "http://${module.lb.dns_name}"
}
15 changes: 15 additions & 0 deletions examples/ecs-app/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_version = "~> 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "eu-central-1"
}

0 comments on commit bae357d

Please sign in to comment.