我有下面的 TF 文件,它将创建一个函数 - FirstFunction。这完美地工作。
resource "azurerm_function_app" "**firstfunction**" {
name = **var.firstfunctionname**
location = azurerm_resource_group.resourcegroupX.location
resource_group_name = azurerm_resource_group.resourcegroupX.name
app_service_plan_id = azurerm_app_service_plan.appserviceplan.id
https_only = "true"
client_affinity_enabled = "true"
app_settings = {
NS = azurerm_eventhub_namespace.eventhubns.name
Hub = azurerm_eventhub.**firsteventhub**.name
propertyX = "**firstproperty**"
LogRef = "${azurerm_storage_account.store.primary_blob_endpoint}${azurerm_storage_container.**firstlogs**.name}"
}
}
resource "azurerm_app_service_virtual_network_swift_connection" "**firstvnet**" {
app_service_id = azurerm_function_app.**firstfunction**.id
subnet_id = azurerm_subnet.snet.id
}
在文件中,看到用****括起来的部分,需要更改以创建SecondFunction,ThirdFunction等...
我现在的方法是创建多个 TF 文件,复制相同的代码并更改 ** 中包含的部分。
我通读了模块系统,但了解模块系统的限制是我无法引用在同一 TF 根模块中创建的其他组件,如下所示例如在 TF 文件中,我将位置称为 location = azurerm_resource_group.resourcegroupX .location 如果我将其作为一个模块进行,则该位置应称为 location = var.location_name 其中 location_name 应定义为变量。我不能引用使用相同根模块创建的组件。
您能否提出一个解决方案,让我可以根据类似的代码创建多个组件?请注意,在上面的示例中,我在单个 TF 文件中创建了 2 个资源,并且它们都是相关的。