Skip to content

Commit 5bb2976

Browse files
authored
User input validation (#57)
* adds support for field validation * shorten appended cluster-name suffix * production -> prod * staging -> stage * update env * update readme * shorten rds secret env
1 parent 95541fd commit 5bb2976

10 files changed

Lines changed: 57 additions & 33 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ The root folder is used for declaring parameters required by the templates, and
1616
| |-- terraform/
1717
| | |-- bootstrap/ #initial setup
1818
| | |-- environments/ #infrastructure setup
19-
| | | |-- production/
20-
| | | |-- staging/
19+
| | | |-- prod/
20+
| | | |-- stage/
2121
| |-- kubernetes
2222
| | |-- terraform
2323
| | | |-- environments #k8s-ultities
24-
| | | | |-- production/
25-
| | | | |-- staging/
24+
| | | | |-- prod/
25+
| | | | |-- stage/
2626
```
2727

2828
## AWS EKS Stack
@@ -60,7 +60,7 @@ infrastructure:
6060
- RDS (db.t3.small): $0.034 USD / hr
6161
- EC2 (t2.small): $0.023 USD / hr
6262

63-
EC2 instance sizing can be configured in [terraform/environments/staging/main.tf](terraform/environments/staging/main.tf)
63+
EC2 instance sizing can be configured in [terraform/environments/stage/main.tf](terraform/environments/stage/main.tf)
6464

6565
## Other links
6666
Project board: [zenhub][zenhub-board]

templates/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ENVIRONMENT ?= staging
1+
ENVIRONMENT ?= stage
22

33
apply: apply-remote-state apply-secrets apply-env apply-k8s-utils
44

templates/kubernetes/terraform/environments/development/main.tf renamed to templates/kubernetes/terraform/environments/dev/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
terraform {
22
backend "s3" {
3-
bucket = "<% .Name %>-development-terraform-state"
3+
bucket = "<% .Name %>-dev-terraform-state"
44
key = "infrastructure/terraform/environments/development/kubernetes"
55
encrypt = true
66
region = "<% index .Params `region` %>"
7-
dynamodb_table = "<% .Name %>-development-terraform-state-locks"
7+
dynamodb_table = "<% .Name %>-dev-terraform-state-locks"
88
}
99
}
1010

1111
# Provision kubernetes resources required to run services/applications
1212
module "kubernetes" {
1313
source = "../../modules/kubernetes"
1414

15-
environment = "development"
15+
environment = "dev"
1616
region = "<% index .Params `region` %>"
1717

1818
# Authenticate with the EKS cluster via the cluster id

templates/kubernetes/terraform/environments/production/main.tf renamed to templates/kubernetes/terraform/environments/prod/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
22
backend "s3" {
3-
bucket = "<% .Name %>-production-terraform-state"
3+
bucket = "<% .Name %>-prod-terraform-state"
44
key = "infrastructure/terraform/environments/production/kubernetes"
55
encrypt = true
66
region = "<% index .Params `region` %>"
7-
dynamodb_table = "<% .Name %>-production-terraform-state-locks"
7+
dynamodb_table = "<% .Name %>-prod-terraform-state-locks"
88
}
99
}
1010

@@ -16,11 +16,11 @@ provider "aws" {
1616
module "kubernetes" {
1717
source = "../../modules/kubernetes"
1818

19-
environment = "production"
19+
environment = "prod"
2020
region = "<% index .Params `region` %>"
2121

2222
# Authenticate with the EKS cluster via the cluster id
23-
cluster_name = "<% .Name %>-production-<% index .Params `region` %>"
23+
cluster_name = "<% .Name %>-prod-<% index .Params `region` %>"
2424

2525
external_dns_zone = "<% index .Params `productionHostRoot` %>"
2626
external_dns_owner_id = "<% GenerateUUID %>" # randomly generated ID

templates/kubernetes/terraform/environments/staging/main.tf renamed to templates/kubernetes/terraform/environments/stage/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
22
backend "s3" {
3-
bucket = "<% .Name %>-staging-terraform-state"
3+
bucket = "<% .Name %>-stage-terraform-state"
44
key = "infrastructure/terraform/environments/staging/kubernetes"
55
encrypt = true
66
region = "<% index .Params `region` %>"
7-
dynamodb_table = "<% .Name %>-staging-terraform-state-locks"
7+
dynamodb_table = "<% .Name %>-stage-terraform-state-locks"
88
}
99
}
1010

@@ -16,11 +16,11 @@ provider "aws" {
1616
module "kubernetes" {
1717
source = "../../modules/kubernetes"
1818

19-
environment = "staging"
19+
environment = "stage"
2020
region = "<% index .Params `region` %>"
2121

2222
# Authenticate with the EKS cluster via the cluster id
23-
cluster_name = "<% .Name %>-staging-<% index .Params `region` %>"
23+
cluster_name = "<% .Name %>-stage-<% index .Params `region` %>"
2424

2525
external_dns_zone = "<% index .Params `stagingHostRoot` %>"
2626
external_dns_owner_id = "<% GenerateUUID %>" # randomly generated ID

templates/terraform/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
```
5050
README.md
5151
environments/
52-
production/
52+
prod/
5353
main.tf
54-
staging/
54+
stage/
5555
main.tf
5656
development/
5757
main.tf

templates/terraform/bootstrap/secrets/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ module "ci_user_keys" {
3232
tags = map("project", local.project)
3333
}
3434

35-
module "rds_master_secret_staging" {
35+
module "rds_master_secret_stage" {
3636
source = "../../modules/secret"
37-
name = "${local.project}-staging-rds-<% index .Params `randomSeed` %>"
37+
name = "${local.project}-stage-rds-<% index .Params `randomSeed` %>"
3838
type = "random"
3939
random_length = 32
40-
tags = map("rds", "${local.project}-staging")
40+
tags = map("rds", "${local.project}-stage")
4141
}
4242

43-
module "rds_master_secret_production" {
43+
module "rds_master_secret_prod" {
4444
source = "../../modules/secret"
45-
name = "${local.project}-production-rds-<% index .Params `randomSeed` %>"
45+
name = "${local.project}-prod-rds-<% index .Params `randomSeed` %>"
4646
type = "random"
4747
random_length = 32
48-
tags = map("rds", "${local.project}-production")
48+
tags = map("rds", "${local.project}-prod")
4949
}

templates/terraform/environments/production/main.tf renamed to templates/terraform/environments/prod/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
terraform {
22
required_version = ">= 0.12"
33
backend "s3" {
4-
bucket = "<% .Name %>-production-terraform-state"
4+
bucket = "<% .Name %>-prod-terraform-state"
55
key = "infrastructure/terraform/environments/production/main"
66
encrypt = true
77
region = "<% index .Params `region` %>"
8-
dynamodb_table = "<% .Name %>-production-terraform-state-locks"
8+
dynamodb_table = "<% .Name %>-prod-terraform-state-locks"
99
}
1010
}
1111

1212
# Instantiate the production environment
13-
module "production" {
13+
module "prod" {
1414
source = "../../modules/environment"
15-
environment = "production"
15+
environment = "prod"
1616

1717
# Project configuration
1818
project = "<% .Name %>"

templates/terraform/environments/staging/main.tf renamed to templates/terraform/environments/stage/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
terraform {
22
required_version = ">= 0.12"
33
backend "s3" {
4-
bucket = "<% .Name %>-staging-terraform-state"
4+
bucket = "<% .Name %>-stage-terraform-state"
55
key = "infrastructure/terraform/environments/staging/main"
66
encrypt = true
77
region = "<% index .Params `region` %>"
8-
dynamodb_table = "<% .Name %>-staging-terraform-state-locks"
8+
dynamodb_table = "<% .Name %>-stage-terraform-state-locks"
99
}
1010
}
1111

1212
# Instantiate the staging environment
13-
module "staging" {
13+
module "stage" {
1414
source = "../../modules/environment"
15-
environment = "staging"
15+
environment = "stage"
1616

1717
# Project configuration
1818
project = "<% .Name %>"

zero-module.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,44 @@ parameters:
2323
- "us-east-2"
2424
- field: productionHostRoot
2525
label: Production Root Host Name (e.g. mydomain.com) - this must be the root of the chosen domain, not a subdomain.
26+
fieldValidation:
27+
type: regex
28+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.{1})+[a-z]{2,}$'
29+
errorMessage: Invalid root domain name
2630
- field: productionFrontendSubdomain
2731
label: Production Frontend Host Name (e.g. app.)
2832
default: app.
33+
fieldValidation:
34+
type: regex
35+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.)$'
36+
errorMessage: Invalid subdomain (cannot contain special chars & must end with a '.')
2937
- field: productionBackendSubdomain
3038
label: Production Backend Host Name (e.g. api.)
3139
default: api.
40+
fieldValidation:
41+
type: regex
42+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.)$'
43+
errorMessage: Invalid subdomain (cannot contain special chars & must end with a '.')
3244
- field: stagingHostRoot
3345
label: Staging Root Host Name (e.g. mydomain-staging.com) - this must be the root of the chosen domain, not a subdomain.
46+
fieldValidation:
47+
type: regex
48+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.{1})+[a-z]{2,}$'
49+
errorMessage: Invalid root domain name
3450
- field: stagingFrontendSubdomain
3551
label: Staging Frontend Host Name (e.g. app.)
3652
default: app.
53+
fieldValidation:
54+
type: regex
55+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.)$'
56+
errorMessage: Invalid subdomain (cannot contain special chars & must end with a '.')
3757
- field: stagingBackendSubdomain
3858
label: Staging Backend Host Name (e.g. api.)
3959
default: api.
60+
fieldValidation:
61+
type: regex
62+
value: '^([a-z0-9]+(-[a-z0-9]+)*\.)$'
63+
errorMessage: Invalid subdomain (cannot contain special chars & must end with a '.')
4064
- field: accountId
4165
label: AWS Account ID
4266
execute: aws sts get-caller-identity --query "Account" | tr -d '"'

0 commit comments

Comments
 (0)