Skip to content

Commit

Permalink
feat: Add managed ctrl plane option to ASM module (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaPrete committed Apr 16, 2021
1 parent 1fe90e9 commit 7034f68
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ credentials.json
# File to populate env vars used by Docker test runs
.envrc

# ignore generated ASM yamls in /workspace/test/fixtures/simple_zonal_with_asm as it is a test
# in a production scenario these files are expected to be checked in
# ignore generated ASM yamls in /workspace/test/fixtures/simple_zonal_with_asm
# as it is a test in a production scenario these files are expected to be checked in
/test/fixtures/simple_zonal_with_asm/asm-dir
1 change: 1 addition & 0 deletions modules/asm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ To deploy this config:
| cluster\_name | The unique name to identify the cluster in ASM. | `string` | n/a | yes |
| gcloud\_sdk\_version | The gcloud sdk version to use. Minimum required version is 293.0.0 | `string` | `"296.0.1"` | no |
| location | The location (zone or region) this cluster has been created in. | `string` | n/a | yes |
| managed | Whether the control plane should be managed. | `bool` | `false` | no |
| project\_id | The project in which the resource belongs. | `string` | n/a | yes |
| service\_account\_key\_file | Path to service account key file to auth as for running `gcloud container clusters get-credentials`. | `string` | `""` | no |

Expand Down
6 changes: 4 additions & 2 deletions modules/asm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ data "google_project" "asm_project" {
project_id = var.project_id
}

locals {
kubectl_create_command_base = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version}"
}

module "asm_install" {
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
Expand All @@ -32,7 +35,6 @@ module "asm_install" {
project_id = var.project_id
service_account_key_file = var.service_account_key_file


kubectl_create_command = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version}"
kubectl_create_command = var.managed ? "${local.kubectl_create_command_base} ${var.managed}" : local.kubectl_create_command_base
kubectl_destroy_command = "kubectl delete ns istio-system"
}
1 change: 1 addition & 0 deletions modules/asm/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install_asm
29 changes: 25 additions & 4 deletions modules/asm/scripts/install_asm.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Copyright 2018 Google LLC

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,11 +25,31 @@ PROJECT_ID=$1
CLUSTER_NAME=$2
CLUSTER_LOCATION=$3
ASM_VERSION=$4
MANAGED=$5
MODE="install"

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

#run the script with appropriate flags
./install_asm --verbose --project_id "${PROJECT_ID}" --cluster_name "${CLUSTER_NAME}" --cluster_location "${CLUSTER_LOCATION}" --mode "${MODE}" --enable_cluster_labels --enable_cluster_roles
declare -a params=(
"--verbose"
"--project_id ${PROJECT_ID}"
"--cluster_name ${CLUSTER_NAME}"
"--cluster_location ${CLUSTER_LOCATION}"
"--mode ${MODE}"
"--enable_cluster_labels"
"--enable_cluster_roles"
)

# Add the --managed param if MANAGED is set to true
if [[ "${MANAGED}" == true ]]; then
params+=("--managed")
fi

# Run the script with appropriate flags
echo "Running ./install_asm" "${params[@]}"

# Disable shell linting. Other forms will prevent the command to work
# shellcheck disable=SC2046,SC2116
./install_asm $(echo "${params[@]}")
6 changes: 6 additions & 0 deletions modules/asm/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ variable "asm_version" {
type = string
default = "1.8"
}

variable "managed" {
description = "Whether the control plane should be managed."
type = bool
default = false
}

0 comments on commit 7034f68

Please sign in to comment.