【发布时间】:2020-07-05 23:17:44
【问题描述】:
我正在尝试将模块用于我的 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}"
}
【问题讨论】:
-
你能分享你使用的 Terraform 代码吗?而且你存储的模块在哪里也是必要的。
-
@CharlesXu 我已经添加了我的文件结构。
-
您还需要提供 Terraform 代码。
-
pred 和 dev 和 staging 是什么意思?不同的模块或 Terraform 文件?
-
根据层次结构,在主文件夹中,这些是 .tf 文件,在模块文件夹中,它们是包含所需模块的不同文件夹
标签: terraform-provider-azure terraform-modules