Skip to content

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
 - Updating [terraform-aws-tag](https://github.com/obytes/terraform-aws-tag) version
 - Adding an optional variable `delimiter` thats is defaults to `-`
 - Updating README
  • Loading branch information
ahaffar committed Aug 9, 2022
1 parent aadf11b commit 8772f8b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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"
prefix_length_limit = 12
}
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"
Expand Down
6 changes: 4 additions & 2 deletions examples/example.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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
}

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
Expand Down
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "-"
}


Expand Down Expand Up @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions nat-gw.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions private-subnets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]) }
))
}

Expand All @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions public-subnets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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]]]) }
))
}

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
)
}
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ variable "additional_tags" {
description = "Additional Tags, tags which can be accessed by module.<name>.tags_as_list not added to <module>.<name>.<tags>"
}

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 #
#=============#
Expand Down

0 comments on commit 8772f8b

Please sign in to comment.