我正在尝试在我的 Terraform 代码中使用模块作为依赖项。但即使在模块中提到特定的源路径后,它也会给出错误“模块目录不存在或无法读取。”和“无法评估目录 - 系统找不到指定的文件。” 谁能告诉我可能是什么原因。
我必须管理 3 个不同的环境,每个环境有 3 个不同的后端状态文件。这里每个主文件调用各自的模块文件。主文件夹包括后端配置,资源组的创建,它调用模块文件
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}"
}