2017-06-14 37 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后创建的状态文件。看起来你要么没有你的状态文件,要么没有输出。