2017-06-14 18 views
0

跑在我的根目錄Terraform一個terraform output我得到:無法找到模塊根目錄。沒有什麼可以輸出

The module root could not be found. There is nothing to output. 

我有以下文件:

iam.tf

resource "aws_iam_user" "a_user" { 
    name = "a_user" 
} 

output.tf

數據「aws_caller_identity」「current」{}

output "account_id" { 
    value = "${data.aws_caller_identity.current.account_id}" 
} 

https://www.terraform.io/docs/modules/index.html說:

Root module That is the current working directory when you run terraform apply or get, holding the Terraform configuration files. It is itself a valid module. 

任何想法,爲什麼錯誤信息,以及如何解決?

回答

1

Terraform從terraform.tfstate文件引用root module文件。

此文件包含.tf文件以及output variables的所有關於您最後一次已知狀態的信息。

將第一次執行terraform apply命令後生成的命令放入當前目錄。

只需運行terraform apply ,然後terraform output將顯示您的輸出變量。

0

你還沒有添加上面的模塊配置,但假設你有一個模塊文件,那麼你必須告訴terraform關於源。如果源是與iam.tf和output.tf位於同一位置的子目錄,則必須添加模塊,然後從output.tf和iam.tf所在的目錄運行terraform apply:

module "consul" { 
    source = "./example" 

} 

如果你的輸出是一個遠程位置(例如github上),那麼源必須是如下

module "consul" { 
    source = "github.com/some-git.git" 

} 

然後,你必須運行「terraform獲得」下載你的模塊。然後,「terraform apply」應用模塊,然後「terraform output」列出您在上面指定的輸出

0

問題是您還沒有添加模塊配置文件。沿東西

module "test_module" { 
    source = "./test_module" 
} 

你必須確保模塊的配置存在,也源是有效的。要獲得輸出,需要運行terraform apply後創建的狀態文件。看起來你要麼沒有你的狀態文件,要麼沒有輸出。