天天看點

Terraform Output 變量輸出

Terraform Output 變量輸出

output可以了解為它是一個變量,隻不過它是輸出變量,它主要的是幫我們列印變量。

下面就是輸出變量。 

Changes to Outputs:
  + first_image_id = [
      + "centos_7_9_uefi_x64_20G_alibase_20210611.vhd",
      + "centos_7_9_uefi_x64_20G_scc_20220906.vhd",
      + "centos_7_9_x64_20G_alibase_20220824.vhd",
      + "centos_7_8_amd_x64_20G_alibase_20200806.vhd",
      + "centos_7_8_tpm_x64_20G_alibase_20200810.vhd",
      + "centos_7_8_x64_20G_alibase_20211130.vhd",
      + "centos_7_7_x64_20G_alibase_20211130.vhd",
      + "centos_7_6_x64_20G_alibase_20211130.vhd",
      + "centos_7_5_x64_20G_alibase_20211130.vhd",
      + "centos_7_05_64_40G_scc_20190415.raw",
      + "centos_7_04_64_20G_alibase_201701015.vhd",
      + "centos_7_03_64_20G_alibase_20170818.vhd",
      + "centos_7_02_64_20G_alibase_20170818.vhd",
    ]
  + my_env         = "prod"      

但凡你想調試的時候都可以加output去列印出來。 

Terraform Output 變量輸出

比如有兩個子產品,一個子產品a,一個子產品b。比如要想傳回ecs的IP,那麼提供為另外一個子產品去引用。這樣就可以在子產品裡面加上output,将IP列印出來,一個是列印,另外一個是另外子產品調用它的IP。

是以這是兩個子產品之間傳遞值的方法。

Terraform Output 變量輸出

如果是私密的消息,那麼就可以讓其不列印。 

output "esc_info" {
  value = var.ecs_info.esc_image
  sensitive = true
}      
Terraform Output 變量輸出

其實每一個目錄都可以了解為一個子產品,最外層的子產品叫做根子產品。

output "security_group_id" {
  value = alicloud_security_group.group.id
}


│ Error: Reference to undeclared input variable
│
│   on alicloud_security_group_rule.tf line 19, in resource "alicloud_security_group_rule" "allow_22_tcp":
│   19:   security_group_id = var.security_group_id
│
│ An input variable with the name "security_group_id" has not been declared. This variable can be declared with a        
│ variable "security_group_id" {} block.      

繼續閱讀