-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 43: Fix issue with single zone, and update test for the problem. #50
Changes from 1 commit
ab5e1e4
2b0aca1
fc09822
1f4dd21
e4345be
57e8334
911a75e
ca8f15e
216d593
f9cae1a
a62416e
8427c3c
8ec5679
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Simple Zonal Cluster | ||
|
||
This example illustrates how to create a simple cluster. | ||
|
||
[^]: (autogen_docs_start) | ||
|
||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| compute_engine_service_account | Service account to associate to the nodes in the cluster | string | - | yes | | ||
| credentials_path | The path to the GCP credentials JSON file | string | - | yes | | ||
| ip_range_pods | The secondary ip range to use for pods | string | - | yes | | ||
| ip_range_services | The secondary ip range to use for pods | string | - | yes | | ||
| network | The VPC network to host the cluster in | string | - | yes | | ||
| project_id | The project ID to host the cluster in | string | - | yes | | ||
| region | The region to host the cluster in | string | - | yes | | ||
| subnetwork | The subnetwork to host the cluster in | string | - | yes | | ||
| zones | The zone to host the cluster in (required if is a zonal cluster) | list | - | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| ca_certificate | | | ||
| client_token | | | ||
| cluster_name | Cluster name | | ||
| credentials_path | | | ||
| ip_range_pods | The secondary IP range used for pods | | ||
| ip_range_services | The secondary IP range used for services | | ||
| kubernetes_endpoint | | | ||
| location | | | ||
| master_kubernetes_version | The master Kubernetes version | | ||
| network | | | ||
| project_id | | | ||
| region | | | ||
| subnetwork | | | ||
| zones | List of zones in which the cluster resides | | ||
|
||
[^]: (autogen_docs_end) | ||
|
||
To provision this example, run the following from within this directory: | ||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
cluster_type = "single-zone" | ||
} | ||
|
||
provider "google" { | ||
credentials = "${file(var.credentials_path)}" | ||
region = "${var.region}" | ||
} | ||
|
||
module "gke" { | ||
source = "../../" | ||
project_id = "${var.project_id}" | ||
name = "${local.cluster_type}-cluster" | ||
regional = false | ||
region = "${var.region}" | ||
zones = "${list(element(var.zones, 1))}" | ||
network = "${var.network}" | ||
subnetwork = "${var.subnetwork}" | ||
ip_range_pods = "${var.ip_range_pods}" | ||
ip_range_services = "${var.ip_range_services}" | ||
kubernetes_version = "1.11.4-gke.13" | ||
node_version = "1.11.4-gke.13" | ||
service_account = "${var.compute_engine_service_account}" | ||
} | ||
|
||
data "google_client_config" "default" {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "kubernetes_endpoint" { | ||
sensitive = true | ||
value = "${module.gke.endpoint}" | ||
} | ||
|
||
output "client_token" { | ||
sensitive = true | ||
value = "${base64encode(data.google_client_config.default.access_token)}" | ||
} | ||
|
||
output "ca_certificate" { | ||
value = "${module.gke.ca_certificate}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// These outputs are used to test the module with kitchen-terraform | ||
// They do not need to be included in real-world uses of this module | ||
|
||
output "project_id" { | ||
value = "${var.project_id}" | ||
} | ||
|
||
output "credentials_path" { | ||
value = "${var.credentials_path}" | ||
} | ||
|
||
output "region" { | ||
value = "${module.gke.region}" | ||
} | ||
|
||
output "cluster_name" { | ||
description = "Cluster name" | ||
value = "${module.gke.name}" | ||
} | ||
|
||
output "network" { | ||
value = "${var.network}" | ||
} | ||
|
||
output "subnetwork" { | ||
value = "${var.subnetwork}" | ||
} | ||
|
||
output "location" { | ||
value = "${module.gke.location}" | ||
} | ||
|
||
output "ip_range_pods" { | ||
description = "The secondary IP range used for pods" | ||
value = "${var.ip_range_pods}" | ||
} | ||
|
||
output "ip_range_services" { | ||
description = "The secondary IP range used for services" | ||
value = "${var.ip_range_services}" | ||
} | ||
|
||
output "zones" { | ||
description = "List of zones in which the cluster resides" | ||
value = "${module.gke.zones}" | ||
} | ||
|
||
output "master_kubernetes_version" { | ||
description = "The master Kubernetes version" | ||
value = "${module.gke.master_version}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "project_id" { | ||
description = "The project ID to host the cluster in" | ||
} | ||
|
||
variable "credentials_path" { | ||
description = "The path to the GCP credentials JSON file" | ||
} | ||
|
||
variable "region" { | ||
description = "The region to host the cluster in" | ||
} | ||
|
||
variable "zones" { | ||
type = "list" | ||
description = "The zone to host the cluster in (required if is a zonal cluster)" | ||
} | ||
|
||
variable "network" { | ||
description = "The VPC network to host the cluster in" | ||
} | ||
|
||
variable "subnetwork" { | ||
description = "The subnetwork to host the cluster in" | ||
} | ||
|
||
variable "ip_range_pods" { | ||
description = "The secondary ip range to use for pods" | ||
} | ||
|
||
variable "ip_range_services" { | ||
description = "The secondary ip range to use for pods" | ||
} | ||
|
||
variable "compute_engine_service_account" { | ||
description = "Service account to associate to the nodes in the cluster" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ locals { | |
} | ||
|
||
cluster_type_output_regional_zones = "${concat(google_container_cluster.primary.*.additional_zones, list(list()))}" | ||
cluster_type_output_zonal_zones = "${concat(google_container_cluster.zonal_primary.*.additional_zones, list(list()))}" | ||
cluster_type_output_zonal_zones = "${concat(slice(var.zones,1,length(var.zones)), list(list()))}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the relevant change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding, is the issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I was able to clarify my understanding back in the bug report in #43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that's exactly right. When there's no additional zones, the provider returns null, which breaks that logic. |
||
|
||
cluster_type_output_zones = { | ||
regional = "${local.cluster_type_output_regional_zones[0]}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module "example" { | ||
source = "../../../examples/single_zone" | ||
|
||
project_id = "${var.project_id}" | ||
credentials_path = "${local.credentials_path}" | ||
region = "${var.region}" | ||
zones = ["${var.zones}"] | ||
network = "${google_compute_network.main.name}" | ||
subnetwork = "${google_compute_subnetwork.main.name}" | ||
ip_range_pods = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}" | ||
ip_range_services = "${google_compute_subnetwork.main.secondary_ip_range.1.range_name}" | ||
compute_engine_service_account = "${var.compute_engine_service_account}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
credentials_path = "${path.module}/${var.credentials_path_relative}" | ||
} | ||
|
||
resource "random_string" "suffix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
} | ||
|
||
provider "google" { | ||
credentials = "${file(local.credentials_path)}" | ||
project = "${var.project_id}" | ||
} | ||
|
||
resource "google_compute_network" "main" { | ||
name = "cft-gke-test-${random_string.suffix.result}" | ||
auto_create_subnetworks = "false" | ||
} | ||
|
||
resource "google_compute_subnetwork" "main" { | ||
name = "cft-gke-test-${random_string.suffix.result}" | ||
ip_cidr_range = "10.0.0.0/17" | ||
region = "${var.region}" | ||
network = "${google_compute_network.main.self_link}" | ||
|
||
secondary_ip_range { | ||
range_name = "cft-gke-test-pods-${random_string.suffix.result}" | ||
ip_cidr_range = "192.168.0.0/18" | ||
} | ||
|
||
secondary_ip_range { | ||
range_name = "cft-gke-test-services-${random_string.suffix.result}" | ||
ip_cidr_range = "192.168.64.0/18" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing a full new example/fixture, could we just make the simple_zonal example use a single zone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure