Skip to content

Commit 3883600

Browse files
authored
Merge pull request GoogleCloudPlatform#4247 from ighosh98/develop
kubernetes provider module implementation
2 parents 094e9ee + e3c65d5 commit 3883600

10 files changed

Lines changed: 256 additions & 0 deletions

File tree

community/modules/management/helm-install/helm_install/README.md renamed to community/modules/management/dependencies-installer/helm_install/README.md

File renamed without changes.

community/modules/management/helm-install/helm_install/main.tf renamed to community/modules/management/dependencies-installer/helm_install/main.tf

File renamed without changes.

community/modules/management/helm-install/helm_install/metadata.yaml renamed to community/modules/management/dependencies-installer/helm_install/metadata.yaml

File renamed without changes.

community/modules/management/helm-install/helm_install/variables.tf renamed to community/modules/management/dependencies-installer/helm_install/variables.tf

File renamed without changes.

community/modules/management/helm-install/helm_install/versions.tf renamed to community/modules/management/dependencies-installer/helm_install/versions.tf

File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Requirements
3+
4+
| Name | Version |
5+
|------|---------|
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
7+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | ~> 2.23 |
8+
9+
## Providers
10+
11+
| Name | Version |
12+
|------|---------|
13+
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | ~> 2.23 |
14+
15+
## Modules
16+
17+
No modules.
18+
19+
## Resources
20+
21+
| Name | Type |
22+
|------|------|
23+
| [kubernetes_manifest.apply_manifests](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
24+
25+
## Inputs
26+
27+
| Name | Description | Type | Default | Required |
28+
|------|-------------|------|---------|:--------:|
29+
| <a name="input_content"></a> [content](#input\_content) | The YAML body to apply to gke cluster. | `string` | `null` | no |
30+
| <a name="input_field_manager"></a> [field\_manager](#input\_field\_manager) | (Optional) Configure field manager options. The `name` is the name of the field manager. The `force_conflicts` flag allows overriding conflicts. | <pre>object({<br/> name = optional(string, null)<br/> force_conflicts = optional(bool, false)<br/> })</pre> | `null` | no |
31+
| <a name="input_resource_timeouts"></a> [resource\_timeouts](#input\_resource\_timeouts) | (Optional) Configure custom timeouts for the create, update, and delete operations of the resource. These timeouts also govern the duration for any 'wait' conditions to be met. | <pre>object({<br/> create = optional(string, null)<br/> update = optional(string, null)<br/> delete = optional(string, null)<br/> })</pre> | <pre>{<br/> "create": "15m",<br/> "delete": "5m",<br/> "update": "10m"<br/>}</pre> | no |
32+
| <a name="input_source_path"></a> [source\_path](#input\_source\_path) | The source for manifest(s) to apply to gke cluster. Acceptable sources are a local yaml or template (.tftpl) file path, a directory (ends with '/') containing yaml or template files, and a url for a yaml file. | `string` | `""` | no |
33+
| <a name="input_template_vars"></a> [template\_vars](#input\_template\_vars) | The values to populate template file(s) with. | `any` | `null` | no |
34+
| <a name="input_wait_for_fields"></a> [wait\_for\_fields](#input\_wait\_for\_fields) | (Optional) A map of attribute paths and desired patterns to be matched. After each apply the provider will wait for all attributes listed here to reach a value that matches the desired pattern. | `map(string)` | `{}` | no |
35+
| <a name="input_wait_for_rollout"></a> [wait\_for\_rollout](#input\_wait\_for\_rollout) | Wait or not for Deployments and APIService to complete rollout. See [kubectl wait](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_wait/) for more details. | `bool` | `true` | no |
36+
37+
## Outputs
38+
39+
No outputs.
40+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright 2025 "Google LLC"
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
locals {
16+
yaml_separator = "\n---"
17+
18+
# --- 1. Determine the primary source of YAML content ---
19+
# Prioritize 'content' variable if provided
20+
primary_content_body = var.content != "" ? var.content : null
21+
22+
# --- 2. Handle 'source_path' based on its type (File vs. Directory) ---
23+
24+
# Check if source_path is a directory (indicated by trailing slash)
25+
is_directory = endswith(var.source_path, "/")
26+
directory_absolute_path = local.is_directory ? abspath(var.source_path) : null
27+
28+
# Check if source_path is a single yaml or tftpl file (only if not a directory)
29+
is_single_file = !local.is_directory && (
30+
length(regexall("\\.yaml$", lower(var.source_path))) > 0 ||
31+
length(regexall("\\.tftpl$", lower(var.source_path))) > 0
32+
)
33+
single_file_raw_content = local.is_single_file ? (
34+
length(regexall("\\.tftpl$", lower(var.source_path))) > 0 ?
35+
templatefile(abspath(var.source_path), var.template_vars) :
36+
file(abspath(var.source_path))
37+
) : null
38+
39+
# Docs from primary_content_body
40+
docs_from_primary_source = [
41+
for doc in split(local.yaml_separator, coalesce(local.primary_content_body, local.single_file_raw_content, "")) : trimspace(doc)
42+
if length(trimspace(doc)) > 0
43+
]
44+
45+
# Docs from .yaml files in a directory
46+
directory_yaml_files = local.is_directory ? fileset(local.directory_absolute_path, "*.yaml") : []
47+
docs_from_directory_yamls = flatten([
48+
for file_name in local.directory_yaml_files :
49+
[
50+
for doc in split(local.yaml_separator, file(format("%s/%s", local.directory_absolute_path, file_name))) : trimspace(doc)
51+
if length(trimspace(doc)) > 0
52+
]
53+
])
54+
55+
# Docs from .tftpl files in a directory
56+
directory_template_files = local.is_directory ? fileset(local.directory_absolute_path, "*.tftpl") : []
57+
docs_from_directory_templates = flatten([
58+
for file_name in local.directory_template_files :
59+
[
60+
for doc in split(local.yaml_separator, templatefile(format("%s/%s", local.directory_absolute_path, file_name), var.template_vars)) : trimspace(doc)
61+
if length(trimspace(doc)) > 0
62+
]
63+
])
64+
65+
all_parsed_docs = concat(
66+
local.docs_from_primary_source,
67+
local.docs_from_directory_yamls,
68+
local.docs_from_directory_templates
69+
)
70+
71+
# --- 5. Create the final map for `for_each` (keys must be unique strings) ---
72+
docs_map = tomap({
73+
for index, doc in local.all_parsed_docs : index => doc
74+
if length(trimspace(doc)) > 0
75+
})
76+
}
77+
78+
# Apply all manifest files dynamically
79+
resource "kubernetes_manifest" "apply_manifests" {
80+
for_each = local.docs_map
81+
manifest = yamldecode(each.value)
82+
timeouts {
83+
create = var.resource_timeouts.create
84+
update = var.resource_timeouts.update
85+
delete = var.resource_timeouts.delete
86+
}
87+
88+
dynamic "wait" {
89+
for_each = var.wait_for_rollout ? [1] : []
90+
content {
91+
rollout = var.wait_for_rollout
92+
fields = var.wait_for_fields
93+
}
94+
}
95+
96+
# Configure the 'field_manager' block dynamically
97+
dynamic "field_manager" {
98+
for_each = var.field_manager != null ? [var.field_manager] : []
99+
content {
100+
name = field_manager.value.name
101+
force_conflicts = field_manager.value.force_conflicts
102+
}
103+
}
104+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 "Google LLC"
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
---
15+
16+
spec:
17+
requirements:
18+
services:
19+
- container.googleapis.com
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2025 "Google LLC"
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Description: Input variables for the generic Helm release module.
16+
17+
variable "content" {
18+
description = "The YAML body to apply to gke cluster."
19+
type = string
20+
default = null
21+
}
22+
23+
variable "source_path" {
24+
description = "The source for manifest(s) to apply to gke cluster. Acceptable sources are a local yaml or template (.tftpl) file path, a directory (ends with '/') containing yaml or template files, and a url for a yaml file."
25+
type = string
26+
default = ""
27+
}
28+
29+
variable "template_vars" {
30+
description = "The values to populate template file(s) with."
31+
type = any
32+
default = null
33+
}
34+
35+
variable "wait_for_rollout" {
36+
description = "Wait or not for Deployments and APIService to complete rollout. See [kubectl wait](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_wait/) for more details."
37+
type = bool
38+
default = true
39+
}
40+
41+
42+
variable "wait_for_fields" {
43+
description = "(Optional) A map of attribute paths and desired patterns to be matched. After each apply the provider will wait for all attributes listed here to reach a value that matches the desired pattern."
44+
type = map(string)
45+
default = {}
46+
}
47+
48+
variable "resource_timeouts" {
49+
description = "(Optional) Configure custom timeouts for the create, update, and delete operations of the resource. These timeouts also govern the duration for any 'wait' conditions to be met."
50+
type = object({
51+
create = optional(string, null)
52+
update = optional(string, null)
53+
delete = optional(string, null)
54+
})
55+
default = {
56+
create = "15m" # Default create timeout, also covers waiting for initial conditions
57+
update = "10m" # Default update timeout, also covers waiting for update conditions
58+
delete = "5m" # Default delete timeout
59+
}
60+
}
61+
62+
variable "field_manager" {
63+
description = "(Optional) Configure field manager options. The `name` is the name of the field manager. The `force_conflicts` flag allows overriding conflicts."
64+
type = object({
65+
name = optional(string, null)
66+
force_conflicts = optional(bool, false)
67+
})
68+
default = null
69+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2025 "Google LLC"
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
terraform {
16+
# Defines the providers that this module depends on and their versions.
17+
required_providers {
18+
kubernetes = {
19+
source = "hashicorp/kubernetes"
20+
version = "~> 2.23"
21+
}
22+
}
23+
required_version = ">= 1.3"
24+
}

0 commit comments

Comments
 (0)