Skip to content

Commit 839093c

Browse files
DrFaust92apeabodygemini-code-assist[bot]
authored
fix: additional_ip_ranges_config (#2458)
Signed-off-by: drfaust92 <[email protected]> Co-authored-by: Andrew Peabody <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 039c927 commit 839093c

File tree

44 files changed

+977
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+977
-22
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ resource "google_container_cluster" "primary" {
557557
dynamic "additional_ip_ranges_config" {
558558
for_each = var.additional_ip_ranges_config
559559
content {
560-
subnetwork = var.additional_ip_ranges_config.subnetwork
561-
pod_ipv4_range_names = var.additional_ip_ranges_config.pod_ipv4_range_names
560+
subnetwork = additional_ip_ranges_config.value.subnetwork
561+
pod_ipv4_range_names = additional_ip_ranges_config.value.pod_ipv4_range_names
562562
}
563563
}
564564
stack_type = var.stack_type

build/int.cloudbuild.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ steps:
8989
- verify simple-regional-local
9090
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
9191
args: ['/bin/bash', '-c', 'cft test run TestSimpleRegional --stage teardown --verbose']
92+
- id: apply simple-regional-additional-local
93+
waitFor:
94+
- init-all
95+
- teardown simple-regional-local
96+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
97+
args: ['/bin/bash', '-c', 'cft test run TestSimpleRegionalAdditionalIPRanges --stage apply --verbose']
98+
- id: verify simple-regional-additional-local
99+
waitFor:
100+
- apply simple-regional-additional-local
101+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
102+
args: ['/bin/bash', '-c', 'cft test run TestSimpleRegionalAdditionalIPRanges --stage verify --verbose']
103+
- id: teardown simple-regional-additional-local
104+
waitFor:
105+
- verify simple-regional-additional-local
106+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
107+
args: ['/bin/bash', '-c', 'cft test run TestSimpleRegionalAdditionalIPRanges --stage teardown --verbose']
92108
- id: apply simple-regional-private-local
93109
waitFor:
94110
- init-all

cluster.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ resource "google_container_cluster" "primary" {
424424
dynamic "additional_ip_ranges_config" {
425425
for_each = var.additional_ip_ranges_config
426426
content {
427-
subnetwork = var.additional_ip_ranges_config.subnetwork
428-
pod_ipv4_range_names = var.additional_ip_ranges_config.pod_ipv4_range_names
427+
subnetwork = additional_ip_ranges_config.value.subnetwork
428+
pod_ipv4_range_names = additional_ip_ranges_config.value.pod_ipv4_range_names
429429
}
430430
}
431431
stack_type = var.stack_type
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Simple Regional Cluster
2+
3+
This example illustrates how to create a simple cluster.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| additional\_ip\_pod\_range | The secondary ip range to use for pods in the additional range | `any` | n/a | yes |
11+
| additional\_ip\_pod\_range\_subnetwork | The subnetwork to host the additional pod range in | `any` | n/a | yes |
12+
| cluster\_name\_suffix | A suffix to append to the default cluster name | `string` | `""` | no |
13+
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | `any` | n/a | yes |
14+
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
15+
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
16+
| network | The VPC network to host the cluster in | `any` | n/a | yes |
17+
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
18+
| region | The region to host the cluster in | `any` | n/a | yes |
19+
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
20+
21+
## Outputs
22+
23+
| Name | Description |
24+
|------|-------------|
25+
| ca\_certificate | n/a |
26+
| client\_token | n/a |
27+
| cluster\_name | Cluster name |
28+
| ip\_range\_pods | The secondary IP range used for pods |
29+
| ip\_range\_services | The secondary IP range used for services |
30+
| kubernetes\_endpoint | n/a |
31+
| location | n/a |
32+
| master\_kubernetes\_version | The master Kubernetes version |
33+
| network | n/a |
34+
| project\_id | n/a |
35+
| region | n/a |
36+
| service\_account | The default service account used for running nodes. |
37+
| subnetwork | n/a |
38+
| zones | List of zones in which the cluster resides |
39+
40+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
41+
42+
To provision this example, run the following from within this directory:
43+
- `terraform init` to get the plugins
44+
- `terraform plan` to see the infrastructure plan
45+
- `terraform apply` to apply the infrastructure build
46+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
cluster_type = "simple-regional-add-ip"
19+
}
20+
21+
data "google_client_config" "default" {}
22+
23+
provider "kubernetes" {
24+
host = "https://${module.gke.endpoint}"
25+
token = data.google_client_config.default.access_token
26+
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
27+
}
28+
29+
module "gke" {
30+
source = "terraform-google-modules/kubernetes-engine/google"
31+
version = "~> 41.0"
32+
33+
project_id = var.project_id
34+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
35+
regional = true
36+
region = var.region
37+
network = var.network
38+
subnetwork = var.subnetwork
39+
ip_range_pods = var.ip_range_pods
40+
ip_range_services = var.ip_range_services
41+
create_service_account = false
42+
service_account = var.compute_engine_service_account
43+
enable_cost_allocation = true
44+
deletion_protection = false
45+
46+
additional_ip_ranges_config = [
47+
{
48+
subnetwork = "projects/${var.project_id}/regions/${var.region}/subnetworks/${var.additional_ip_pod_range_subnetwork}"
49+
pod_ipv4_range_names = [var.additional_ip_pod_range]
50+
}
51+
]
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "kubernetes_endpoint" {
18+
sensitive = true
19+
value = module.gke.endpoint
20+
}
21+
22+
output "client_token" {
23+
sensitive = true
24+
value = base64encode(data.google_client_config.default.access_token)
25+
}
26+
27+
output "ca_certificate" {
28+
value = module.gke.ca_certificate
29+
}
30+
31+
output "service_account" {
32+
description = "The default service account used for running nodes."
33+
value = module.gke.service_account
34+
}
35+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// These outputs are used to test the module with kitchen-terraform
18+
// They do not need to be included in real-world uses of this module
19+
20+
output "project_id" {
21+
value = var.project_id
22+
}
23+
24+
output "region" {
25+
value = module.gke.region
26+
}
27+
28+
output "cluster_name" {
29+
description = "Cluster name"
30+
value = module.gke.name
31+
}
32+
33+
output "network" {
34+
value = var.network
35+
}
36+
37+
output "subnetwork" {
38+
value = var.subnetwork
39+
}
40+
41+
output "location" {
42+
value = module.gke.location
43+
}
44+
45+
output "ip_range_pods" {
46+
description = "The secondary IP range used for pods"
47+
value = var.ip_range_pods
48+
}
49+
50+
output "ip_range_services" {
51+
description = "The secondary IP range used for services"
52+
value = var.ip_range_services
53+
}
54+
55+
output "zones" {
56+
description = "List of zones in which the cluster resides"
57+
value = module.gke.zones
58+
}
59+
60+
output "master_kubernetes_version" {
61+
description = "The master Kubernetes version"
62+
value = module.gke.master_version
63+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to host the cluster in"
19+
}
20+
21+
variable "cluster_name_suffix" {
22+
description = "A suffix to append to the default cluster name"
23+
default = ""
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
}
29+
30+
variable "network" {
31+
description = "The VPC network to host the cluster in"
32+
}
33+
34+
variable "subnetwork" {
35+
description = "The subnetwork to host the cluster in"
36+
}
37+
38+
variable "ip_range_pods" {
39+
description = "The secondary ip range to use for pods"
40+
}
41+
42+
variable "ip_range_services" {
43+
description = "The secondary ip range to use for services"
44+
}
45+
46+
variable "compute_engine_service_account" {
47+
description = "Service account to associate to the nodes in the cluster"
48+
}
49+
50+
variable "additional_ip_pod_range_subnetwork" {
51+
description = "The subnetwork to host the additional pod range in"
52+
}
53+
54+
variable "additional_ip_pod_range" {
55+
description = "The secondary ip range to use for pods in the additional range"
56+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_providers {
19+
google = {
20+
source = "hashicorp/google"
21+
}
22+
kubernetes = {
23+
source = "hashicorp/kubernetes"
24+
}
25+
}
26+
required_version = ">= 0.13"
27+
}

metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ spec:
120120
location: examples/simple_fleet_app_operator_permissions
121121
- name: simple_regional
122122
location: examples/simple_regional
123+
- name: simple_regional_additional_ip_ranges
124+
location: examples/simple_regional_additional_ip_ranges
123125
- name: simple_regional_beta
124126
location: examples/simple_regional_beta
125127
- name: simple_regional_cluster_autoscaling

0 commit comments

Comments
 (0)