Skip to content

Commit be5e130

Browse files
authored
Merge pull request #2 from terraform-google-modules/master
update
2 parents 366b5cb + 3945205 commit be5e130

File tree

43 files changed

+713
-50
lines changed

Some content is hidden

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

43 files changed

+713
-50
lines changed

.kitchen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ suites:
8585
backend: local
8686
controls:
8787
- gcloud
88+
- acm
8889
- name: gcp
8990
backend: gcp
9091
controls:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Extending the adopted spec, each change should have a link to its corresponding
1111
### Added
1212

1313
* Support for Shielded Nodes beta feature via `enabled_shielded_nodes` variable. [#300]
14+
* Support for setting node_locations on node pools. [#303]
15+
* Fix for specifying `node_count` on node pools when autoscaling is disabled. [#311]
16+
* Added submodule for installing Anthos Config Management. [#268]
1417

1518
## [v5.1.1] - 2019-10-25
1619

@@ -225,6 +228,10 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
225228
[v0.3.0]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/compare/v0.2.0...v0.3.0
226229
[v0.2.0]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/compare/v0.1.0...v0.2.0
227230

231+
[#268]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/268
232+
[#311]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/311
233+
[#303]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/303
234+
[#300]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/300
228235
[#286]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/286
229236
[#285]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/285
230237
[#284]: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/284

autogen/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ module "gke" {
5555
{
5656
name = "default-node-pool"
5757
machine_type = "n1-standard-2"
58+
{% if beta_cluster %}
59+
node_locations = "us-central1-b,us-central1-c"
60+
{% endif %}
5861
min_count = 1
5962
max_count = 100
6063
disk_size_gb = 100

autogen/cluster.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,28 @@ resource "google_container_node_pool" "pools" {
310310
{% endif %}
311311
project = var.project_id
312312
location = local.location
313+
{% if beta_cluster %}
314+
// use node_locations if provided, defaults to cluster level node_locations if not specified
315+
node_locations = lookup(var.node_pools[count.index], "node_locations", "") != "" ? split(",", var.node_pools[count.index]["node_locations"]) : null
316+
{% endif %}
313317
cluster = google_container_cluster.primary.name
314318
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
315319
var.node_pools[count.index],
316320
"version",
317321
local.node_version,
318322
)
319-
initial_node_count = lookup(
323+
324+
initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
320325
var.node_pools[count.index],
321326
"initial_node_count",
322-
lookup(var.node_pools[count.index], "min_count", 1),
323-
)
327+
lookup(var.node_pools[count.index], "min_count", 1)
328+
) : null
329+
324330
{% if beta_cluster %}
325331
max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null)
326332
{% endif %}
327333

328-
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
334+
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)
329335

330336
dynamic "autoscaling" {
331337
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []

autogen/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ locals {
9292
cluster_output_zones = local.cluster_output_regional_zones
9393

9494
{% if private_cluster %}
95-
cluster_output_endpoint = var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config.0.private_endpoint : google_container_cluster.primary.endpoint
95+
cluster_output_endpoint = var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config.0.private_endpoint : google_container_cluster.primary.private_cluster_config.0.public_endpoint
9696
{% else %}
9797
cluster_output_endpoint = google_container_cluster.primary.endpoint
9898
{% endif %}

build/int.cloudbuild.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
timeout: 12600s
1616
steps:
17+
- id: download acm
18+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
19+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && download_acm']
1720
- id: prepare
1821
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
1922
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment']
@@ -306,6 +309,6 @@ tags:
306309
- 'integration'
307310
substitutions:
308311
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
309-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'
312+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.5.4'
310313
options:
311314
machineType: 'N1_HIGHCPU_8'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ tags:
2424
- 'lint'
2525
substitutions:
2626
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
27-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'
27+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.5.4'

cluster.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ resource "google_container_node_pool" "pools" {
137137
"version",
138138
local.node_version,
139139
)
140-
initial_node_count = lookup(
140+
141+
initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
141142
var.node_pools[count.index],
142143
"initial_node_count",
143-
lookup(var.node_pools[count.index], "min_count", 1),
144-
)
144+
lookup(var.node_pools[count.index], "min_count", 1)
145+
) : null
146+
145147

146-
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
148+
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)
147149

148150
dynamic "autoscaling" {
149151
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []

examples/node_pool/main.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module "gke" {
2727
source = "../../modules/beta-public-cluster/"
2828
project_id = var.project_id
2929
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
30-
regional = false
3130
region = var.region
3231
zones = var.zones
3332
network = var.network
@@ -59,12 +58,24 @@ module "gke" {
5958
auto_repair = false
6059
service_account = var.compute_engine_service_account
6160
},
61+
{
62+
name = "pool-03"
63+
node_locations = "${var.region}-b,${var.region}-c"
64+
autoscaling = false
65+
node_count = 2
66+
machine_type = "n1-standard-2"
67+
disk_type = "pd-standard"
68+
image_type = "COS"
69+
auto_upgrade = true
70+
service_account = var.compute_engine_service_account
71+
},
6272
]
6373

6474
node_pools_oauth_scopes = {
6575
all = []
6676
pool-01 = []
6777
pool-02 = []
78+
pool-03 = []
6879
}
6980

7081
node_pools_metadata = {
@@ -73,6 +84,7 @@ module "gke" {
7384
shutdown-script = file("${path.module}/data/shutdown-script.sh")
7485
}
7586
pool-02 = {}
87+
pool-03 = {}
7688
}
7789

7890
node_pools_labels = {
@@ -83,6 +95,7 @@ module "gke" {
8395
pool-01-example = true
8496
}
8597
pool-02 = {}
98+
pool-03 = {}
8699
}
87100

88101
node_pools_taints = {
@@ -101,6 +114,7 @@ module "gke" {
101114
},
102115
]
103116
pool-02 = []
117+
pool-03 = []
104118
}
105119

106120
node_pools_tags = {
@@ -111,6 +125,7 @@ module "gke" {
111125
"pool-01-example",
112126
]
113127
pool-02 = []
128+
pool-03 = []
114129
}
115130
}
116131

examples/simple_zonal/README.md renamed to examples/simple_zonal_with_acm/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# Simple Zonal Cluster
22

3-
This example illustrates how to create a simple cluster.
3+
This example illustrates how to create a simple cluster and install [Anthos Config Management](https://cloud.google.com/anthos-config-management/docs/).
4+
5+
It incorporates the standard cluster module and the [ACM install module](../../modules/acm).
46

57
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
68
## Inputs
79

810
| Name | Description | Type | Default | Required |
911
|------|-------------|:----:|:-----:|:-----:|
12+
| acm\_policy\_dir | Subfolder containing configs in ACM Git repo | string | `"foo-corp"` | no |
13+
| acm\_sync\_branch | Anthos config management Git branch | string | `"1.0.0"` | no |
14+
| acm\_sync\_repo | Anthos config management Git repo | string | `"[email protected]:GoogleCloudPlatform/csp-config-management.git"` | no |
1015
| cluster\_name\_suffix | A suffix to append to the default cluster name | string | `""` | no |
1116
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |
1217
| ip\_range\_services | The secondary ip range to use for pods | string | n/a | yes |
1318
| network | The VPC network to host the cluster in | string | n/a | yes |
19+
| operator\_path | Path to the operator yaml config. If unset, will download from GCS releases. | string | `"null"` | no |
1420
| project\_id | The project ID to host the cluster in | string | n/a | yes |
1521
| region | The region to host the cluster in | string | n/a | yes |
1622
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
@@ -20,6 +26,7 @@ This example illustrates how to create a simple cluster.
2026

2127
| Name | Description |
2228
|------|-------------|
29+
| acm\_git\_creds\_public | Public key of SSH keypair to allow the Anthos Operator to authenticate to your Git repository. |
2330
| ca\_certificate | |
2431
| client\_token | |
2532
| cluster\_name | Cluster name |

examples/simple_zonal_with_acm/acm.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
module "acm" {
18+
source = "../../modules/acm"
19+
project_id = var.project_id
20+
location = module.gke.location
21+
cluster_name = module.gke.name
22+
sync_repo = var.acm_sync_repo
23+
sync_branch = var.acm_sync_branch
24+
policy_dir = var.acm_policy_dir
25+
cluster_endpoint = module.gke.endpoint
26+
operator_path = var.operator_path
27+
}

examples/simple_zonal/outputs.tf renamed to examples/simple_zonal_with_acm/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ output "service_account" {
3333
value = module.gke.service_account
3434
}
3535

36+
output "acm_git_creds_public" {
37+
description = "Public key of SSH keypair to allow the Anthos Operator to authenticate to your Git repository."
38+
value = module.acm.git_creds_public
39+
}
40+

examples/simple_zonal/variables.tf renamed to examples/simple_zonal_with_acm/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ variable "ip_range_services" {
4848
description = "The secondary ip range to use for pods"
4949
}
5050

51+
variable "acm_sync_repo" {
52+
description = "Anthos config management Git repo"
53+
type = string
54+
default = "[email protected]:GoogleCloudPlatform/csp-config-management.git"
55+
}
56+
57+
variable "acm_sync_branch" {
58+
description = "Anthos config management Git branch"
59+
type = string
60+
default = "1.0.0"
61+
}
62+
63+
variable "acm_policy_dir" {
64+
description = "Subfolder containing configs in ACM Git repo"
65+
type = string
66+
default = "foo-corp"
67+
}
68+
69+
variable "operator_path" {
70+
description = "Path to the operator yaml config. If unset, will download from GCS releases."
71+
type = string
72+
default = null
73+
}

modules/acm/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This fill will be always downloaded by terraform local-exec command from gc bucket
2+
config-management-operator.yaml
3+
/terraform.tfvars

modules/acm/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Terraform Kubernetes Engine ACM Submodule
2+
3+
This module installs [Anthos Config Management](https://cloud.google.com/anthos-config-management/docs/) (ACM) in a Kubernetes cluster.
4+
5+
Specifically, this module automates the following steps for [installing ACM](https://cloud.google.com/anthos-config-management/docs/how-to/installing):
6+
1. Installing the ACM Operator on your cluster.
7+
2. Generating an SSH key for accessing Git and providing it to the Operator
8+
3. Configuring the Operator to connect to your ACM repository
9+
10+
## Usage
11+
12+
There is a [full example](../../examples/simple_zonal_with_acm) provided. Simple usage is as follows:
13+
14+
```tf
15+
module "acm" {
16+
source = "terraform-google-modules/kubernetes-engine/google//modules/acm"
17+
18+
project_id = "my-project-id"
19+
cluster_name = "my-cluster-name"
20+
location = module.gke.location
21+
cluster_endpoint = module.gke.endpoint
22+
23+
sync_repo = "[email protected]:GoogleCloudPlatform/csp-config-management.git"
24+
sync_branch = "1.0.0"
25+
policy_dir = "foo-corp"
26+
}
27+
```
28+
29+
To deploy this config:
30+
1. Run `terraform apply`
31+
2. Inspect the `git_creds_public` [output](#outputs) to retrieve the public key used for accessing Git. Whitelist this key for access to your Git repo. Instructions for some popular Git hosting providers are included for convenience:
32+
33+
* [Cloud Souce Repositories](https://cloud.google.com/source-repositories/docs/authentication#ssh)
34+
* [Bitbucket](https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html)
35+
* [GitHub](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/)
36+
* [Gitlab](https://docs.gitlab.com/ee/ssh/)
37+
38+
## Whitelisting
39+
Note that installing Anthos Config Management [requires](https://cloud.google.com/anthos-config-management/docs/how-to/installing#local_environment) an active Anthos license.
40+
By default, this module will attempt to download the ACM operator from Google directly—meaning your Terraform service account needs to be whitelisted for ACM access. If this is an issue, you can predownload the operator yourself then set the `operator_path` variable to point to the file location.
41+
42+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
43+
## Inputs
44+
45+
| Name | Description | Type | Default | Required |
46+
|------|-------------|:----:|:-----:|:-----:|
47+
| cluster\_endpoint | Kubernetes cluster endpoint. | string | n/a | yes |
48+
| cluster\_name | The unique name to identify the cluster in ACM. | string | n/a | yes |
49+
| create\_ssh\_key | Controls whether a key will be generated for Git authentication | bool | `"true"` | no |
50+
| enable\_policy\_controller | Whether to enable the ACM Policy Controller on the cluster | bool | `"true"` | no |
51+
| install\_template\_library | Whether to install the default Policy Controller template library | bool | `"true"` | no |
52+
| location | The location (zone or region) this cluster has been created in. | string | n/a | yes |
53+
| operator\_path | Path to the operator yaml config. If unset, will download from GCS releases. | string | `"null"` | no |
54+
| policy\_dir | Subfolder containing configs in ACM Git repo | string | n/a | yes |
55+
| project\_id | The project in which the resource belongs. | string | n/a | yes |
56+
| sync\_branch | ACM repo Git branch | string | `"master"` | no |
57+
| sync\_repo | ACM Git repo address | string | n/a | yes |
58+
59+
## Outputs
60+
61+
| Name | Description |
62+
|------|-------------|
63+
| git\_creds\_public | Public key of SSH keypair to allow the Anthos Operator to authenticate to your Git repository. |
64+
65+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)