模块目录不存在或无法在 Terraform 中读取
Module directory does not exist or cannot be read in Terraform
我正在尝试在我的 Terraform 代码中使用模块作为依赖项。但即使在模块中提到特定的源路径之后,它也会给出错误“模块目录不存在或无法读取。”和“无法评估目录——系统找不到指定的文件。”谁能告诉我是什么原因。
我必须管理 3 个不同的环境,每个环境有 3 个不同的后端状态文件。这里每个主文件调用各自的模块 file.The 主文件夹由后端配置、资源组的创建组成,它调用模块文件
root
|
|-- main
| |--prod
| |--dev
| |--staging
|-- modules
| |--prod
| |--dev
| |--staging
------------代码----------------
provider "azurerm" {
version = "=2.2.0"
features {}
}
#--- CREATING RESOURCE GROUP PER ENVIRONEMENT
terraform {
backend "azurerm" {
resource_group_name = ""
storage_account_name = ""
container_name = ""
key = ""
}
}
variable "location" {
description = "Location for deployment of the Azure
resources"
}
variable "Code" {
description = "Enter a unique two-letter ID to identify
customer resources; should match the DynamoDB table."
}
variable "EnvironmentType" {
description = "Enter a valid environment type. Valid values are
Prod, Dev, Staging"
}
variable "AccountType" {
description = "Select the type of account you wish to create. This
will determine which environments and other resources are created."
}
resource "azurerm_resource_group" "main" {
name = "${var.Code}-${var.EnvironmentType}"
location = "${var.location}"
}
module "ResourcesStack" {
source = "./modules"
AccountType = "${var.AccountType}"
CustomerCode = "${var.Code}"
EnvironmentType = "${var.EnvironmentType}"
location = "${var.location}"
}
嗯,通过沟通,我认为你在 Terraform 代码中引用模块时犯了错误。
错误的是,要引用模块时,需要引用特殊的模块。比如你想引用模块dev,那么在Terraform代码中可以这样引用:
module "dev" {
source = "./modules/dev"
...
}
不要像你一样用所有模块的根路径设置模块源。
始终确保目录名称是 module 而不是模块。
我遇到了同样的问题,更新目录名称后,问题已解决。
我正在尝试在我的 Terraform 代码中使用模块作为依赖项。但即使在模块中提到特定的源路径之后,它也会给出错误“模块目录不存在或无法读取。”和“无法评估目录——系统找不到指定的文件。”谁能告诉我是什么原因。
我必须管理 3 个不同的环境,每个环境有 3 个不同的后端状态文件。这里每个主文件调用各自的模块 file.The 主文件夹由后端配置、资源组的创建组成,它调用模块文件
root
|
|-- main
| |--prod
| |--dev
| |--staging
|-- modules
| |--prod
| |--dev
| |--staging
------------代码----------------
provider "azurerm" {
version = "=2.2.0"
features {}
}
#--- CREATING RESOURCE GROUP PER ENVIRONEMENT
terraform {
backend "azurerm" {
resource_group_name = ""
storage_account_name = ""
container_name = ""
key = ""
}
}
variable "location" {
description = "Location for deployment of the Azure
resources"
}
variable "Code" {
description = "Enter a unique two-letter ID to identify
customer resources; should match the DynamoDB table."
}
variable "EnvironmentType" {
description = "Enter a valid environment type. Valid values are
Prod, Dev, Staging"
}
variable "AccountType" {
description = "Select the type of account you wish to create. This
will determine which environments and other resources are created."
}
resource "azurerm_resource_group" "main" {
name = "${var.Code}-${var.EnvironmentType}"
location = "${var.location}"
}
module "ResourcesStack" {
source = "./modules"
AccountType = "${var.AccountType}"
CustomerCode = "${var.Code}"
EnvironmentType = "${var.EnvironmentType}"
location = "${var.location}"
}
嗯,通过沟通,我认为你在 Terraform 代码中引用模块时犯了错误。
错误的是,要引用模块时,需要引用特殊的模块。比如你想引用模块dev,那么在Terraform代码中可以这样引用:
module "dev" {
source = "./modules/dev"
...
}
不要像你一样用所有模块的根路径设置模块源。
始终确保目录名称是 module 而不是模块。 我遇到了同样的问题,更新目录名称后,问题已解决。