Commit 7fac1731 authored by Seweryn Zeman's avatar Seweryn Zeman 🎪
Browse files

Merge branch 'dev-vpc' into 'master'

Bugfix: fix vpc subnets variable type to map

See merge request !1
parents 3fa5c02f cc5372f8
locals {
subnet_nums = ["a", "b", "c"]
subnet_ids = [for v in local.subnet_nums : var.jz_vpc.subnets[v].id]
# Mapping of NLB listeners from config port_mapping.
listeners = {
for i, z in var.port_mapping :
z.nlb_port => {
app_port = z.app_port
app_protocol = upper(z.app_protocol)
nlb_port = z.nlb_port
nlb_protocol = upper(z.nlb_protocol)
is_secure = upper(z.nlb_protocol) == "TLS"
}...
}
# Mapping of NLB target groups from config port_mapping.
target_groups = {
for i, z in var.port_mapping :
z.app_port => {
app_port = z.app_port
app_protocol = upper(z.app_protocol)
}...
}
# TGs * instances
instance_ids_flatten = flatten([
var.jz_swarm_project.instance_ids.leader,
var.jz_swarm_project.instance_ids.managers.*,
var.jz_swarm_project.instance_ids.workers.*]
)
target_group_arns = values(aws_lb_target_group.default).*.arn
tg_x_instance = setproduct(local.target_group_arns, local.instance_ids_flatten)
}
resource "aws_lb" "default" {
load_balancer_type = "network"
name = "${var.name}-${var.env}-nlb"
subnets = var.jz_vpc.subnets.*.id
subnets = local.subnet_ids
enable_deletion_protection = true
......@@ -17,36 +17,6 @@ resource "aws_lb" "default" {
}
}
locals {
# Mapping of NLB listeners from config port_mapping.
listeners = {
for i, z in var.port_mapping:
z.nlb_port => {
app_port = z.app_port
app_protocol = upper(z.app_protocol)
nlb_port = z.nlb_port
nlb_protocol = upper(z.nlb_protocol)
is_secure = upper(z.nlb_protocol) == "TLS"
}...
}
# Mapping of NLB target groups from config port_mapping.
target_groups = {
for i, z in var.port_mapping:
z.app_port => {
app_port = z.app_port
app_protocol = upper(z.app_protocol)
}...
}
# TGs * instances
instance_ids_flatten = flatten([
var.jz_swarm_project.instance_ids.leader,
var.jz_swarm_project.instance_ids.managers.*,
var.jz_swarm_project.instance_ids.workers.*]
)
target_group_arns = values(aws_lb_target_group.default).*.arn
tg_x_instance = setproduct(local.target_group_arns, local.instance_ids_flatten)
}
resource "aws_lb_listener" "default" {
for_each = local.listeners
......@@ -65,16 +35,16 @@ resource "aws_lb_listener" "default" {
resource "aws_lb_target_group" "default" {
for_each = local.target_groups
name = "${var.name}-${var.env}-${each.key}-${each.value[0].app_protocol}-tg"
vpc_id = var.jz_vpc.self.id
name = "${var.name}-${var.env}-${each.key}-${each.value[0].app_protocol}-tg"
vpc_id = var.jz_vpc.self.id
port = each.value[0].app_port
protocol = each.value[0].app_protocol
health_check {
enabled = true
port = var.health_check_port
protocol = each.value[0].app_protocol
enabled = true
port = var.health_check_port
protocol = each.value[0].app_protocol
}
}
......
......@@ -9,17 +9,17 @@ variable "env" {
}
variable "jz_vpc" {
type = object({
self = object({
type = object({
self = object({
id = string
})
subnets = list(any)
subnets = map(any)
})
description = "A reference to jz_vpc module."
}
variable "jz_swarm_project" {
type = object({
type = object({
instance_ids = object({
leader = string
managers = set(string)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment