Skip to content

Commit 0744f1c

Browse files
authored
Merge pull request #4 from softwaremill/feat/variable-input-validation
feat: variable input validation
2 parents f078920 + 8280f96 commit 0744f1c

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.terraform
44
.terraform.lock.hcl
55
terraform.tfstate*
6+
.DS_Store

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
This module creates the GKE cluster with all dependencies: project, network (VPC), subnet etc.
33
It can also use existing project - in such case set the `create_project` to `false` and provide the existing `project_id`.
44

5+
# Prerequisite
6+
7+
- Before you create GCP project make sure you have right permission to attach billing accounts to created project.
8+
That means have at least one of IAM roles attached:
9+
- roles/billing.creator
10+
- roles/billing.admin
11+
- roles/billing.user
12+
- roles/billing.projectManager
13+
514
## Usage
615

716
The simplest way to use this module:
@@ -40,8 +49,8 @@ No requirements.
4049

4150
| Name | Version |
4251
|------|---------|
43-
| <a name="provider_google"></a> [google](#provider\_google) | 4.53.1 |
44-
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 4.53.1 |
52+
| <a name="provider_google"></a> [google](#provider\_google) | 4.62.1 |
53+
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 4.62.1 |
4554

4655
## Modules
4756

@@ -67,7 +76,7 @@ No requirements.
6776
|------|-------------|------|---------|:--------:|
6877
| <a name="input_activate_apis"></a> [activate\_apis](#input\_activate\_apis) | List of Google APIs activated in new or existing project. | `list(string)` | <pre>[<br> "compute.googleapis.com",<br> "container.googleapis.com"<br>]</pre> | no |
6978
| <a name="input_additional_node_pool_oauth_scopes"></a> [additional\_node\_pool\_oauth\_scopes](#input\_additional\_node\_pool\_oauth\_scopes) | Node pool oauth scopes added to specified node pool in addition to default\_node\_pool\_oauth\_scopes. It's referenced by node\_pool `name` | `map(list(string))` | <pre>{<br> "default-node-pool": []<br>}</pre> | no |
70-
| <a name="input_billing_account"></a> [billing\_account](#input\_billing\_account) | The billing account to witch the new project should be connected. Required if `create_project` set to `true`. | `string` | `""` | no |
79+
| <a name="input_billing_account"></a> [billing\_account](#input\_billing\_account) | YOU NEED TO HAVE PERMISSION TO BILLING ACCOUNT, The billing account to witch the new project should be connected. Required if `create_project` set to `true`. | `string` | `""` | no |
7180
| <a name="input_create_project"></a> [create\_project](#input\_create\_project) | Defines if create the project. All resources are created this project. If `false` - the project\_id is required. | `bool` | `false` | no |
7281
| <a name="input_default_node_pools_oauth_scopes"></a> [default\_node\_pools\_oauth\_scopes](#input\_default\_node\_pools\_oauth\_scopes) | Default node pool oauth scopes added to all node pools | `list(string)` | <pre>[<br> "https://www.googleapis.com/auth/devstorage.read_only",<br> "https://www.googleapis.com/auth/cloud-platform",<br> "https://www.googleapis.com/auth/logging.write",<br> "https://www.googleapis.com/auth/monitoring",<br> "https://www.googleapis.com/auth/compute"<br>]</pre> | no |
7382
| <a name="input_default_pool_machine_type"></a> [default\_pool\_machine\_type](#input\_default\_pool\_machine\_type) | In some cases the GKE won't be created unless the default pool uses specific machine type (for example confidential nodes) so we have to set the type even if the default pool is removed. | `string` | `"e2-small"` | no |

examples/terragrunt/public-cluster-terragrunt/terragrunt.hcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ generate "providers" {
1414
contents = <<EOF
1515
provider "google" {
1616
}
17+
18+
provider "google-beta" {
19+
}
1720
EOF
1821
}
1922

variables.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ variable "create_project" {
66
variable "billing_account" {
77
type = string
88
default = ""
9-
description = "The billing account to witch the new project should be connected. Required if `create_project` set to `true`."
9+
description = "YOU NEED TO HAVE PERMISSION TO BILLING ACCOUNT, The billing account to witch the new project should be connected. Required if `create_project` set to `true`."
1010
}
1111
variable "org_id" {
1212
type = string
@@ -21,20 +21,36 @@ variable "project_id" {
2121
type = string
2222
default = ""
2323
description = "Existing project id. Required if `create_project` set to `false`"
24+
validation {
25+
condition = can(regex("^[a-z]{1}[0-9a-z-]{5,29}$", var.project_id))
26+
error_message = "The project id must be 6 to 30 characters in length, can only contain lowercase letters, numbers, and hyphens"
27+
}
2428
}
2529
variable "project_name" {
2630
type = string
2731
default = ""
2832
description = "The name of the created project. Defaults to `platform_name` if not set."
33+
validation {
34+
condition = length(var.project_name) < 25 && length(var.project_name) > 4
35+
error_message = "The project name should contain only 25 characters. Last 5 characters up to 30 total are generated"
36+
}
2937
}
3038
variable "release_channel" {
3139
type = string
3240
default = "UNSPECIFIED"
3341
description = "The GKE release channel."
42+
validation {
43+
condition = contains(["UNSPECIFIED", "RAPID", "STABLE"], var.release_channel)
44+
error_message = "Valid values for var: test_variable are (UNSPECIFIED, RAPID, STABLE)"
45+
}
3446
}
3547
variable "platform_name" {
3648
type = string
3749
description = "The name of the platform. Many resource names are based on this (VPC, subnet, GKE cluster etc)."
50+
validation {
51+
condition = length(var.platform_name) < 25 && length(var.platform_name) > 4
52+
error_message = "The platform name should contain only 25 characters. Last 5 characters up to 30 total are generated"
53+
}
3854
}
3955
variable "subnet_network" {
4056
type = string

0 commit comments

Comments
 (0)