commitdev/zero

Validate project name during "zero apply"

aspcanada opened this issue · 2 comments

I received several errors during zero apply. It appears that the project name that I chose (0play) should be validated to not accept names that start with a numeral. It appears that some AWS resources do not like names starting with a numeric.

Originally, I thought the issue was the domain that I registered (0play-stage.click).

Error: invalid value for replication_group_id (must begin with a letter)

│
│   with module.stage.module.cache[0].module.redis[0].aws_elasticache_replication_group.default[0],
│   on .terraform/modules/stage.cache.redis/main.tf line 83, in resource "aws_elasticache_replication_group" "default":
│   83:   replication_group_id          = var.replication_group_id == "" ? module.this.id : var.replication_group_id

Error: invalid value for domain_name (must start with a lowercase alphabet and be at least 3 and no more than 28 characters long. Valid characters are a-z (lowercase letters), 0-9, and - (hyphen).)

│   with module.stage.module.logging[0].module.elasticsearch.aws_elasticsearch_domain.default[0],
│   on .terraform/modules/stage.logging.elasticsearch/main.tf line 102, in resource "aws_elasticsearch_domain" "default":
│  102:   domain_name           = module.this.id

Error: first character of "name_prefix" must be a letter

│   with module.stage.module.db[0].module.rds_postgres[0].module.db_option_group.aws_db_option_group.this[0],
│   on .terraform/modules/stage.db.rds_postgres/modules/db_option_group/main.tf line 4, in resource "aws_db_option_group" "this":
│    4:   name_prefix              = var.name_prefix

Error: first character of parameter group "name_prefix" must be a letter

│   with module.stage.module.db[0].module.rds_postgres[0].module.db_parameter_group.aws_db_parameter_group.this[0],
│   on .terraform/modules/stage.db.rds_postgres/modules/db_parameter_group/main.tf line 36, in resource "aws_db_parameter_group" "this":
│   36:   name_prefix = var.name_prefix
│
╵
make[1]: *** [apply-env] Error 1
make: *** [make-apply] Error 2
2022/01/19 14:18:20 Module Apply failed: Module (zero-aws-eks-stack)

Seems like this would be an issue with the project name rather than the domain name. This is a pain since the project name is used pretty extensively as an identifier in resource naming. A reasonable fix for now would be to add validation on the project name field to enforce starting it with a letter. In the long run it's probably a good idea to find the individual spots with these restrictions and make sure we are enforcing the right name format.

This would require a small tweak to the ValidateProjectName function in this project since the project name is the very first thing we prompt for, and not in the module parameter definitions.

Oh interesting... I didn't even think about the project name, I assumed it was an issue with my domain name choice. I'll update the summary and description.