【问题标题】:Assign terraform output to environment variable将 terraform 输出分配给环境变量
【发布时间】:2021-02-26 06:56:16
【问题描述】:

如何将 terraform 输出分配给环境变量?

假设我在 main.tf

中定义了以下输出
output "gce_public_ip" {
    value = element(concat(google_compute_instance.vm_instance.*.network_interface.0.access_config.0.nat_ip, list("")), 0)
}

我想导出gce_public_ip,所以它可以作为环境变量GCE_PUBLIC_IP使用

【问题讨论】:

    标签: terraform terraform-provider-gcp


    【解决方案1】:

    您可以使用the terraform output command

    没有用你的价值进行测试,但应该是这样的:

    export GCE_PUBLIC_IP=$(terraform output -raw gce_public_ip)
    

    【讨论】:

    • 您可能希望在输出命令中包含 -raw 参数,即 export GCE_PUBLIC_IP=$(terraform output -raw gce_public_ip)
    猜你喜欢
    • 2021-09-24
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2019-03-04
    相关资源
    最近更新 更多