Skip to content

Commit 64b782c

Browse files
feat: ASM CA option without providing CA_CERT maps and adding revision_name flag (terraform-google-modules#952)
* modifying CA config options * Adding flag as an option and adding the ability for to be used without providing the four maps. * adding missed variable in line 207 and 211 * correcting REVISION_NAME_COMMAND_SNIPPET variable in line 211 * updated revision_label process * Made every CA CERTS map its own command snippet * Made every CA CERTS map its own command snippet * testing validations * testing validations * Fixed a missing bracket * Reverting * added revision_name flag and included option to run --ca flag without --ca_certs flag, to use self-signed certificate * Fixed whitespacing * removing another whitespace * ran make build * fixed Error: No newline at end of file ./modules/asm/variables.tf * testing * ran make build * In install_asm.sh: Consolidating IF statement for CA_CERT keys, adding {} around single digits numbers for line 24-32, adding echos for CA variables. Co-authored-by: Bharath KKB <[email protected]>
1 parent 712fc54 commit 64b782c

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

modules/asm/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ To deploy this config:
5252
| asm\_git\_tag | ASM git tag to deploy. This module supports versions `1.8` and `1.9`. You can get the exact `asm_git_tag` by running the command `install_asm --version`. The ASM git tab should be of the form `1.9.3-asm.2+config5`. You can also see all ASM git tags by running `curl https://storage.googleapis.com/csm-artifacts/asm/STABLE_VERSIONS`. You must provide the full and exact git tag. This variable is optional. Leaving it empty (default) will download the latest `install_asm` script for the version provided by the `asm_version` variable. | `string` | `""` | no |
5353
| asm\_version | ASM version to deploy. This module supports versions `1.8` and `1.9`. Available versions are documented in https://github.com/GoogleCloudPlatform/anthos-service-mesh-packages | `string` | `"1.9"` | no |
5454
| ca | Sets CA option. Possible values are `meshca` or `citadel`. Additional documentation on Citadel is available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_citadel_as_the_ca. | `string` | `"meshca"` | no |
55-
| ca\_certs | Sets CA certificate file paths when `ca` is set to `citadel`. These values must be provided when using Citadel as CA. Additional documentation on Citadel is available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_citadel_as_the_ca. | `map` | `{}` | no |
55+
| ca\_certs | Sets CA certificate file paths when `ca` is set to `citadel`. These values must be provided when using Citadel as CA. Additional documentation on Citadel is available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_citadel_as_the_ca. | `map(any)` | `{}` | no |
5656
| cluster\_endpoint | The GKE cluster endpoint. | `string` | n/a | yes |
5757
| cluster\_name | The unique name to identify the cluster in ASM. | `string` | n/a | yes |
58-
| custom\_overlays | Comma separated list of custom\_overlay file paths. Works with in-cluster control plane only. Additional documentation available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_an_overlay_file | `list` | `[]` | no |
58+
| custom\_overlays | Comma separated list of custom\_overlay file paths. Works with in-cluster control plane only. Additional documentation available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_an_overlay_file | `list(any)` | `[]` | no |
5959
| enable\_all | Sets `--enable_all` option if true. | `bool` | `false` | no |
6060
| enable\_cluster\_labels | Sets `--enable_cluster_labels` option if true. | `bool` | `false` | no |
6161
| enable\_cluster\_roles | Sets `--enable_cluster_roles` option if true. | `bool` | `false` | no |
@@ -70,9 +70,10 @@ To deploy this config:
7070
| location | The location (zone or region) this cluster has been created in. | `string` | n/a | yes |
7171
| managed\_control\_plane | ASM managed control plane boolean. Determines whether to install ASM managed control plane. Installing ASM managed control plane does not install gateways. Documentation on how to install gateways with ASM MCP can be found at https://cloud.google.com/service-mesh/docs/managed-control-plane#install_istio_gateways_optional. | `bool` | `false` | no |
7272
| mode | ASM mode for deployment. Supported modes are `install` and `upgrade`. | `string` | `"install"` | no |
73-
| options | Comma separated list of options. Works with in-cluster control plane only. Supported options are documented in https://cloud.google.com/service-mesh/docs/enable-optional-features. | `list` | `[]` | no |
73+
| options | Comma separated list of options. Works with in-cluster control plane only. Supported options are documented in https://cloud.google.com/service-mesh/docs/enable-optional-features. | `list(any)` | `[]` | no |
7474
| outdir | Sets `--outdir` option. | `string` | `"none"` | no |
7575
| project\_id | The project in which the resource belongs. | `string` | n/a | yes |
76+
| revision\_name | Sets `--revision-name` option. | `string` | `"none"` | no |
7677
| service\_account | The GCP Service Account email address used to deploy ASM. | `string` | `""` | no |
7778
| service\_account\_key\_file | Path to service account key file to auth as for running `gcloud container clusters get-credentials`. | `string` | `""` | no |
7879
| skip\_validation | Sets `_CI_NO_VALIDATE` variable. Determines whether the script should perform validation checks for prerequisites such as IAM roles, Google APIs etc. | `bool` | `false` | no |

modules/asm/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ locals {
2828
ca_key = lookup(var.ca_certs, "ca_key", "none")
2929
root_cert = lookup(var.ca_certs, "root_cert", "none")
3030
cert_chain = lookup(var.ca_certs, "cert_chain", "none")
31+
revision_name_string = (var.revision_name == "" ? "none" : var.revision_name)
3132
# https://github.com/GoogleCloudPlatform/anthos-service-mesh-packages/blob/1cf61b679cd369f42a0e735f8e201de1a6a6433b/scripts/asm-installer/install_asm#L1970
3233
iam_roles = [
3334
"roles/container.admin",
@@ -96,6 +97,6 @@ module "asm_install" {
9697
service_account_key_file = var.service_account_key_file
9798
impersonate_service_account = var.impersonate_service_account
9899

99-
kubectl_create_command = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version} ${var.mode} ${var.managed_control_plane} ${var.skip_validation} ${local.options_string} ${local.custom_overlays_string} ${var.enable_all} ${var.enable_cluster_roles} ${var.enable_cluster_labels} ${var.enable_gcp_components} ${var.enable_registration} ${var.outdir} ${var.ca} ${local.ca_cert} ${local.ca_key} ${local.root_cert} ${local.cert_chain} ${local.service_account_string} ${local.key_file_string} ${local.asm_git_tag_string}"
100+
kubectl_create_command = "${path.module}/scripts/install_asm.sh ${var.project_id} ${var.cluster_name} ${var.location} ${var.asm_version} ${var.mode} ${var.managed_control_plane} ${var.skip_validation} ${local.options_string} ${local.custom_overlays_string} ${var.enable_all} ${var.enable_cluster_roles} ${var.enable_cluster_labels} ${var.enable_gcp_components} ${var.enable_registration} ${var.outdir} ${var.ca} ${local.ca_cert} ${local.ca_key} ${local.root_cert} ${local.cert_chain} ${local.service_account_string} ${local.key_file_string} ${local.asm_git_tag_string} ${local.revision_name_string}"
100101
kubectl_destroy_command = "${path.module}/scripts/destroy_asm.sh"
101102
}

modules/asm/scripts/install_asm.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ if [ "$#" -lt 5 ]; then
2121
exit 1
2222
fi
2323

24-
PROJECT_ID=$1
25-
CLUSTER_NAME=$2
26-
CLUSTER_LOCATION=$3
27-
ASM_VERSION=$4
28-
MODE=$5
29-
MCP=$6
30-
SKIP_VALIDATION=$7
31-
OPTIONS_LIST=$8
32-
CUSTOM_OVERLAYS_LIST=$9
24+
PROJECT_ID=${1}
25+
CLUSTER_NAME=${2}
26+
CLUSTER_LOCATION=${3}
27+
ASM_VERSION=${4}
28+
MODE=${5}
29+
MCP=${6}
30+
SKIP_VALIDATION=${7}
31+
OPTIONS_LIST=${8}
32+
CUSTOM_OVERLAYS_LIST=${9}
3333
ENABLE_ALL=${10}
3434
ENABLE_CLUSTER_ROLES=${11}
3535
ENABLE_CLUSTER_LABELS=${12}
@@ -44,6 +44,7 @@ CERT_CHAIN=${20}
4444
SERVICE_ACCOUNT=${21}
4545
KEY_FILE=${22}
4646
ASM_GIT_TAG=${23}
47+
REVISION_NAME=${24}
4748

4849
# Set SKIP_VALIDATION variable
4950
if [[ ${SKIP_VALIDATION} = "true" ]]; then
@@ -93,7 +94,12 @@ echo -e "ENABLE_REGISTRATION is $ENABLE_REGISTRATION"
9394
echo -e "OUTDIR is $OUTDIR"
9495
echo -e "SERVICE_ACCOUNT is $SERVICE_ACCOUNT"
9596
echo -e "KEY_FILE is $KEY_FILE"
96-
97+
echo -e "REVISION_NAME is $REVISION_NAME"
98+
echo -e "CA is $CA"
99+
echo -e "CA_CERT is $CA_CERT"
100+
echo -e "CA_KEY is $CA_KEY"
101+
echo -e "ROOT_CERT is $ROOT_CERT"
102+
echo -e "CERT_CHAIN is $CERT_CHAIN"
97103
#download the correct version of the install_asm script
98104
if [[ "${ASM_GIT_TAG}" = "none" ]]; then
99105
echo -e "Downloading install_asm with latest git tag..."
@@ -177,15 +183,21 @@ else
177183
mkdir -p "${OUTDIR}"
178184
fi
179185

180-
if [[ "${CA}" = "citadel" ]]; then
181-
CA_COMMAND_SNIPPET="--ca citadel --ca_cert ${CA_CERT} --ca_key ${CA_KEY} --root_cert ${ROOT_CERT} --cert_chain ${CERT_CHAIN}"
186+
if [[ "${CA}" == "citadel" ]]; then
187+
CA_COMMAND_SNIPPET="--ca citadel"
182188
else
183189
CA_COMMAND_SNIPPET=""
184190
fi
185191

192+
if [[ "${CA_CERT}" == "none" ]]; then
193+
CA_CERTS_COMMAND_SNIPPET=""
194+
else
195+
CA_CERTS_COMMAND_SNIPPET="--ca_cert ${CA_CERT} --ca_key ${CA_KEY} --root_cert ${ROOT_CERT} --cert_chain ${CERT_CHAIN}"
196+
fi
197+
186198
# Echo the command before executing
187-
echo -e "install_asm_${ASM_VERSION} --verbose --project_id ${PROJECT_ID} --cluster_name ${CLUSTER_NAME} --cluster_location ${CLUSTER_LOCATION} --mode ${MODE} ${MCP_COMMAND_SNIPPET} ${OPTIONS_COMMAND_SNIPPET} ${CUSTOM_OVERLAYS_COMMAND_SNIPPET} ${OUTDIR_COMMAND_SNIPPET} ${ENABLE_ALL_COMMAND_SNIPPET} ${ENABLE_CLUSTER_ROLES_COMMAND_SNIPPET} ${ENABLE_CLUSTER_LABELS_COMMAND_SNIPPET} ${ENABLE_GCP_COMPONENTS_COMMAND_SNIPPET} ${ENABLE_REGISTRATION_COMMAND_SNIPPET} ${CA_COMMAND_SNIPPET} ${SERVICE_ACCOUNT_COMMAND_SNIPPET} ${KEY_FILE_COMMAND_SNIPPET}"
199+
echo -e "install_asm_${ASM_VERSION} --verbose --project_id ${PROJECT_ID} --cluster_name ${CLUSTER_NAME} --cluster_location ${CLUSTER_LOCATION} --mode ${MODE} ${MCP_COMMAND_SNIPPET} ${OPTIONS_COMMAND_SNIPPET} ${CUSTOM_OVERLAYS_COMMAND_SNIPPET} ${OUTDIR_COMMAND_SNIPPET} ${ENABLE_ALL_COMMAND_SNIPPET} ${ENABLE_CLUSTER_ROLES_COMMAND_SNIPPET} ${ENABLE_CLUSTER_LABELS_COMMAND_SNIPPET} ${ENABLE_GCP_COMPONENTS_COMMAND_SNIPPET} ${ENABLE_REGISTRATION_COMMAND_SNIPPET} ${CA_COMMAND_SNIPPET} ${CA_CERTS_COMMAND_SNIPPET} ${SERVICE_ACCOUNT_COMMAND_SNIPPET} ${KEY_FILE_COMMAND_SNIPPET} ${REVISION_NAME_COMMAND_SNIPPET}"
188200

189201
# run the script with appropriate flags
190202
# shellcheck disable=SC2086
191-
./install_asm_${ASM_VERSION} --verbose --project_id ${PROJECT_ID} --cluster_name ${CLUSTER_NAME} --cluster_location ${CLUSTER_LOCATION} --mode ${MODE} ${MCP_COMMAND_SNIPPET} ${OPTIONS_COMMAND_SNIPPET} ${CUSTOM_OVERLAYS_COMMAND_SNIPPET} ${OUTDIR_COMMAND_SNIPPET} ${ENABLE_ALL_COMMAND_SNIPPET} ${ENABLE_CLUSTER_ROLES_COMMAND_SNIPPET} ${ENABLE_CLUSTER_LABELS_COMMAND_SNIPPET} ${ENABLE_GCP_COMPONENTS_COMMAND_SNIPPET} ${ENABLE_REGISTRATION_COMMAND_SNIPPET} ${CA_COMMAND_SNIPPET} ${SERVICE_ACCOUNT_COMMAND_SNIPPET} ${KEY_FILE_COMMAND_SNIPPET}
203+
./install_asm_${ASM_VERSION} --verbose --project_id ${PROJECT_ID} --cluster_name ${CLUSTER_NAME} --cluster_location ${CLUSTER_LOCATION} --mode ${MODE} ${MCP_COMMAND_SNIPPET} ${OPTIONS_COMMAND_SNIPPET} ${CUSTOM_OVERLAYS_COMMAND_SNIPPET} ${OUTDIR_COMMAND_SNIPPET} ${ENABLE_ALL_COMMAND_SNIPPET} ${ENABLE_CLUSTER_ROLES_COMMAND_SNIPPET} ${ENABLE_CLUSTER_LABELS_COMMAND_SNIPPET} ${ENABLE_GCP_COMPONENTS_COMMAND_SNIPPET} ${ENABLE_REGISTRATION_COMMAND_SNIPPET} ${CA_COMMAND_SNIPPET} ${CA_CERTS_COMMAND_SNIPPET} ${SERVICE_ACCOUNT_COMMAND_SNIPPET} ${KEY_FILE_COMMAND_SNIPPET} ${REVISION_NAME_COMMAND_SNIPPET}

modules/asm/variables.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ variable "impersonate_service_account" {
9595

9696
variable "options" {
9797
description = "Comma separated list of options. Works with in-cluster control plane only. Supported options are documented in https://cloud.google.com/service-mesh/docs/enable-optional-features."
98-
type = list
98+
type = list(any)
9999
default = []
100100
}
101101

102102
variable "custom_overlays" {
103103
description = "Comma separated list of custom_overlay file paths. Works with in-cluster control plane only. Additional documentation available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_an_overlay_file"
104-
type = list
104+
type = list(any)
105105
default = []
106106
}
107107

@@ -167,18 +167,28 @@ variable "ca" {
167167

168168
variable "ca_certs" {
169169
description = "Sets CA certificate file paths when `ca` is set to `citadel`. These values must be provided when using Citadel as CA. Additional documentation on Citadel is available at https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#installation_with_citadel_as_the_ca."
170-
type = map
170+
type = map(any)
171171
default = {}
172172
# default = {
173173
# "ca_cert" = "none"
174174
# "ca_key" = "none"
175175
# "root_cert" = "none"
176176
# "cert_chain" = "none"
177177
# }
178+
validation {
179+
condition = contains([4, 0], length(compact([for k in ["ca_cert", "ca_key", "root_cert", "cert_chain"] : lookup(var.ca_certs, k, "")])))
180+
error_message = "One or more required keys for ca_certs are missing. If you plan to use the self-signed certificate, do not declare the ca_certs variable."
181+
}
178182
}
179183

180184
variable "iam_member" {
181185
description = "The GCP member email address to grant IAM roles to. If impersonate_service_account or service_account is set, roles are granted to that SA."
182186
type = string
183187
default = ""
184188
}
189+
190+
variable "revision_name" {
191+
description = "Sets `--revision-name` option."
192+
type = string
193+
default = "none"
194+
}

0 commit comments

Comments
 (0)