Sid*_*kar 9 terraform-provider-azure terraform-modules
我正在尝试在我的 Terraform 代码中使用模块作为依赖项。但即使在提到模块中的特定源路径之后,它也会给出错误 \xe2\x80\x9c 模块目录不存在或无法读取。” 和 \xe2\x80\x9cUnable tovaluing directory \xe2\x80\x93 系统找不到指定的文件。” 谁能告诉我这可能是什么原因。
\n\n我必须管理 3 个不同的环境,每个环境有 3 个不同的后端状态文件。这里每个主文件都调用各自的模块文件。主文件夹由后端配置、资源组的创建和调用模块文件组成
\n\n root\n |\n |-- main \n | |--prod \n | |--dev \n | |--staging\n |-- modules\n | |--prod \n | |--dev \n | |--staging\nRun Code Online (Sandbox Code Playgroud)\n\n- - - - - - 代码 - - - - - - - - -
\n\n provider "azurerm" {\n version = "=2.2.0"\n features {}\n }\n\n #--- CREATING RESOURCE GROUP PER ENVIRONEMENT\n terraform {\n backend "azurerm" {\n resource_group_name = ""\n storage_account_name = ""\n container_name = ""\n key = ""\n }\n }\n\n\n variable "location" {\n description = "Location for deployment of the Azure \n resources"\n }\n\n variable "Code" {\n description = "Enter a unique two-letter ID to identify \n customer resources; should match the DynamoDB table."\n }\n\n variable "EnvironmentType" {\n description = "Enter a valid environment type. Valid values are \n Prod, Dev, Staging"\n }\n\n variable "AccountType" {\n description = "Select the type of account you wish to create. This \n will determine which environments and other resources are created."\n }\n\n\n resource "azurerm_resource_group" "main" {\n name = "${var.Code}-${var.EnvironmentType}"\n location = "${var.location}"\n }\n\n module "ResourcesStack" {\n source = "./modules"\n AccountType = "${var.AccountType}"\n CustomerCode = "${var.Code}"\n EnvironmentType = "${var.EnvironmentType}"\n location = "${var.location}"\n }\nRun Code Online (Sandbox Code Playgroud)\n
好吧,通过沟通,然后我认为您在引用 Terraform 代码中的模块时犯了错误。
错误在于,当你想引用模块时,你需要引用特殊的模块。例如,您想引用模块 dev,那么您可以在 Terraform 代码中引用它,如下所示:
module "dev" {
source = "./modules/dev"
...
}
Run Code Online (Sandbox Code Playgroud)
不要像您一样将模块源设置为所有模块的根路径。
| 归档时间: |
|
| 查看次数: |
39213 次 |
| 最近记录: |