Skip to content

Commit 0905359

Browse files
author
Sam Naser
committed
Change example to use google_container_cluster
1 parent 88f7600 commit 0905359

File tree

5 files changed

+45
-145
lines changed

5 files changed

+45
-145
lines changed

examples/simple_zonal_with_asm/hub.tf

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
module "hub" {
18-
source = "../../modules/hub"
19-
project_id = var.project_id
20-
location = module.gke.location
21-
cluster_name = module.gke.name
22-
cluster_endpoint = module.gke.endpoint
23-
gke_hub_membership_name = "gke-asm-membership"
17+
resource "google_gke_hub_membership" "cluster_membership" {
18+
provider = google-beta
19+
project = var.project_id
20+
membership_id = "${google_container_cluster.primary.name}-membership"
21+
endpoint{
22+
gke_cluster {
23+
resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}"
24+
}
25+
}
26+
}
27+
# enable Anthos Configmanagement feature on the project.
28+
resource "google_gke_hub_feature" "mesh_feature" {
29+
name = "servicemesh"
30+
project = var.project_id
31+
location = "global"
32+
provider = google-beta
2433
}

examples/simple_zonal_with_asm/main.tf

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,42 @@ locals {
2121
data "google_client_config" "default" {}
2222

2323
provider "kubernetes" {
24-
host = "https://${module.gke.endpoint}"
24+
host = "https://${google_container_cluster.primary.endpoint}"
2525
token = data.google_client_config.default.access_token
26-
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
26+
cluster_ca_certificate = base64decode(google_container_cluster.primary.master_auth[0].cluster_ca_certificate)
2727
}
2828

2929
data "google_project" "project" {
3030
project_id = var.project_id
3131
}
3232

33-
module "gke" {
34-
source = "../../"
35-
project_id = var.project_id
36-
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
37-
regional = false
38-
region = var.region
39-
zones = var.zones
40-
release_channel = "REGULAR"
41-
network = var.network
42-
subnetwork = var.subnetwork
43-
ip_range_pods = var.ip_range_pods
44-
ip_range_services = var.ip_range_services
45-
network_policy = false
46-
cluster_resource_labels = { "mesh_id" : "proj-${data.google_project.project.number}" }
47-
node_pools = [
48-
{
49-
name = "asm-node-pool"
50-
autoscaling = false
51-
auto_upgrade = true
52-
# ASM requires minimum 4 nodes and e2-standard-4
53-
node_count = 4
54-
machine_type = "e2-standard-4"
55-
},
56-
]
33+
resource "google_container_cluster" "primary" {
34+
name = "drew-barrymore"
35+
project = var.project_id
36+
location = "us-central1-a"
37+
initial_node_count = 3
38+
workload_identity_config {
39+
identity_namespace = "${var.project_id}.svc.id.goog"
40+
}
41+
node_config {
42+
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
43+
oauth_scopes = [
44+
"https://www.googleapis.com/auth/cloud-platform"
45+
]
46+
labels = {
47+
foo = "bar"
48+
}
49+
tags = ["foo", "bar"]
50+
}
51+
timeouts {
52+
create = "30m"
53+
update = "40m"
54+
}
5755
}
5856

5957
module "asm" {
6058
source = "../../modules/asm"
61-
cluster_name = module.gke.name
62-
cluster_endpoint = module.gke.endpoint
6359
project_id = var.project_id
64-
location = module.gke.location
65-
enable_cluster_roles = true
66-
enable_cluster_labels = true
67-
enable_gcp_apis = true
68-
enable_gcp_components = true
69-
enable_namespace_creation = true
70-
options = ["envoy-access-log"]
71-
outdir = "./${module.gke.name}-outdir"
60+
cluster_name = google_container_cluster.primary.name
61+
cluster_location = google_container_cluster.primary.location
7262
}
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +0,0 @@
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-
sensitive = true
29-
value = module.gke.ca_certificate
30-
}
31-
32-
output "service_account" {
33-
description = "The default service account used for running nodes."
34-
value = module.gke.service_account
35-
}
Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +0,0 @@
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-
}

modules/asm/scripts/create_cpr.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ if [ "$#" -lt 3 ]; then
2121
exit 1
2222
fi
2323

24+
echo "Sleeping for CPR... do retries instead..."
25+
sleep 30
26+
2427
REVISION_NAME=$1; shift
2528
CHANNEL=$1; shift
2629
ENABLE_CNI=$1; shift

0 commit comments

Comments
 (0)