Commit 4416e379 authored by andrewtcymmer's avatar andrewtcymmer Committed by GitHub

feat: Add custom subnet names (#816)

Co-authored-by: default avatarAnton Babenko <anton@antonbabenko.com>
parent 386de73a
repos: repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform - repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.75.0 rev: v1.76.0
hooks: hooks:
- id: terraform_fmt - id: terraform_fmt
- id: terraform_validate - id: terraform_validate
......
This diff is collapsed.
...@@ -31,6 +31,13 @@ module "vpc" { ...@@ -31,6 +31,13 @@ module "vpc" {
redshift_subnets = ["10.0.41.0/24", "10.0.42.0/24", "10.0.43.0/24"] redshift_subnets = ["10.0.41.0/24", "10.0.42.0/24", "10.0.43.0/24"]
intra_subnets = ["10.0.51.0/24", "10.0.52.0/24", "10.0.53.0/24"] intra_subnets = ["10.0.51.0/24", "10.0.52.0/24", "10.0.53.0/24"]
private_subnet_names = ["Private Subnet One", "Private Subnet Two"]
# public_subnet_names omitted to show default name generation for all three subnets
database_subnet_names = ["DB Subnet One"]
elasticache_subnet_names = ["Elasticache Subnet One", "Elasticache Subnet Two"]
redshift_subnet_names = ["Redshift Subnet One", "Redshift Subnet Two", "Redshift Subnet Three"]
intra_subnet_names = []
create_database_subnet_group = false create_database_subnet_group = false
manage_default_network_acl = true manage_default_network_acl = true
......
...@@ -370,9 +370,9 @@ resource "aws_subnet" "public" { ...@@ -370,9 +370,9 @@ resource "aws_subnet" "public" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.public_subnet_suffix}-%s", var.public_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.public_subnet_suffix}-%s", element(var.azs, count.index))
) )
}, },
var.tags, var.tags,
...@@ -397,9 +397,9 @@ resource "aws_subnet" "private" { ...@@ -397,9 +397,9 @@ resource "aws_subnet" "private" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.private_subnet_suffix}-%s", var.private_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.private_subnet_suffix}-%s", element(var.azs, count.index))
) )
}, },
var.tags, var.tags,
...@@ -425,9 +425,9 @@ resource "aws_subnet" "outpost" { ...@@ -425,9 +425,9 @@ resource "aws_subnet" "outpost" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.outpost_subnet_suffix}-%s", var.outpost_subnet_names[count.index],
var.outpost_az, format("${var.name}-${var.outpost_subnet_suffix}-%s", var.outpost_az)
) )
}, },
var.tags, var.tags,
...@@ -452,9 +452,9 @@ resource "aws_subnet" "database" { ...@@ -452,9 +452,9 @@ resource "aws_subnet" "database" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.database_subnet_suffix}-%s", var.database_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.database_subnet_suffix}-%s", element(var.azs, count.index), )
) )
}, },
var.tags, var.tags,
...@@ -495,9 +495,9 @@ resource "aws_subnet" "redshift" { ...@@ -495,9 +495,9 @@ resource "aws_subnet" "redshift" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.redshift_subnet_suffix}-%s", var.redshift_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.redshift_subnet_suffix}-%s", element(var.azs, count.index))
) )
}, },
var.tags, var.tags,
...@@ -536,9 +536,9 @@ resource "aws_subnet" "elasticache" { ...@@ -536,9 +536,9 @@ resource "aws_subnet" "elasticache" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.elasticache_subnet_suffix}-%s", var.elasticache_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.elasticache_subnet_suffix}-%s", element(var.azs, count.index))
) )
}, },
var.tags, var.tags,
...@@ -577,9 +577,9 @@ resource "aws_subnet" "intra" { ...@@ -577,9 +577,9 @@ resource "aws_subnet" "intra" {
tags = merge( tags = merge(
{ {
"Name" = format( Name = try(
"${var.name}-${var.intra_subnet_suffix}-%s", var.intra_subnet_names[count.index],
element(var.azs, count.index), format("${var.name}-${var.intra_subnet_suffix}-%s", element(var.azs, count.index))
) )
}, },
var.tags, var.tags,
......
...@@ -136,6 +136,48 @@ variable "private_subnet_suffix" { ...@@ -136,6 +136,48 @@ variable "private_subnet_suffix" {
default = "private" default = "private"
} }
variable "public_subnet_names" {
description = "Explicit values to use in the Name tag on public subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "private_subnet_names" {
description = "Explicit values to use in the Name tag on private subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "outpost_subnet_names" {
description = "Explicit values to use in the Name tag on outpost subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "intra_subnet_names" {
description = "Explicit values to use in the Name tag on intra subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "database_subnet_names" {
description = "Explicit values to use in the Name tag on database subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "redshift_subnet_names" {
description = "Explicit values to use in the Name tag on redshift subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "elasticache_subnet_names" {
description = "Explicit values to use in the Name tag on elasticache subnets. If empty, Name tags are generated."
type = list(string)
default = []
}
variable "outpost_subnet_suffix" { variable "outpost_subnet_suffix" {
description = "Suffix to append to outpost subnets name" description = "Suffix to append to outpost subnets name"
type = string type = string
......
Markdown is supported
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