【问题标题】:run complex bash command in before_hook block terragrunt在 before_hook 块 terragrunt 中运行复杂的 bash 命令
【发布时间】:2023-01-20 23:59:56
【问题描述】:

需要为不同的环境部署创建和选择不同的工作区,在 bash 中我可以做 hack

terraform workspace select $env_name || terraform workspace new $env_name

如果第一个失败,将执行第二个命令

我的问题是如何在钩子之前在 terragrunt 中运行它?

#root/terragrunt.hcl

terraform {
  before_hook "workspace" {
    commands = ["plan", "apply", "destroy"]
    execute = ["terraform", "workspace", "select", local.environment]
  }

似乎 terragrunt 无法识别“||”符号

【问题讨论】:

    标签: terraform terragrunt terraform-workspace


    【解决方案1】:

    我无法仅通过使用执行参数来让它工作,但是解决方法是创建一个名为 workspace.sh 的 bash 文件,如下所示:

    #!/usr/bin/env bash
    
    terraform workspace select "${1}" || terraform workspace new "${1}"
    

    然后在 terragrunt 配置中:

    execute = [
          "bash",
          "./workspace.sh",
          get_env("WORKSPACE_NAME")
        ]
    

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      相关资源
      最近更新 更多