Bash 如何将terragrunt apply的输出变量保存为常规shell环境变量?
在我的CI步骤(基本上是一个bash脚本)中运行我的Bash 如何将terragrunt apply的输出变量保存为常规shell环境变量?,bash,terraform,Bash,Terraform,在我的CI步骤(基本上是一个bash脚本)中运行我的terragrunt apply all后,我得到了我的输出,在这种情况下,我只有一个输出: output "cloudrun-hostname" { value = google_cloud_run_service.cloudrun.status[0].url description = "API endpoint URL" } 如何将该输出的值传递给环境变量,基本上就像我导出的变
terragrunt apply all
后,我得到了我的输出,在这种情况下,我只有一个输出:
output "cloudrun-hostname" {
value = google_cloud_run_service.cloudrun.status[0].url
description = "API endpoint URL"
}
如何将该输出的值传递给环境变量,基本上就像我导出的变量一样:
export HOSTNAME=terragrunt-cloudrun-hostname-output
我需要这个变量带有该值,以便以后可以在另一个文件中使用该值。您需要展开该命令,因此:
export HOSTNAME="$(terragrunt apply-all | awk -F= '/value/ { gsub(" ","",$2);print $2 }')"
您可以使用命令,即
export MY_ENV=$(terraform output cloudrun-hostname)
当然,在您的
应用所有之后,terragrunt cloudrun主机名输出是什么?这只是实际命令或值的替代。好的,我已经修改了答案,用awk解析输出。很抱歉造成混淆terragrunt cloudrun主机名输出
根本没有任何意义。好吧,那么它应该是terragrunt apply all?出于某种原因,我发现只有terragrunt输出对我有效。我打赌Terragrunt中的output all
使用Terraform中的output
。所以我并不感到惊讶。另外,我认为不解析Terragrunt或Terraform输出更干净。当然可以。Terragrunt从字面上向您展示了它使用的Terraform命令,例如Terraform output cloudrun hostname
,但是当我尝试复制Terragrunt并使用它使用的相同命令时,我会出错。具有讽刺意味的是,Terragrunt文档声称,output all
命令有点坏了。