我试图引用模块内声明的变量来更新同一模块中的另一个变量,但我无法找到有关如何引用该变量的指南。
\n这是我的代码片段
\nmodule "cluster" {\n source = "..."\n\n var1 = value1 # directly passing value\n var2 = module.cluster.var1 # I need to update this variable value based on value of var1\n
Run Code Online (Sandbox Code Playgroud)\n我在地形计划期间遇到以下错误
\nmodule "cluster" {\n source = "..."\n\n var1 = value1 # directly passing value\n var2 = module.cluster.var1 # I need to update this variable value based on value of var1\n
Run Code Online (Sandbox Code Playgroud)\n我还尝试使用 local.var1 进行引用,如下所示
\nmodule "cluster" {\n source = "..."\n\n var1 = value1 # directly passing value\n var2 = local.var1 # I need to update this variable value based on value of var1\n
Run Code Online (Sandbox Code Playgroud)\n然后我遇到以下错误
\nTerraform v1.0.11\non linux_amd64\nConfiguring remote state backend...\nInitializing Terraform configuration...\n\n Error: Unsupported attribute\n\xe2\x94\x82 \n\xe2\x94\x82 on main.tf line 04, in module "cluster":\n\xe2\x94\x82 04: var2 = module.cluster.var1\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\xe2\x94\x82 \xe2\x94\x82 module.cluster is a object, known only after apply\n\xe2\x94\x82 \n\xe2\x94\x82 This object does not have an attribute named "var1".\n\n
Run Code Online (Sandbox Code Playgroud)\n任何线索都会有帮助。
\n问候
\n您的第二次尝试使用局部变量,是在正确的轨道上,但您必须实际声明局部变量:
locals {
var1 = value1
}
module "cluster" {
source = "..."
var1 = local.var1
var2 = local.var1
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3107 次 |
最近记录: |