diff --git a/README.md b/README.md index b808622..e7e789d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Below is an example how to call and use the module, kindly check the example fol ```hcl module "label" { - source = "github.com/obytes/terraform-aws-tag.git?ref=v1.0.7" + source = "github.com/obytes/terraform-aws-tag.git?ref=v1.0.8" project_name = "pto" region = "eu-west-2" environment = "qa" @@ -21,7 +21,7 @@ module "label" { } module "example1" { - source = "github.com/obytes/terraform-aws-vpc.git?ref=v1.0.8" + source = "github.com/obytes/terraform-aws-vpc.git?ref=v1.0.9" enabled = true prefix = module.label.id name = "vpc" diff --git a/examples/example.tf b/examples/example.tf index 96a462c..0630084 100644 --- a/examples/example.tf +++ b/examples/example.tf @@ -1,8 +1,10 @@ module "label" { - source = "github.com/obytes/terraform-aws-tag.git?ref=v1.0.7" + source = "github.com/obytes/terraform-aws-tag.git?ref=v1.0.8" project_name = "pto" region = "eu-west-2" environment = "qa" + company_name = "genius" + prefix_order = ["project_name", "company_name", "environment"] prefix_length_limit = 12 } @@ -10,7 +12,7 @@ module "example1" { source = "../" enabled = true prefix = module.label.id - name = "vpc" + delimiter = module.label.delimiter additional_tags = module.label.tags cidr_block = "172.16.0.0/18" enable_dns_hostnames = true diff --git a/main.tf b/main.tf index 32688a3..e788f03 100644 --- a/main.tf +++ b/main.tf @@ -4,7 +4,8 @@ locals { custom_default_security_group = var.create_custom_security_group && local.enabled ? true : false az_name_list = length(flatten(var.azs_list_names)) > 0 ? var.azs_list_names : data.aws_availability_zones.azs.names availability_zones = length(var.azs_list_names) > 0 ? var.azs_list_names : data.aws_availability_zones.azs.names - name = var.name != null ? join("-", [var.prefix, var.name]) : var.prefix + name = var.name != null ? join(var.delimiter, [var.prefix, var.name]) : var.prefix + delimiter = var.delimiter != null ? var.delimiter : "-" } @@ -93,7 +94,7 @@ resource "aws_vpc_dhcp_options" "_" { netbios_name_servers = var.vpc_dhcp_netbios_name_servers netbios_node_type = var.vpc_dhcp_netbios_node_type - tags = merge(var.additional_tags, tomap({ "Name" = join("-", [local.name, "dhcp-ops"]) })) + tags = merge(var.additional_tags, tomap({ "Name" = join(local.delimiter, [local.name, "dhcp-ops"]) })) } resource "aws_vpc_dhcp_options_association" "dhcp-assoc" { diff --git a/nat-gw.tf b/nat-gw.tf index b68810f..fee1fb4 100644 --- a/nat-gw.tf +++ b/nat-gw.tf @@ -9,14 +9,14 @@ locals { resource "aws_eip" "_" { count = local.enabled ? local.nat_gateway_eip_count : 0 vpc = true - tags = merge(var.additional_tags, tomap({ "Name" = join("-", [local.name, count.index]) })) + tags = merge(var.additional_tags, tomap({ "Name" = join(local.delimiter, [local.name, count.index]) })) } resource "aws_nat_gateway" "_" { count = local.enabled && var.enable_nat_gateway ? local.nat_gateway_count : 0 allocation_id = element(local.eip_allocation_ids, count.index) subnet_id = element(aws_subnet.public.*.id, count.index) - tags = merge(var.additional_tags, tomap({ "Name" = join("-", [local.name, count.index]) })) + tags = merge(var.additional_tags, tomap({ "Name" = join(local.delimiter, [local.name, count.index]) })) lifecycle { create_before_destroy = true diff --git a/private-subnets.tf b/private-subnets.tf index 932ea3c..51eec6b 100644 --- a/private-subnets.tf +++ b/private-subnets.tf @@ -12,7 +12,7 @@ resource "aws_subnet" "private" { vpc_id = join("", aws_vpc._.*.id) tags = merge(var.additional_tags, var.additional_private_subnet_tags, tomap({ "VPC" = join("", aws_vpc._.*.id), "Availability Zone" = length(var.azs_list_names) > 0 ? element(var.azs_list_names, count.index) : element(data.aws_availability_zones.azs.names, count.index), - "Name" = join("-", [local.name, local.az_map_list_short[local.availability_zones[count.index]]]) } + "Name" = join(local.delimiter, [local.name, local.az_map_list_short[local.availability_zones[count.index]]]) } )) } @@ -21,7 +21,7 @@ resource "aws_route_table" "private" { count = local.enabled && local.private_subnet_count > 0 ? local.nat_gateway_count : 0 vpc_id = aws_vpc._[count.index].id - tags = merge(var.additional_tags, tomap({ "Name" = join("-", [local.name, "prv-route", count.index]) }), + tags = merge(var.additional_tags, tomap({ "Name" = join(local.delimiter, [local.name, "prv-route", count.index]) }), var.additional_private_route_tags ) diff --git a/public-subnets.tf b/public-subnets.tf index 433f98c..ca7efe9 100644 --- a/public-subnets.tf +++ b/public-subnets.tf @@ -15,7 +15,7 @@ resource "aws_subnet" "public" { map_public_ip_on_launch = var.map_public_ip_on_lunch tags = merge(var.additional_tags, var.additional_public_subnet_tags, tomap({ "VPC" = join("", aws_vpc._.*.id), "Availability Zone" = length(var.azs_list_names) > 0 ? element(var.azs_list_names, count.index) : element(data.aws_availability_zones.azs.names, count.index), - "Name" = join("-", [local.name, local.az_map_list_short[local.availability_zones[count.index]]]) } + "Name" = join(local.delimiter, [local.name, local.az_map_list_short[local.availability_zones[count.index]]]) } )) } @@ -23,7 +23,7 @@ resource "aws_route_table" "public" { count = local.enabled && local.public_subnet_count > 0 ? 1 : 0 vpc_id = aws_vpc._[count.index].id - tags = merge(var.additional_tags, tomap({ "Name" = join("-", [local.name, "pub-route", count.index]) }), + tags = merge(var.additional_tags, tomap({ "Name" = join(local.delimiter, [local.name, "pub-route", count.index]) }), var.additional_public_route_tags ) } diff --git a/variables.tf b/variables.tf index 8eea2ba..b82bfb7 100644 --- a/variables.tf +++ b/variables.tf @@ -22,6 +22,16 @@ variable "additional_tags" { description = "Additional Tags, tags which can be accessed by module..tags_as_list not added to .." } +variable "delimiter" { + type = string + default = null + + description = <<-EOL + Delimiter to be used between `project_name`, `environment`, `region` and, `name`. + Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. + EOL +} + #=============# # V P C # #=============#