Skip to content

Commit f3647e4

Browse files
authored
Merge branch 'master' into feature/node-pools-oauth-scopes
2 parents 917f113 + 567c586 commit f3647e4

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

+384
-321
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ test/integration/gcloud/config.sh
4747
test/integration/tmp
4848

4949
credentials.json
50+
51+
# File to populate env vars used by Docker test runs
52+
.envrc

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ docker_create: docker_build_kitchen_terraform
130130
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
131131
-v $(CURDIR):/cft/workdir \
132132
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
133-
/bin/bash -c "kitchen create"
133+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"
134134

135135
.PHONY: docker_converge
136136
docker_converge:
@@ -144,7 +144,7 @@ docker_converge:
144144
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
145145
-v $(CURDIR):/cft/workdir \
146146
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
147-
/bin/bash -c "kitchen converge && kitchen converge"
147+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge && kitchen converge"
148148

149149
.PHONY: docker_verify
150150
docker_verify:
@@ -158,7 +158,7 @@ docker_verify:
158158
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
159159
-v $(CURDIR):/cft/workdir \
160160
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
161-
/bin/bash -c "kitchen verify"
161+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"
162162

163163
.PHONY: docker_destroy
164164
docker_destroy:
@@ -172,7 +172,7 @@ docker_destroy:
172172
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
173173
-v $(CURDIR):/cft/workdir \
174174
${DOCKER_IMAGE_KITCHEN_TERRAFORM}:${DOCKER_TAG_KITCHEN_TERRAFORM} \
175-
/bin/bash -c "kitchen destroy"
175+
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"
176176

177177
.PHONY: test_integration_docker
178178
test_integration_docker:

README.md

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -100,64 +100,62 @@ Then perform the following commands on the root folder:
100100

101101
[^]: (autogen_docs_start)
102102

103-
104103
## Inputs
105104

106105
| Name | Description | Type | Default | Required |
107106
|------|-------------|:----:|:-----:|:-----:|
108-
| description | The description of the cluster | string | `` | no |
109-
| horizontal_pod_autoscaling | Enable horizontal pod autoscaling addon | string | `true` | no |
110-
| http_load_balancing | Enable httpload balancer addon | string | `true` | no |
111-
| ip_masq_link_local | Whether to masquerade traffic to the link-local prefix (169.254.0.0/16). | string | `false` | no |
112-
| ip_masq_resync_interval | The interval at which the agent attempts to sync its ConfigMap file from the disk. | string | `60s` | no |
113-
| ip_range_pods | The secondary ip range to use for pods | string | - | yes |
114-
| ip_range_services | The secondary ip range to use for pods | string | - | yes |
115-
| kubernetes_dashboard | Enable kubernetes dashboard addon | string | `false` | no |
116-
| kubernetes_version | The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region. | string | `latest` | no |
117-
| logging_service | The logging service that the cluster should write logs to. Available options include logging.googleapis.com, logging.googleapis.com/kubernetes (beta), and none | string | `logging.googleapis.com` | no |
118-
| maintenance_start_time | Time window specified for daily maintenance operations in RFC3339 format | string | `05:00` | no |
119-
| master_authorized_networks_config | The desired configuration options for master authorized networks. Omit the nested cidr_blocks attribute to disallow external access (except the cluster node IPs, which GKE automatically whitelists)<br><br> ### example format ### master_authorized_networks_config = [{ cidr_blocks = [{ cidr_block = "10.0.0.0/8" display_name = "example_network" }], }] | list | `<list>` | no |
120-
| monitoring_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | string | `monitoring.googleapis.com` | no |
121-
| name | The name of the cluster (required) | string | - | yes |
122-
| network | The VPC network to host the cluster in (required) | string | - | yes |
123-
| network_policy | Enable network policy addon | string | `false` | no |
124-
| network_project_id | The project ID of the shared VPC's host (for shared vpc support) | string | `` | no |
125-
| node_pools | List of maps containing node pools | list | `<list>` | no |
126-
| node_pools_labels | Map of maps containing node labels by node-pool name | map | `<map>` | no |
127-
| node_pools_metadata | Map of maps containing node metadata by node-pool name | map | `<map>` | no |
128-
| node_pools_tags | Map of lists containing node network tags by node-pool name | map | `<map>` | no |
129-
| node_pools_oauth_scopes | Map of lists containing node oauth scopes by node-pool name | map | `<map>` | no |
130-
| node_pools_taints | Map of lists containing node taints by node-pool name | map | `<map>` | no |
131-
| node_version | The Kubernetes version of the node pools. Defaults kubernetes_version (master) variable and can be overridden for individual node pools by setting the `version` key on them. Must be empyty or set the same as master at cluster creation. | string | `` | no |
132-
| non_masquerade_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list | `<list>` | no |
133-
| project_id | The project ID to host the cluster in (required) | string | - | yes |
134-
| region | The region to host the cluster in (required) | string | - | yes |
135-
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | string | `true` | no |
136-
| remove_default_node_pool | Remove default node pool while setting up the cluster | string | `false` | no |
137-
| service_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `` | no |
138-
| stub_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
139-
| subnetwork | The subnetwork to host the cluster in (required) | string | - | yes |
107+
| description | The description of the cluster | string | `""` | no |
108+
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | string | `"true"` | no |
109+
| http\_load\_balancing | Enable httpload balancer addon | string | `"true"` | no |
110+
| ip\_masq\_link\_local | Whether to masquerade traffic to the link-local prefix (169.254.0.0/16). | string | `"false"` | no |
111+
| ip\_masq\_resync\_interval | The interval at which the agent attempts to sync its ConfigMap file from the disk. | string | `"60s"` | no |
112+
| ip\_range\_pods | The _name_ of the secondary subnet ip range to use for pods | string | - | yes |
113+
| ip\_range\_services | The _name_ of the secondary subnet ip range to use for services | string | - | yes |
114+
| kubernetes\_dashboard | Enable kubernetes dashboard addon | string | `"false"` | no |
115+
| kubernetes\_version | The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region. | string | `"latest"` | no |
116+
| logging\_service | The logging service that the cluster should write logs to. Available options include logging.googleapis.com, logging.googleapis.com/kubernetes (beta), and none | string | `"logging.googleapis.com"` | no |
117+
| maintenance\_start\_time | Time window specified for daily maintenance operations in RFC3339 format | string | `"05:00"` | no |
118+
| master\_authorized\_networks\_config | The desired configuration options for master authorized networks. Omit the nested cidr_blocks attribute to disallow external access (except the cluster node IPs, which GKE automatically whitelists)<br><br> ### example format ### master_authorized_networks_config = [{ cidr_blocks = [{ cidr_block = "10.0.0.0/8" display_name = "example_network" }], }] | list | `<list>` | no |
119+
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | string | `"monitoring.googleapis.com"` | no |
120+
| name | The name of the cluster (required) | string | n/a | yes |
121+
| network | The VPC network to host the cluster in (required) | string | n/a | yes |
122+
| network\_policy | Enable network policy addon | string | `"false"` | no |
123+
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | string | `""` | no |
124+
| node\_pools | List of maps containing node pools | list | `<list>` | no |
125+
| node\_pools\_labels | Map of maps containing node labels by node-pool name | map | `<map>` | no |
126+
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | map | `<map>` | no |
127+
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | map | `<map>` | no |
128+
| node\_pools\_taints | Map of lists containing node taints by node-pool name | map | `<map>` | no |
129+
| node\_version | The Kubernetes version of the node pools. Defaults kubernetes_version (master) variable and can be overridden for individual node pools by setting the `version` key on them. Must be empyty or set the same as master at cluster creation. | string | `""` | no |
130+
| non\_masquerade\_cidrs | List of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading. | list | `<list>` | no |
131+
| project\_id | The project ID to host the cluster in (required) | string | n/a | yes |
132+
| region | The region to host the cluster in (required) | string | n/a | yes |
133+
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | string | `"true"` | no |
134+
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | string | `"false"` | no |
135+
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no |
136+
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
137+
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
140138
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `<list>` | no |
141139

142140
## Outputs
143141

144142
| Name | Description |
145143
|------|-------------|
146-
| ca_certificate | Cluster ca certificate (base64 encoded) |
144+
| ca\_certificate | Cluster ca certificate (base64 encoded) |
147145
| endpoint | Cluster endpoint |
148-
| horizontal_pod_autoscaling_enabled | Whether horizontal pod autoscaling enabled |
149-
| http_load_balancing_enabled | Whether http load balancing enabled |
150-
| kubernetes_dashboard_enabled | Whether kubernetes dashboard enabled |
146+
| horizontal\_pod\_autoscaling\_enabled | Whether horizontal pod autoscaling enabled |
147+
| http\_load\_balancing\_enabled | Whether http load balancing enabled |
148+
| kubernetes\_dashboard\_enabled | Whether kubernetes dashboard enabled |
151149
| location | Cluster location (region if regional cluster, zone if zonal cluster) |
152-
| logging_service | Logging service used |
153-
| master_authorized_networks_config | Networks from which access to master is permitted |
154-
| master_version | Current master kubernetes version |
155-
| min_master_version | Minimum master kubernetes version |
156-
| monitoring_service | Monitoring service used |
150+
| logging\_service | Logging service used |
151+
| master\_authorized\_networks\_config | Networks from which access to master is permitted |
152+
| master\_version | Current master kubernetes version |
153+
| min\_master\_version | Minimum master kubernetes version |
154+
| monitoring\_service | Monitoring service used |
157155
| name | Cluster name |
158-
| network_policy_enabled | Whether network policy enabled |
159-
| node_pools_names | List of node pools names |
160-
| node_pools_versions | List of node pools versions |
156+
| network\_policy\_enabled | Whether network policy enabled |
157+
| node\_pools\_names | List of node pools names |
158+
| node\_pools\_versions | List of node pools versions |
161159
| region | Cluster region |
162160
| type | Cluster type (regional / zonal) |
163161
| zones | List of zones in which the cluster resides |
@@ -190,6 +188,7 @@ following project roles:
190188
- roles/container.developer
191189
- roles/iam.serviceAccountAdmin
192190
- roles/iam.serviceAccountUser
191+
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)
193192

194193
### Enable APIs
195194
In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created:
@@ -248,6 +247,9 @@ The test-kitchen instances in `test/fixtures/` wrap identically-named examples i
248247

249248
1. Configure the [test fixtures](#test-configuration)
250249
2. Download a Service Account key with the necessary permissions and put it in the module's root directory with the name `credentials.json`.
250+
- Requires the [permissions to run the module](#configure-a-service-account)
251+
- Requires `roles/compute.networkAdmin` to create the test suite's networks
252+
- Requires `roles/resourcemanager.projectIamAdmin` since service account creation is tested
251253
3. Build the Docker container for testing:
252254

253255
```

auth.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ provider "kubernetes" {
3131
host = "https://${local.cluster_endpoint}"
3232
token = "${data.google_client_config.default.access_token}"
3333
cluster_ca_certificate = "${base64decode(local.cluster_ca_certificate)}"
34-
}
34+
}

autogen/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ following project roles:
191191
- roles/container.developer
192192
- roles/iam.serviceAccountAdmin
193193
- roles/iam.serviceAccountUser
194+
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)
194195

195196
### Enable APIs
196197
In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created:
@@ -249,6 +250,9 @@ The test-kitchen instances in `test/fixtures/` wrap identically-named examples i
249250

250251
1. Configure the [test fixtures](#test-configuration)
251252
2. Download a Service Account key with the necessary permissions and put it in the module's root directory with the name `credentials.json`.
253+
- Requires the [permissions to run the module](#configure-a-service-account)
254+
- Requires `roles/compute.networkAdmin` to create the test suite's networks
255+
- Requires `roles/resourcemanager.projectIamAdmin` since service account creation is tested
252256
3. Build the Docker container for testing:
253257

254258
```

autogen/cluster_regional.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "google_container_cluster" "primary" {
3131

3232
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}"
34-
min_master_version = "${local.kubernetes_version}"
34+
min_master_version = "${local.kubernetes_version_regional}"
3535

3636
logging_service = "${var.logging_service}"
3737
monitoring_service = "${var.monitoring_service}"
@@ -104,7 +104,7 @@ resource "google_container_node_pool" "pools" {
104104
project = "${var.project_id}"
105105
region = "${var.region}"
106106
cluster = "${var.name}"
107-
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}"
107+
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version_regional)}"
108108
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"
109109

110110
autoscaling {

autogen/cluster_zonal.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "google_container_cluster" "zonal_primary" {
3131

3232
network = "${replace(data.google_compute_network.gke_network.self_link, "https://www.googleapis.com/compute/v1/", "")}"
3333
subnetwork = "${replace(data.google_compute_subnetwork.gke_subnetwork.self_link, "https://www.googleapis.com/compute/v1/", "")}"
34-
min_master_version = "${local.kubernetes_version}"
34+
min_master_version = "${local.kubernetes_version_zonal}"
3535

3636
logging_service = "${var.logging_service}"
3737
monitoring_service = "${var.monitoring_service}"
@@ -104,7 +104,7 @@ resource "google_container_node_pool" "zonal_pools" {
104104
project = "${var.project_id}"
105105
zone = "${var.zones[0]}"
106106
cluster = "${var.name}"
107-
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version)}"
107+
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version_zonal)}"
108108
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"
109109

110110
autoscaling {

autogen/main.tf

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ resource "random_shuffle" "available_zones" {
3131
}
3232

3333
locals {
34-
kubernetes_version = "${var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_node_version}"
35-
node_version = "${var.node_version != "" ? var.node_version : local.kubernetes_version}"
36-
custom_kube_dns_config = "${length(keys(var.stub_domains)) > 0 ? true : false}"
37-
network_project_id = "${var.network_project_id != "" ? var.network_project_id : var.project_id}"
34+
kubernetes_version_regional = "${var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.region.latest_master_version}"
35+
kubernetes_version_zonal = "${var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.zone.latest_master_version}"
36+
node_version_regional = "${var.node_version != "" && var.regional ? var.node_version : local.kubernetes_version_regional}"
37+
node_version_zonal = "${var.node_version != "" && !var.regional ? var.node_version : local.kubernetes_version_zonal}"
38+
custom_kube_dns_config = "${length(keys(var.stub_domains)) > 0 ? true : false}"
39+
network_project_id = "${var.network_project_id != "" ? var.network_project_id : var.project_id}"
3840

3941
cluster_type = "${var.regional ? "regional" : "zonal"}"
4042

@@ -149,7 +151,17 @@ locals {
149151
Get available container engine versions
150152
*****************************************/
151153
data "google_container_engine_versions" "region" {
152-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
153-
zone = "${data.google_compute_zones.available.names[0]}"
154+
provider = "google-beta"
155+
region = "${var.region}"
156+
project = "${var.project_id}"
157+
}
158+
159+
data "google_container_engine_versions" "zone" {
160+
provider = "google-beta"
161+
// Work around to prevent a lack of zone declaration from causing regional cluster creation from erroring out due to error
162+
//
163+
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
164+
//
165+
zone = "${var.zones[0] == "" ? data.google_compute_zones.available.names[0] : var.zones[0]}"
154166
project = "${var.project_id}"
155167
}

autogen/sa.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ locals {
2424
resource "google_service_account" "cluster_service_account" {
2525
count = "${var.service_account == "create" ? 1 : 0}"
2626
project = "${var.project_id}"
27-
account_id = "tf-gke-${substr(var.name, 0, 20)}"
27+
account_id = "tf-gke-${substr(var.name, 0, min(20, length(var.name)))}"
2828
display_name = "Terraform-managed service account for cluster ${var.name}"
2929
}
3030

0 commit comments

Comments
 (0)