Skip to content

Commit 4247408

Browse files
Added missing dependencies and additional node_pool attributes (#9)
* Added missing dependencies and additional node_pool attributes * terraform-docs: automated action Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3006ab6 commit 4247408

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ No requirements.
4040

4141
| Name | Version |
4242
|------|---------|
43-
| <a name="provider_google"></a> [google](#provider\_google) | 4.33.0 |
43+
| <a name="provider_google"></a> [google](#provider\_google) | 4.34.0 |
44+
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 4.34.0 |
4445

4546
## Modules
4647

@@ -55,9 +56,9 @@ No requirements.
5556

5657
| Name | Type |
5758
|------|------|
59+
| [google-beta_google_container_node_pool.pools](https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_container_node_pool) | resource |
5860
| [google_compute_address.cloud_nat_address](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_address) | resource |
5961
| [google_container_cluster.gke](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster) | resource |
60-
| [google_container_node_pool.pools](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool) | resource |
6162
| [google_container_registry.registry](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_registry) | resource |
6263

6364
## Inputs
@@ -70,6 +71,7 @@ No requirements.
7071
| <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 |
7172
| <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/cloud-platform",<br> "https://www.googleapis.com/auth/logging.write",<br> "https://www.googleapis.com/auth/monitoring"<br>]</pre> | no |
7273
| <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 |
74+
| <a name="input_disable_services_on_destroy"></a> [disable\_services\_on\_destroy](#input\_disable\_services\_on\_destroy) | Whether project services will be disabled when the resources are destroyed. | `bool` | `true` | no |
7375
| <a name="input_enable_confidential_nodes"></a> [enable\_confidential\_nodes](#input\_enable\_confidential\_nodes) | Whether to enable confidential nodes. | `bool` | `false` | no |
7476
| <a name="input_enable_private_endpoint"></a> [enable\_private\_endpoint](#input\_enable\_private\_endpoint) | Defines if create private endpoint. It disables the public endpoint so the cluster is accessible only from VPC. | `bool` | `false` | no |
7577
| <a name="input_enable_private_nodes"></a> [enable\_private\_nodes](#input\_enable\_private\_nodes) | Defines if use private nodes. Implies creation of cloud NAT service so nodes and pods can access public internet. | `bool` | `true` | no |
@@ -111,12 +113,14 @@ The node_pools variable takes the following parameters:
111113
| --- | --- | --- | --- |
112114
| <a name="autoscaling"></a> [autoscaling](#autoscaling) | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | `true` | Optional |
113115
| <a name="node_locations"></a> [node\_locations](#node\_locations) | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | `""` | Optional |
114-
| <a name="node_count"></a> [node\_count](#node\_count) | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | `` | Required |
116+
| <a name="node_count"></a> [node\_count](#node\_count) | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | `1` | Required |
115117
| <a name="min_count"></a> [min\_count](#min\_count) | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | `1` | Optional |
116118
| <a name="max_count"></a> [max\_count](#max\_count) | Maximum number of nodes in the NodePool. Must be >= min_count | `100` | Optional |
117119
| <a name="image_type"></a> [image\_type](#image\_type) | The image type to use for this node. Note that changing the image type will delete and recreate all nodes in the node pool | `COS_CONTAINERD` | Optional |
118120
| <a name="machine_type"></a> [machine\_type](#machine\_type) | The name of a Google Compute Engine machine type | `e2-medium` | Optional |
119121
| <a name="min_cpu_platform"></a> [min\_cpu\_platform](#min\_cpu\_platform) | Minimum CPU platform to be used by the nodes in the pool. The nodes may be scheduled on the specified or newer CPU platform. | `""` | Optional |
120122
| <a name="local_ssd_count"></a> [local\_ssd\_count](#local\_ssd\_count) | The amount of local SSD disks that will be attached to each cluster node and may be used as a `hostpath` volume or a `local` PersistentVolume. | `0` | Optional |
121123
| <a name="disk_size_gb"></a> [disk\_size\_gb](#disk\_size\_gb) | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | `100` | Optional |
122-
| <a name="disk_type"></a> [disk\_type](#disk\_type) | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | `pd-standard` | Optional |
124+
| <a name="preemptible"></a> [preemptible](#preemptible) | A boolean that represents whether or not the underlying node VMs are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm)</a> for more information.) | `false` | Optional |
125+
| <a name="spot"></a> [spot](#spot) | A boolean that represents whether the underlying node VMs are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms) for more information. | `false` | Optional |
126+
| <a name="compact_placement_policy"></a> [compact\_placement\_policy](#compact\_placement\_policy) | Compact placement policy enabled places node pool's nodes in a closer physical proximity in order to reduce network latency between nodes. | `false` | Optional |

main.tf

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ module "project" {
1010
}
1111

1212
module "project_services" {
13-
source = "registry.terraform.io/terraform-google-modules/project-factory/google//modules/project_services"
14-
version = "13.0.0"
15-
project_id = var.project_id
16-
activate_apis = var.activate_apis
17-
count = var.create_project ? 0 : 1
13+
source = "registry.terraform.io/terraform-google-modules/project-factory/google//modules/project_services"
14+
version = "13.0.0"
15+
project_id = var.project_id
16+
activate_apis = var.activate_apis
17+
disable_services_on_destroy = var.disable_services_on_destroy
18+
count = var.create_project ? 0 : 1
1819
}
1920

2021
module "network" {
@@ -42,13 +43,19 @@ module "network" {
4243
}
4344
]
4445
}
46+
depends_on = [
47+
module.project_services.project_id
48+
]
4549
}
4650

4751
resource "google_compute_address" "cloud_nat_address" {
4852
name = local.cloud_nat_name
4953
project = local.project_id
5054
region = var.region
5155
count = var.enable_private_nodes ? 1 : 0
56+
depends_on = [
57+
module.project_services.project_id
58+
]
5259
}
5360

5461
module "cloud_nat" {
@@ -82,10 +89,13 @@ resource "google_container_cluster" "gke" {
8289
lifecycle {
8390
ignore_changes = [initial_node_count, node_config]
8491
}
92+
depends_on = [
93+
module.network.subnets
94+
]
8595
}
8696

8797
resource "google_container_node_pool" "pools" {
88-
98+
provider = google-beta
8999
for_each = local.node_pools
90100
location = local.location
91101
project = local.project_id
@@ -100,13 +110,22 @@ resource "google_container_node_pool" "pools" {
100110
}
101111
}
102112

113+
dynamic "placement_policy" {
114+
for_each = lookup(each.value, "compact_placement_policy", false) ? [each.value] : []
115+
content {
116+
type = "COMPACT"
117+
}
118+
}
119+
103120
node_config {
104121
image_type = lookup(each.value, "image_type", "COS_CONTAINERD")
105122
machine_type = lookup(each.value, "machine_type", "e2-medium")
106123
min_cpu_platform = lookup(each.value, "min_cpu_platform", "")
107124
local_ssd_count = lookup(each.value, "local_ssd_count", 0)
108125
disk_size_gb = lookup(each.value, "disk_size_gb", 100)
109126
disk_type = lookup(each.value, "disk_type", "pd-standard")
127+
preemptible = lookup(each.value, "preemptible", false)
128+
spot = lookup(each.value, "spot", false)
110129
labels = lookup(var.node_pools_labels, each.value["name"], {})
111130
oauth_scopes = lookup(local.node_pool_oauth_scopes, each.value["name"], [])
112131
}

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ variable "activate_apis" {
107107
]
108108
description = "List of Google APIs activated in new or existing project."
109109
}
110+
variable "disable_services_on_destroy" {
111+
description = "Whether project services will be disabled when the resources are destroyed."
112+
default = true
113+
type = bool
114+
}
110115
variable "gcr_location" {
111116
type = string
112117
default = "EU"

0 commit comments

Comments
 (0)