Skip to content

Commit 7034f68

Browse files
authored
feat: Add managed ctrl plane option to ASM module (#864)
1 parent 1fe90e9 commit 7034f68

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ credentials.json
5151
# File to populate env vars used by Docker test runs
5252
.envrc
5353

54-
# ignore generated ASM yamls in /workspace/test/fixtures/simple_zonal_with_asm as it is a test
55-
# in a production scenario these files are expected to be checked in
54+
# ignore generated ASM yamls in /workspace/test/fixtures/simple_zonal_with_asm
55+
# as it is a test in a production scenario these files are expected to be checked in
5656
/test/fixtures/simple_zonal_with_asm/asm-dir

modules/asm/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ To deploy this config:
4343
| cluster\_name | The unique name to identify the cluster in ASM. | `string` | n/a | yes |
4444
| gcloud\_sdk\_version | The gcloud sdk version to use. Minimum required version is 293.0.0 | `string` | `"296.0.1"` | no |
4545
| location | The location (zone or region) this cluster has been created in. | `string` | n/a | yes |
46+
| managed | Whether the control plane should be managed. | `bool` | `false` | no |
4647
| project\_id | The project in which the resource belongs. | `string` | n/a | yes |
4748
| service\_account\_key\_file | Path to service account key file to auth as for running `gcloud container clusters get-credentials`. | `string` | `""` | no |
4849

modules/asm/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ data "google_project" "asm_project" {
1818
project_id = var.project_id
1919
}
2020

21+
locals {
22+
kubectl_create_command_base = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version}"
23+
}
2124

2225
module "asm_install" {
2326
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
@@ -32,7 +35,6 @@ module "asm_install" {
3235
project_id = var.project_id
3336
service_account_key_file = var.service_account_key_file
3437

35-
36-
kubectl_create_command = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version}"
38+
kubectl_create_command = var.managed ? "${local.kubectl_create_command_base} ${var.managed}" : local.kubectl_create_command_base
3739
kubectl_destroy_command = "kubectl delete ns istio-system"
3840
}

modules/asm/scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
install_asm

modules/asm/scripts/install_asm.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# Copyright 2018 Google LLC
2+
3+
# Copyright 2021 Google LLC
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -24,11 +25,31 @@ PROJECT_ID=$1
2425
CLUSTER_NAME=$2
2526
CLUSTER_LOCATION=$3
2627
ASM_VERSION=$4
28+
MANAGED=$5
2729
MODE="install"
2830

29-
#download the correct version of the install_asm script
31+
# Download the correct version of the install_asm script
3032
curl https://storage.googleapis.com/csm-artifacts/asm/install_asm_"${ASM_VERSION}" > install_asm
3133
chmod u+x install_asm
3234

33-
#run the script with appropriate flags
34-
./install_asm --verbose --project_id "${PROJECT_ID}" --cluster_name "${CLUSTER_NAME}" --cluster_location "${CLUSTER_LOCATION}" --mode "${MODE}" --enable_cluster_labels --enable_cluster_roles
35+
declare -a params=(
36+
"--verbose"
37+
"--project_id ${PROJECT_ID}"
38+
"--cluster_name ${CLUSTER_NAME}"
39+
"--cluster_location ${CLUSTER_LOCATION}"
40+
"--mode ${MODE}"
41+
"--enable_cluster_labels"
42+
"--enable_cluster_roles"
43+
)
44+
45+
# Add the --managed param if MANAGED is set to true
46+
if [[ "${MANAGED}" == true ]]; then
47+
params+=("--managed")
48+
fi
49+
50+
# Run the script with appropriate flags
51+
echo "Running ./install_asm" "${params[@]}"
52+
53+
# Disable shell linting. Other forms will prevent the command to work
54+
# shellcheck disable=SC2046,SC2116
55+
./install_asm $(echo "${params[@]}")

modules/asm/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ variable "asm_version" {
5656
type = string
5757
default = "1.8"
5858
}
59+
60+
variable "managed" {
61+
description = "Whether the control plane should be managed."
62+
type = bool
63+
default = false
64+
}

0 commit comments

Comments
 (0)