You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(terraform): add support for using existing GKE clusters (#20)
* feat(terraform): add support for using existing GKE clusters
Introduce a new variable `use_existing_cluster` to toggle between
creating a new GKE cluster or using an existing one. Update resources
and outputs to conditionally reference existing cluster data when
enabled. Add a migration script and upgrade guide for transitioning
from version 0.3.x to 0.4.x, ensuring a smooth upgrade process. Enhance
variable descriptions for clarity and improve documentation.
* terraform-docs: automated action
* feat(gke): add conditional logic for existing cluster usage
Introduce `use_existing_cluster` variable to conditionally create
resources, allowing flexibility in using existing clusters. Update
firewall rules and node pool configurations to respect this setting.
Enhance variable descriptions with defaults for clarity and improve
resource tagging and filtering capabilities.
* terraform-docs: automated action
* fix(gke.tf): remove conditional cluster assignment to ensure consistent cluster ID usage
fix(gke.tf): adjust firewall rule count logic to account for shared VPC with existing cluster
* docs(variables.tf): update section header for clarity in cluster configuration
* docs(upgrade-guide): update guide for 0.4.x migration and remove obsolete script
Remove placeholder migration script for 0.4.x as it is no longer needed.
Update upgrade guide to include new `use_existing_cluster` variable and
instructions for using `terraform state mv` for resource migration.
* chore(scripts): remove unused migration-script-4.sh file to clean up the codebase
* docs(upgrade-guide.md): correct terminology from 'diff' to 'drift' for clarity
refactor(variables.tf): reorder variables for better logical grouping and readability
* terraform-docs: automated action
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
|[google_container_cluster.existing_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster)| data source |
32
33
33
34
## Inputs
34
35
35
36
| Name | Description | Type | Default | Required |
| <aname="input_allowed_ip_ranges"></a> [allowed\_ip\_ranges](#input\_allowed\_ip\_ranges)| Allowed IP ranges to connect to master |`list(string)`| <pre>[<br/> "0.0.0.0/0"<br/>]</pre> | no |
| <a name="input_cluster_generic_node_config"></a> [cluster\_generic\_node\_config](#input\_cluster\_generic\_node\_config) | Configuration for the generic node pool. This includes:<br/>- disk\_size\_gb: Size of the disk attached to each node (default: "100")<br/>- disk\_type: Type of disk attached to each node (pd-standard, pd-balanced, pd-ssd) (default: "pd-balanced")<br/>- machine\_type: The name of a Google Compute Engine machine type (default: "e2-medium")<br/>- enable\_secure\_boot: Secure Boot helps ensure that the system only runs authentic software (default: true)<br/>- enable\_integrity\_monitoring: Enables monitoring and attestation of the boot integrity (default: true)<br/>- auto\_repair: Flag to enable auto repair for the nodes (default: true)<br/>- auto\_upgrade: Flag to enable auto upgrade for the nodes (default: true)<br/>- node\_count: The number of nodes per instance group (default: 1)<br/>- workload\_metadata\_config\_mode: How to expose metadata to workloads running on the node (default: "GKE\_METADATA")<br/>- service\_account: The Google Cloud Platform Service Account (default: "default")<br/>- preemptible: Flag to enable preemptible nodes (default: false)<br/>- spot: Flag to enable spot instances (default: true) | <pre>object({<br/> disk_size_gb = optional(string, "100")<br/> disk_type = optional(string, "pd-balanced")<br/> machine_type = optional(string, "e2-medium")<br/> enable_secure_boot = optional(bool, true)<br/> enable_integrity_monitoring = optional(bool, true)<br/> auto_repair = optional(bool, true)<br/> auto_upgrade = optional(bool, true)<br/> node_count = optional(number, 1)<br/> workload_metadata_config_mode = optional(string, "GKE_METADATA")<br/> service_account = optional(string, "default")<br/> preemptible = optional(bool, false)<br/> spot = optional(bool, true)<br/> })</pre> | `{}` | no |
| <aname="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name)| Name of the cluster. If use\_existing\_cluster is enabled cluster\_name is used to fetch details of existing cluster|`string`| n/a | yes |
42
+
| <a name="input_cluster_nap_node_config"></a> [cluster\_nap\_node\_config](#input\_cluster\_nap\_node\_config) | Configuration for the NAP node pool. This includes:<br/>- disk\_size\_gb: Size of the disk attached to each node (default: "300")<br/>- disk\_type: Type of disk attached to each node (pd-standard, pd-balanced, pd-ssd) (default: "pd-balanced")<br/>- enable\_secure\_boot: Secure Boot helps ensure that the system only runs authentic software (default: true)<br/>- enable\_integrity\_monitoring: Enables monitoring and attestation of the boot integrity (default: true)<br/>- autoscaling\_profile: Profile for autoscaling optimization (default: "OPTIMIZE\_UTILIZATION")<br/>- max\_cpu: Maximum CPU cores allowed per node (default: 1024)<br/>- max\_memory: Maximum memory in MB allowed per node (default: 8172)<br/>- auto\_repair: Flag to enable auto repair for the nodes (default: true)<br/>- auto\_upgrade: Flag to enable auto upgrade for the nodes (default: true)<br/>- max\_surge: Maximum number of nodes that can be created beyond the current size during updates (default: 1)<br/>- max\_unavailable: Maximum number of nodes that can be unavailable during updates (default: 0) | <pre>object({<br/> disk_size_gb = optional(string, "300")<br/> disk_type = optional(string, "pd-balanced")<br/> enable_secure_boot = optional(bool, true)<br/> enable_integrity_monitoring = optional(bool, true)<br/> autoscaling_profile = optional(string, "OPTIMIZE_UTILIZATION")<br/> max_cpu = optional(number, 1024)<br/> max_memory = optional(number, 8172)<br/> auto_repair = optional(bool, true)<br/> auto_upgrade = optional(bool, true)<br/> max_surge = optional(number, 1)<br/> max_unavailable = optional(number, 0)<br/> })</pre> | `{}` | no |
42
43
| <aname="input_cluster_network_id"></a> [cluster\_network\_id](#input\_cluster\_network\_id)| Network ID for the cluster |`string`| n/a | yes |
43
44
| <aname="input_cluster_networking_mode"></a> [cluster\_networking\_mode](#input\_cluster\_networking\_mode)| Networking mode for the cluster. Values can be VPC\_NATIVE (recommended) or ROUTES. VPC\_NATIVE is default after google-beta 5.0.0 |`string`|`"VPC_NATIVE"`| no |
44
45
| <aname="input_cluster_node_locations"></a> [cluster\_node\_locations](#input\_cluster\_node\_locations)| AZ for nodes - this should match the region |`list(string)`| n/a | yes |
@@ -49,14 +50,15 @@ No modules.
49
50
| <aname="input_deletion_protection"></a> [deletion\_protection](#input\_deletion\_protection)| Deletion protection enabled/disabled |`bool`|`false`| no |
50
51
| <aname="input_enable_container_image_streaming"></a> [enable\_container\_image\_streaming](#input\_enable\_container\_image\_streaming)| Enable/disable container image streaming |`bool`|`true`| no |
51
52
| <aname="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version)| Version of GKE |`string`|`"1.28"`| no |
52
-
| <aname="input_max_pods_per_node"></a> [max\_pods\_per\_node](#input\_max\_pods\_per\_node)| Maximum pods per node |`string`|`"32"`| no |
53
+
| <aname="input_max_pods_per_node"></a> [max\_pods\_per\_node](#input\_max\_pods\_per\_node)| Maximum number of pods per node in this cluster.|`string`|`"32"`| no |
53
54
| <aname="input_network_tags"></a> [network\_tags](#input\_network\_tags)| A list of network tags to add to all instances |`list(string)`|`[]`| no |
54
55
| <aname="input_oauth_scopes"></a> [oauth\_scopes](#input\_oauth\_scopes)| Oauth Scopes to attach to the cluste |`list(string)`| <pre>[<br/> "https://www.googleapis.com/auth/cloud-platform",<br/> "https://www.googleapis.com/auth/devstorage.read_only",<br/> "https://www.googleapis.com/auth/logging.write",<br/> "https://www.googleapis.com/auth/monitoring",<br/> "https://www.googleapis.com/auth/service.management.readonly",<br/> "https://www.googleapis.com/auth/servicecontrol",<br/> "https://www.googleapis.com/auth/trace.append"<br/>]</pre> | no |
| <aname="input_region"></a> [region](#input\_region)| region |`string`| n/a | yes |
57
58
| <aname="input_services_secondary_range_name"></a> [services\_secondary\_range\_name](#input\_services\_secondary\_range\_name)| VPC Secondary range name for services |`string`|`""`| no |
58
59
| <aname="input_shared_vpc"></a> [shared\_vpc](#input\_shared\_vpc)| Flag to enable shared VPC |`bool`|`false`| no |
59
-
| <aname="input_tags"></a> [tags](#input\_tags)| A map of tags to add to all resources |`map(string)`|`{}`| no |
60
+
| <aname="input_tags"></a> [tags](#input\_tags)| A map of tags to add to all resources. Tags are key-value pairs used for grouping and filtering |`map(string)`|`{}`| no |
61
+
| <aname="input_use_existing_cluster"></a> [use\_existing\_cluster](#input\_use\_existing\_cluster)| Flag to enable the use of an existing GKE cluster or create a new one |`bool`|`false`| no |
This guide will help you to migrate your terraform code across versions. Keeping your terraform state to the latest version is always recommeneded
4
+
5
+
## Upgrade guide from 0.3.x to 0.4.x
6
+
7
+
Changes, we introduced `use_existing_cluster` variable, which allows you to use an existing cluster.
8
+
Few Modules are shifted to using count block to support this feature.
9
+
10
+
1. Ensure that you are running on the latest version of 0.3.x
11
+
2. Move to `0.4.0` and run the following command
12
+
13
+
```bash
14
+
terraform init -upgrade
15
+
16
+
terraform state mv 'google_container_cluster.cluster''google_container_cluster.cluster[0]'
17
+
terraform state mv 'google_container_node_pool.generic''google_container_node_pool.generic[0]'
18
+
terraform state mv 'google_container_node_pool.control_plane_pool''google_container_node_pool.control_plane_pool[0]'# If control plane is enabled, else skip this step
19
+
```
20
+
21
+
3. Run terraform plan to check if there is any drift
0 commit comments