【发布时间】:2021-12-05 03:31:52
【问题描述】:
我正在使用 terraform 模块创建基础架构。一些常见和重复的基础设施是使用模块创建的 和其他资源是在模块之外独立创建的。我的代码结构描述如下。
-terraform\module\storage.tf
-terraform\main.tf
-terraform\mlws.tf
这是我的 /module/storage.tf 代码,我在其中创建这样的存储帐户
resource "azurerm_storage_account" "storage" {
name = var.storage_account_name
resource_group_name = var.rg_name
location = var.location
account_tier = "Standard"
account_replication_type = "GRS"
min_tls_version = "TLS1_2"
}
module "m1" {
source = "./modules"
storage_account_name = "m1storage"
rg_name = "rg1"
location = "USCentral"
}
module "m2" {
source = "./modules"
storage_account_name = "m2storage"
rg_name = "rg2"
location = "USCentral"
}
module "m3" {
source = "./modules"
storage_account_name = "m3storage"
rg_name = "rg3"
location = "USCentral"
}
resource "azurerm_machine_learning_workspace" "mlws" {
name = "mlws"
location = ""USCentral"
resource_group_name = "mlws-rg1"
application_insights_id = azurerm_application_insights.mlops_appins.id
key_vault_id = data.azurerm_key_vault.kv.id
storage_account_id = **<Mandatory to be filled>**
container_registry_id = azurerm_container_registry.acr.id
identity {
type = "SystemAssigned"
}
depends_on = [
module.m2
]
}
存储帐户的代码在\terraform\module\storage.tf下,调用模块的代码在\terraform\main.tf下,机器学习工作区的代码在\terraform\mlws.tf下。
由于我的 mlws.tf 代码在模块之外,但它需要与上述代码中在模块 m2 下创建的存储帐户 ID 相关联。 我正在努力获取“m2storage”存储帐户的 ID。您能否提供解决方案,说明如何访问通过模块创建的特定存储帐户的 ID 并将其附加到模块外部的代码中。
【问题讨论】: