我是 terraform 的新手,我在模块结构上创建了一个自定义的 azure 策略。每个策略代表一个自定义模块。我创建的模块之一是为创建的任何新 azure 资源启用诊断日志。但是,我需要一个存储帐户。(在启用诊断设置之前,我如何实现“depends_on”?或任何其他方法?
我想首先创建存储帐户,然后创建诊断设置模块。在main.tf(调用所有其他模块的地方)或资源内部(模块)?
谢谢您的帮助!!:)
下面的代码代表 main.tf 文件:
//calling the create storage account name
module "createstorageaccount" {
source = "./modules/module_create_storage_account"
depends_on = [
"module_enable_diagnostics_logs"
]
}
Run Code Online (Sandbox Code Playgroud)
这个代表创建存储帐户模块
resource "azurerm_resource_group" "management" {
name = "management-rg"
location = "West Europe"
}
resource "azurerm_storage_account" "test" {
name = "diagnostics${azurerm_resource_group.management.name}"
resource_group_name = "${azurerm_resource_group.management.name}"
location = "${azurerm_resource_group.management.location}"
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
environment = "diagnostics"
}
}
depends_on = [
"module_enable_diagnostics_logs"
]
Run Code Online (Sandbox Code Playgroud)