0

我需要使用一些 gcloud 命令才能在 GCP 上创建 Redis 实例,因为 terraform 不支持我需要的某些选项。

我正在尝试这个:

terraform {
  # Before apply, run script.
  before_hook "create_redis_script" {
    commands     = ["apply"]
    execute  = ["REDIS_REGION=${local.module_vars.redis_region}", "REDIS_PROJECT=${local.module_vars.redis_project}", "REDIS_VPC=${local.module_vars.redis_vpc}", "REDIS_PREFIX_LENGHT=${local.module_vars.redis_prefix_lenght}", "REDIS_RESERVED_RANGE_NAME=${local.module_vars.redis_reserved_range_name}", "REDIS_RANGE_DESCRIPTION=${local.module_vars.redis_range_description}", "REDIS_NAME=${local.module_vars.redis_name}", "REDIS_SIZE=${local.module_vars.redis_size}", "REDIS_ZONE=${local.module_vars.redis_zone}", "REDIS_ALT_ZONE=${local.module_vars.redis_alt_zone}", "REDIS_VERSION=${local.module_vars.redis_version}", "bash", "../../../scripts/create-redis-instance.sh"]
  }

脚本是这样的:

echo "[+]Creating IP Allocation Automatically using <$REDIS_VPC-network\/$REDIS_PREFIX_LENGHT>"
gcloud compute addresses create $REDIS_RESERVED_RANGE_NAME \
    --global \
    --purpose=VPC_PEERING \
    --prefix-lenght=$REDIS_PREFIX_LENGHT \
    --description=$REDIS_RANGE_DESCRIPTION \
    --network=$REDIS_VPC

我得到的错误是:

terragrunt apply
5b35d0bf15d0a0d61b303ed32556b85417e2317f
5b35d0bf15d0a0d61b303ed32556b85417e2317f
5b35d0bf15d0a0d61b303ed32556b85417e2317f
ERRO[0002] Hit multiple errors:
Hit multiple errors:
exec: "REDIS_REGION=us-east1": executable file not found in $PATH 
ERRO[0002] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
4

1 回答 1

0

我遇到了同样的问题并辞职以将值作为参数而不是环境变量传递。

它涉及修改脚本,并且声明不太清晰,但它有效:|

于 2021-12-21T03:43:50.187 回答