我在使用terraform时遇到了一个奇怪的问题。
考虑以下文件系统:
├── Modules
│ └── IAM
│ ├── outputs.tf
│ ├── resources.tf
│ └── variables.tf
├── outputs.tf
├── providers.tf
├── resources.tf
(Created automatically by Terraform)
├── terraform.tfstate
└── terraform.tfstate.backup
我从IAM
模块调用root
模块:
##resources.tf
# Other Resource configuration...
# Calling IAM module
module "iam" {
source = "Modules/IAM"
}
这很简单,在我重命名模块的文件夹 name之前,一切都很好。
文件夹的原始名称是IAM_Module
,当我将它更改为IAM
时,事情就开始中断了。
terraform init
的输出(模块的名称是iam
,所以不要混淆):
Initializing modules...
- module.iam
Error downloading modules: Error loading modules: module iam:
open .terraform/modules/94...5b: no such file or directory
在.terraform/modules
内部检查,我可以看到,由于某种原因,指向文件夹旧名称(IAM_Module
)的符号链接仍然存在:
├── 94...5b -> /lab1/Modules/IAM
├── b7...3d -> /lab1/Modules/IAM_Module <--- Previous name of folder
└── modules.json
在terraform.tfstate
内部,我可以看到模块存在(在根之后):
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {},
"depends_on": []
},
{
"path": [
"root",
"iam" <----- Here
],
"outputs": {},
"resources": {
我尝试过terraform refresh
,但是我也收到了相同的no such file or directory
错误。
Terraform版本: v0.11.11。
任何帮助都将不胜感激。
(*)在这条线中,他们似乎通过人工干预解决了相同的错误(由不同的原因引起),而我更希望避免这种错误。
发布于 2019-11-15 09:25:40
我又试着重复这个问题。
首先,我手动删除了.terraform
文件并运行了terraform init
。
现在我处于文件重命名之前的状态。
在再次重命名该文件后,我运行了terraform plan
,并收到了以下显式错误:
Error: Error loading modules: module iam: not found, may need to run 'terraform init'.
运行terraform init
后,我检查了.terraform/modules
文件,并看到了2个符号链接:
这两个模块仍然出现在modules.json
文件下。
不知道为什么这条消息在我第一次尝试时就没有弹出,但我认为在这种情况下Terraform 获取命令也可能有所帮助--从文档中:
terraform命令用于下载和更新根模块中提到的模块。
在我的例子中,模块已经下载了,所以我不得不使用terraform get
标志运行-update
:
如果已经下载了一个模块,并且没有设置-update标志,Terraform将什么也不做。
我认为在删除自动生成的文件(如terraform init / get
)之前,需要考虑两种解决方案之一( .terraform
)。
我希望这能帮到别人。
https://stackoverflow.com/questions/58856454
复制相似问题