下面的代码应该创建一个cosmosdb,网络接口(NIC)和专用端点(PE)。
运行下面的terraform代码时,它将自动生成具有动态ip,无标签和通用名称(如“ pe.nic.9xxxxxb-85d7-4756-8b78-dxxxxxxx”)的第二个NIC。
优选地,我想使用通过terraform代码创建的NIC而不是自动生成的NIC,以便能够控制标签,命名以及尽可能的静态ip。
PE的Terraform文档:https://www.terraform.io/docs/providers/azurerm/r/private_endpoint.html
Github的类似实现,未指定NIC:https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/examples/private-endpoint/cosmos-db/main.tf
我该如何实现?
resource "azurerm_cosmosdb_account" "cosmosDb" {
name = "MyCosmosDB"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
offer_type = "Standard"
consistency_policy {
consistency_level= "Session"
max_interval_in_seconds= 5
max_staleness_prefix= 100
}
geo_location {
failover_priority= 0
location= data.azurerm_resource_group.rg.location
}
tags = local.tags
}
resource "azurerm_network_interface" "nic" {
name = "example-nic"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
ip_configuration {
name = "nic-ip-config"
subnet_id = data.azurerm_subnet.subnet_vm.id
private_ip_address_allocation = "Static"
private_ip_address = var.ip
}
tags = local.tags
}
resource "azurerm_private_endpoint" "pe" {
name = "example-pe"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
subnet_id = data.azurerm_subnet.subnet_vm.id
private_service_connection {
is_manual_connection = true
name = "example-psc"
private_connection_resource_id = azurerm_cosmosdb_account.cosmosDb.id
subresource_names = ["sql"]
request_message = "-"
}
}
答案 0 :(得分:1)
根据https://github.com/MicrosoftDocs/azure-docs/issues/50919,无法使用静态IP:
通常对于专用端点,生成的网络接口为 在专用端点的生命周期内为只读并进行管理 资源。