Skip to content

Commit

Permalink
terrarium-generate-code
Browse files Browse the repository at this point in the history
  • Loading branch information
akashcldcvr authored and Akash Jaiswal committed Oct 5, 2023
1 parent 5043037 commit 8ef2d85
Show file tree
Hide file tree
Showing 15 changed files with 971 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .terrarium-output/modules/modules/alb/alb_main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 8.7"

for_each = var.tf_component_lb

name = "${var.extract_resource_name}-alb"

create_lb = local.tr_web_service == true ? true : false

load_balancer_type = each.value.load_balancer_type
create_security_group = true

vpc_id = var.vpc_id
subnets = var.public_subnet_ids
security_groups = var.security_group_ids

access_logs = {
bucket = module.s3_bucket[each.key].s3_bucket_id
}

security_group_rules = [
{
type = "ingress"
from_port = 80
to_port = 80
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
},
{
type = "ingress"
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
},
{
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
]


target_groups = [
for service_key, service_value in var.tr_component_ecs_services : {
name_prefix = substr("${service_key}",0,6)
backend_protocol = "HTTP"
backend_port = try(service_value.port, null)
target_type = "ip"
}
if try(service_value.port, null) != null
]

https_listeners = [
{
port = 443
protocol = "HTTPS"
certificate_arn = each.value.certificate_arn
target_group_index = 0
}
]

http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
action_type = "redirect"
redirect = {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
]

tags = {
Environment = "Test"
}
}

resource "random_id" "bucket_suffix" {
byte_length = 4
keepers = {
bucket_base_name = var.extract_resource_name
}
}

module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "3.14.0"

for_each = var.tf_component_lb

bucket = "${var.extract_resource_name}-alb-logs-${random_id.bucket_suffix.hex}"
acl = "log-delivery-write"

# Allow deletion of non-empty bucket
force_destroy = var.environment == "production" || var.environment == "prod" ? false : true

control_object_ownership = true
object_ownership = "ObjectWriter"

attach_elb_log_delivery_policy = true # Required for ALB logs
attach_lb_log_delivery_policy = true # Required for ALB/NLB logs
}

29 changes: 29 additions & 0 deletions .terrarium-output/modules/modules/alb/alb_outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "alb_names" {
value = [for k, v in module.alb : v.name]
description = "A list of the names of the ALBs that were created."
}

output "alb_dns_names" {
value = [for k, v in module.alb : v.dns_name]
description = "A list of the DNS names of the ALBs that were created."
}

output "alb_arns" {
value = [for k, v in module.alb : v.arn]
description = "A list of the ARNs of the ALBs that were created."
}

output "alb_security_group_ids" {
value = [for k, v in module.alb : v.security_group_id]
description = "A list of the security group IDs of the ALBs that were created."
}

output "alb_target_group_arns" {
value = module.alb.alb_target_group_arns
description = "A list of the ARNs of the target groups associated with the ALBs."
}

output "alb_log_bucket_names" {
value = [for k, v in module.s3_bucket : v.bucket]
description = "A list of the names of the S3 buckets used for ALB access logs."
}
34 changes: 34 additions & 0 deletions .terrarium-output/modules/modules/alb/alb_varibles.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "extract_resource_name" {
type = string
description = "The base name to use for all resources created by this module."
}

variable "environment" {
type = string
description = "The environment in which the infrastructure is being deployed (e.g. dev, prod, etc.)."
}

variable "tf_component_lb" {
type = any
description = "A map of objects that define the load balancers to create."
}

variable "tr_component_ecs_services" {
type = any
description = "A map of objects that define the ECS services to create."
}

variable "vpc_id" {
type = string
description = "The ID of the VPC in which to create the load balancer."
}

variable "public_subnet_ids" {
type = any
description = "A list of IDs of the public subnets in which to create the load balancer."
}

variable "security_group_ids" {
type = any
description = "A list of IDs of the security groups to associate with the load balancer."
}
Loading

0 comments on commit 8ef2d85

Please sign in to comment.