Skip to content

Commit 1eb2b0c

Browse files
authored
Merge branch 'master' into feature/workload-id-automount-token
2 parents ee2073d + 0bcf3ca commit 1eb2b0c

File tree

52 files changed

+1198
-36
lines changed

Some content is hidden

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

52 files changed

+1198
-36
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ credentials.json
5050

5151
# File to populate env vars used by Docker test runs
5252
.envrc
53+
54+
# ignore generated ASM yamls in /workspace/test/fixtures/simple_regional_with_asm as it is a test
55+
# in a production scenario these files are expected to be checked in
56+
/test/fixtures/simple_regional_with_asm/asm-dir

.kitchen.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ suites:
5151
systems:
5252
- name: safer_cluster
5353
backend: local
54+
controls:
55+
- gcloud
56+
- name: inspec-gcp
57+
backend: gcp
58+
controls:
59+
- network
5460
- name: "simple_regional"
5561
driver:
5662
root_module_directory: test/fixtures/simple_regional
@@ -228,3 +234,13 @@ suites:
228234
systems:
229235
- name: safer_cluster_iap_bastion
230236
backend: local
237+
- name: "simple_regional_with_asm"
238+
driver:
239+
root_module_directory: test/fixtures/simple_regional_with_asm
240+
verifier:
241+
systems:
242+
- name: simple_regional_with_asm
243+
backend: local
244+
controls:
245+
- gcloud
246+
- kubectl

autogen/main/cluster.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ resource "google_container_node_pool" "pools" {
509509
{% endif %}
510510

511511
shielded_instance_config {
512-
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
512+
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
513513
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)
514514
}
515515
}

autogen/main/firewall.tf.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ resource "google_compute_firewall" "intra_egress" {
4848
allow { protocol = "esp" }
4949
allow { protocol = "ah" }
5050

51+
{% if not private_cluster %}
5152
depends_on = [
5253
google_container_cluster.primary,
5354
]
55+
{% endif %}
5456
}
5557

5658

@@ -77,8 +79,10 @@ resource "google_compute_firewall" "master_webhooks" {
7779
ports = var.firewall_inbound_ports
7880
}
7981

82+
{% if not private_cluster %}
8083
depends_on = [
8184
google_container_cluster.primary,
8285
]
86+
{% endif %}
8387

8488
}

autogen/main/outputs.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ output "endpoint" {
5454
*/
5555
google_container_cluster.primary,
5656
google_container_node_pool.pools,
57-
null_resource.wait_for_cluster.id,
57+
module.gcloud_wait_for_cluster.wait,
5858
]
5959
}
6060

autogen/safer-cluster/main.tf.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ module "gke" {
4949
ip_range_pods = var.ip_range_pods
5050
ip_range_services = var.ip_range_services
5151

52+
add_cluster_firewall_rules = var.add_cluster_firewall_rules
53+
firewall_priority = var.firewall_priority
54+
firewall_inbound_ports = var.firewall_inbound_ports
55+
5256
horizontal_pod_autoscaling = var.horizontal_pod_autoscaling
5357
http_load_balancing = var.http_load_balancing
5458

autogen/safer-cluster/variables.tf.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,21 @@ variable "gce_pd_csi_driver" {
342342
description = "(Beta) Whether this cluster should enable the Google Compute Engine Persistent Disk Container Storage Interface (CSI) Driver."
343343
default = true
344344
}
345+
346+
variable "add_cluster_firewall_rules" {
347+
type = bool
348+
description = "Create additional firewall rules"
349+
default = false
350+
}
351+
352+
variable "firewall_priority" {
353+
type = number
354+
description = "Priority rule for firewall rules"
355+
default = 1000
356+
}
357+
358+
variable "firewall_inbound_ports" {
359+
type = list(string)
360+
description = "List of TCP ports for admission/webhook controllers"
361+
default = ["8443", "9443", "15017"]
362+
}

build/int.cloudbuild.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,26 @@ steps:
404404
- verify safer-cluster-iap-bastion-local
405405
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
406406
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy safer-cluster-iap-bastion-local']
407+
- id: create simple-regional-with-asm-local
408+
waitFor:
409+
- prepare
410+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
411+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create simple-regional-with-asm-local']
412+
- id: converge simple-regional-with-asm-local
413+
waitFor:
414+
- create simple-regional-with-asm-local
415+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
416+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge simple-regional-with-asm-local']
417+
- id: verify simple-regional-with-asm-local
418+
waitFor:
419+
- converge simple-regional-with-asm-local
420+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
421+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify simple-regional-with-asm-local']
422+
- id: destroy simple-regional-with-asm-local
423+
waitFor:
424+
- verify simple-regional-with-asm-local
425+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
426+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-regional-with-asm-local']
407427
tags:
408428
- 'ci'
409429
- 'integration'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
timeout: 900s
1516
steps:
1617
- id: 'lint-tests'
1718
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'

examples/safer_cluster/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ module "gke" {
4949
ip_range_services = local.svc_range_name
5050
compute_engine_service_account = var.compute_engine_service_account
5151
master_ipv4_cidr_block = "172.16.0.0/28"
52+
add_cluster_firewall_rules = true
53+
firewall_inbound_ports = ["9443", "15017"]
5254

5355
master_authorized_networks = [
5456
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Simple Regional Cluster with ASM
2+
3+
This example illustrates how to create a simple regional cluster with ASM.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|:----:|:-----:|:-----:|
10+
| cluster\_name\_suffix | A suffix to append to the default cluster name | string | `""` | no |
11+
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |
12+
| ip\_range\_services | The secondary ip range to use for services | string | n/a | yes |
13+
| network | The VPC network to host the cluster in | string | n/a | yes |
14+
| project\_id | The project ID to host the cluster in | string | n/a | yes |
15+
| region | The region to host the cluster in | string | n/a | yes |
16+
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
17+
18+
## Outputs
19+
20+
| Name | Description |
21+
|------|-------------|
22+
| ca\_certificate | |
23+
| client\_token | |
24+
| cluster\_name | Cluster name |
25+
| identity\_namespace | |
26+
| ip\_range\_pods | The secondary IP range used for pods |
27+
| ip\_range\_services | The secondary IP range used for services |
28+
| kubernetes\_endpoint | |
29+
| location | |
30+
| master\_kubernetes\_version | The master Kubernetes version |
31+
| network | |
32+
| project\_id | |
33+
| region | |
34+
| service\_account | The default service account used for running nodes. |
35+
| subnetwork | |
36+
| zones | List of zones in which the cluster resides |
37+
38+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
39+
40+
To provision this example, run the following from within this directory:
41+
- `terraform init` to get the plugins
42+
- `terraform plan` to see the infrastructure plan
43+
- `terraform apply` to apply the infrastructure build
44+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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-asm2"
19+
}
20+
21+
provider "google-beta" {
22+
version = "~> 3.23.0"
23+
region = var.region
24+
}
25+
26+
data "google_project" "project" {
27+
project_id = var.project_id
28+
}
29+
30+
module "gke" {
31+
source = "../../modules/beta-public-cluster/"
32+
project_id = var.project_id
33+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
34+
regional = true
35+
release_channel = "REGULAR"
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+
network_policy = false
42+
cluster_resource_labels = { "mesh_id" : "proj-${data.google_project.project.number}" }
43+
node_pools = [
44+
{
45+
name = "asm-node-pool"
46+
autoscaling = false
47+
# ASM requires minimum 4 nodes and e2-standard-4
48+
# As this is a regional cluster we have node_count * 3 = 6 nodes
49+
node_count = 2
50+
machine_type = "e2-standard-4"
51+
},
52+
]
53+
}
54+
55+
module "asm" {
56+
source = "../../modules/asm"
57+
cluster_name = module.gke.name
58+
cluster_endpoint = module.gke.endpoint
59+
project_id = var.project_id
60+
location = module.gke.location
61+
use_tf_google_credentials_env_var = true
62+
}
63+
64+
data "google_client_config" "default" {
65+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}
64+
65+
output "identity_namespace" {
66+
value = module.gke.identity_namespace
67+
}

0 commit comments

Comments
 (0)