【问题标题】:Creating a private endpoint for cosmosDB autogenerates a new network interface. How can I use the network interface I created?为 cosmosDB 创建专用终结点会自动生成新的网络接口。如何使用我创建的网络接口?
【发布时间】:2020-09-21 21:42:23
【问题描述】:

下面的代码应该创建一个 cosmosdb、网络接口 (NIC) 和私有端点 (PE)。

当运行下面的 terraform 代码时,它会自动生成第二个具有动态 ip、无标签和通用名称(如“pe.nic.9xxxxxb-85d7-4756-8b78-dxxxxxxx”)的 NIC。

最好我想使用通过 terraform 代码创建的 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            = "-"
  }
}

【问题讨论】:

  • 你试过这个吗:mssqltips.com/sqlservertip/6167/…
  • 自动创建的 Nic 没有锁(创建的其他资源相同),但我在文档中发现它无法更改(通过 PS 和 Azure 门户确认) .

标签: terraform


【解决方案1】:

根据https://github.com/MicrosoftDocs/azure-docs/issues/50919,静态IP是不可能的:

一般来说,使用私有端点,生成的网络接口是 在私有端点的生命周期内只读和管理 资源。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 2010-09-08
    • 1970-01-01
    • 2014-02-27
    • 2020-06-17
    相关资源
    最近更新 更多