Terraform module which creates name format for AWS resources
This module is to help you create resources in AWS using Terrafom to create names according to the rules. Please refer to Examples for examples of usage. In the following, I will explain the usage and structure in a simple way.
module "namer" {
source = "../../"
prefix = ["namer", "prod"]
}
module "namer_with_additional_identifier_verb" {
source = "../../"
with_additional_identifier_verb = true
prefix = ["namer", "prod"]
}
...
"Name" = format(module.namer.subnet, "bastion", "pub", each.key)
...
"Name" = format(module.namer_with_additional_identifier_verb.ec2_instance, "rest", "auth")
The overall output should look something like this
# delimiter = "-"
# Default
${resource_name}-${prefix}-${identifier}
# With Optional Resource Number
# with_additional_identifier_verb = true
${resource_name}-${prefix}-${identifier}-${additional_identifier}
We'll discuss each element in more detail below.
This element is the name of the resource provided by AWS.
This module uses abbreviated resource names, which can be found and changed in [local.tf] (./local.tf).
This element is a user-definable prefix value and can provide multiple values in an array.
# delimiter = "-"
# ["poc", "dev"]
prefix = "poc-dev"
# ["terraform", "prod"]
prefix = "terraform-prod"
This element is an identifier, with one or two arguments.
ex) ${service_name}
, ${subnet_name}-${route_type}
You can see how many arguments it has in [outputs.tf] (./outputs.tf).
This is an optionally available element, enabled by adding the with_additional_identifier_verb = true
option.
This is an identifier to use when you need to create multiple resources with the same name. If this is not the case, we recommend not using it.
Below shows the result of adding this option when getting the name of an ec2_instance.
# delimiter = "-"
# prefix = ["terraform", "qa"]
# identifier = ["rest"]
# region = "ap-northeast-2"
# with_additional_identifier_verb = true
-> ec2-terraform-qa-rest-an2-%s
For more usage examples, see examples/complete/.
Name | Version |
---|---|
aws | n/a |
No modules.
Name | Type |
---|---|
aws_availability_zones.available_zones | data source |
aws_region.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
delimiter | A delimiter variable that combines each element. | string |
"-" |
no |
identifier | A identifier value of the form {resource_name} {prefix} {identifier} {sufix} , where the listed values are combined into a delimiter variable. |
list(string) |
[] |
no |
prefix | A prefix value of the form {resource_name} {prefix} {identifier} {sufix} , where the listed values are combined into a delimiter variable. |
list(string) |
[ |
no |
with_additional_identifier_verb | If this value is false, naming doesn't contain additional identifier suffix. | bool |
false |
no |
with_random_string | n/a | bool |
false |
no |
with_resource_number_verb | If this value is false, naming doesn't contain number suffix. | bool |
false |
no |
Name | Description |
---|---|
application_load_balancer | Application Load Balancer |
classic_load_balancer | Classic Load Balancer |
ec2_instance | EC2 Instance |
eks_cluster | EKS Cluster |
eks_node_group | EKS Node Group |
elastic_ip | Elastic IP Address Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : eip-project-env-an2%s-%s usage : format(module.namer.elastic_ip, "az_value", "identifier") |
elastic_load_balancer | Elastic Load Balancer |
elasticache | Elasticache |
elasticache_replication_group | Elasticache Replication Group |
elasticache_subnet_group | Elasticache Subnet Group |
iam_policy | IAM Policy |
iam_role | IAM Role |
internet_gateway | Internet Gateway Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : igw-project-env-an2 usage : module.namer.internet_gateway |
key_management_service | Key Management Service |
kinesis_data_stream | Kinesis Data Stream |
nat_gateway | NAT Gateway Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : nat-project-env-an2%s usage : format(module.namer.nat_gateway, "az_value") |
network_access_control_list | Network Access Control List |
network_load_balancer | Network Load Balancer |
rds_cluster | RDS Cluster |
rds_instance | RDS Instance |
rds_parameter_group | RDS Parameter Group |
rds_subnet_group | RDS Subnet Group |
route_table | Route Table Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : rt-project-env-%s-%s-an2%s usage : format(module.namer.route_table, "identifier", "subnet_type [pri, pub]", "az_value") |
secrets_manager | Secrets Manager |
security_group | Security Group |
simple_email_service | Simple Email Service |
simple_queue_service | Simple Queue Service |
subnet | Subnet Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : snet-project-env-%s-%s-an2%s usage : format(module.namer.subnet, "identifier", "subnet_type [pri, pub]", "az_value") |
target_group | Target Group |
transit_gateway | Transit Gateway |
transit_gateway_attachment | Transit Gateway Attachment |
transit_gateway_route_table | Transit Gateway Route Table |
virtual_private_cloud | Virtual Private Cloud Example : setting : region = ap-northeast-2 delimiter = "-" prefix = ["project", "env"] with_resource_number_verb = false // if true, please check examples/with-resource-number-verb result : vpc-project-env-an2 usage : module.namer.virtual_private_cloud |