Skip to content

Commit d778958

Browse files
committed
wip asm module
1 parent eeafe9f commit d778958

File tree

15 files changed

+608
-1
lines changed

15 files changed

+608
-1
lines changed
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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.19.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+
region = var.region
36+
network = var.network
37+
subnetwork = var.subnetwork
38+
ip_range_pods = var.ip_range_pods
39+
ip_range_services = var.ip_range_services
40+
network_policy = false
41+
cluster_resource_labels={"mesh_id":"proj-${data.google_project.project.number}"}
42+
node_pools = [
43+
{
44+
name = "asm-node-pool"
45+
machine_type = "n1-standard-4"
46+
min_count = 2
47+
},
48+
]
49+
}
50+
51+
module "asm" {
52+
source = "../../modules/asm"
53+
cluster_name = module.gke.name
54+
project_id = var.project_id
55+
location = module.gke.location
56+
}
57+
58+
data "google_client_config" "default" {
59+
}
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
variable "project_id" {
18+
description = "The project ID to host the cluster in"
19+
}
20+
21+
variable "cluster_name_suffix" {
22+
description = "A suffix to append to the default cluster name"
23+
default = ""
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
}
29+
30+
variable "network" {
31+
description = "The VPC network to host the cluster in"
32+
}
33+
34+
variable "subnetwork" {
35+
description = "The subnetwork to host the cluster in"
36+
}
37+
38+
variable "ip_range_pods" {
39+
description = "The secondary ip range to use for pods"
40+
}
41+
42+
variable "ip_range_services" {
43+
description = "The secondary ip range to use for services"
44+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
terraform {
18+
required_version = ">= 0.12"
19+
}

modules/asm/main.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 "asm_install" {
18+
source = "terraform-google-modules/gcloud/google"
19+
version = "~> 1.0"
20+
21+
platform = "linux"
22+
gcloud_sdk_version = "292.0.0"
23+
skip_download = var.skip_gcloud_download
24+
upgrade = false
25+
use_tf_google_credentials_env_var = true
26+
additional_components = ["kubectl", "kpt", "anthoscli", "alpha"]
27+
28+
create_cmd_entrypoint = "${path.module}/scripts/install_asm.sh"
29+
create_cmd_body = "${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_release_channel}"
30+
destroy_cmd_entrypoint = "gcloud"
31+
destroy_cmd_body = "version"
32+
}
33+
34+
resource "google_service_account" "gke_hub_sa" {
35+
account_id = "gke-hub-sa"
36+
display_name = "Service Account"
37+
}
38+
39+
resource "google_project_iam_member" "gke_hub_member" {
40+
project = var.project_id
41+
role = "roles/gkehub.connect"
42+
member = "serviceAccount:${google_service_account.gke_hub_sa.email}"
43+
}

modules/asm/outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
*/

modules/asm/scripts/install_asm.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
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+
set -e
17+
18+
if [ "$#" -lt 4 ]; then
19+
>&2 echo "Not all expected arguments set."
20+
exit 1
21+
fi
22+
23+
PROJECT_ID=$1
24+
CLUSTER_NAME=$2
25+
CLUSTER_LOCATION=$3
26+
ASM_CHANNEL=$4
27+
28+
if [[ -d ./asm ]]; then
29+
echo "Removing kpt asm directory"
30+
rm -rf ./asm
31+
fi
32+
gcloud config set project ${PROJECT_ID}
33+
# gcloud auth list
34+
gcloud services enable meshca.googleapis.com
35+
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-packages.git/asm .
36+
kpt cfg set asm gcloud.core.project ${PROJECT_ID}
37+
kpt cfg set asm cluster-name ${CLUSTER_NAME}
38+
kpt cfg set asm gcloud.compute.zone ${CLUSTER_LOCATION}
39+
kpt cfg set asm gcloud.container.cluster.releaseChannel ${ASM_CHANNEL}
40+
anthoscli apply -f asm
41+
kubectl wait --for=condition=available --timeout=600s deployment --all -n istio-system

0 commit comments

Comments
 (0)