Невозможно создать и подключить публичный ip ro VM с помощью terraform - PullRequest
1 голос
/ 27 мая 2019

При попытке создать публичный ip

2019-05-27T03:07:44.5185437Z * azurerm_network_interface.tf-ni-erx-sqlcl1[1]: Resource 'azurerm_public_ip.tf-pip-erx-sqlcl1' not found for variable 'azurerm_public_ip.tf-pip-erx-sqlcl1.id'
2019-05-27T03:07:44.5186152Z * azurerm_network_interface.tf-ni-erx-sqlcl1[0]: Resource 'azurerm_public_ip.tf-pip-erx-sqlcl1' not found for variable 'azurerm_public_ip.tf-pip-erx-sqlcl1.id'
2019-05-27T03:07:44.5186473Z * azurerm_network_interface.tf-ni-erx-sqlcl2: 2 error(s) occurred:
2019-05-27T03:07:44.5186558Z 
2019-05-27T03:07:44.5186910Z * azurerm_network_interface.tf-ni-erx-sqlcl2[0]: Resource 'azurerm_public_ip.tf-pip-erx-sqlcl2' not found for variable 'azurerm_public_ip.tf-pip-erx-sqlcl2.id'
2019-05-27T03:07:44.5187360Z * azurerm_network_interface.tf-ni-erx-sqlcl2[1]: Resource 'azurerm_public_ip.tf-pip-erx-sqlcl2' not found for variable 'azurerm_public_ip.tf-pip-erx-sqlcl2.id'

у меня появляется следующая ошибка:

resource "azurerm_public_ip" "tf-pip-erx-sqlcl1" {
  count                     = "${var.count_sqlcl1_vm}"
  name                      = "${var.sql_base_hostname}${format("%02d",count.index+1)}-pip01"
  location                  = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
  resource_group_name       = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
  allocation_method         = "Dynamic"
}
# Network inteface for sql
resource "azurerm_network_interface" "tf-ni-erx-sqlcl1" {
 count               = "${var.count_sqlcl1_vm}"
 name                = "${var.bussvc_base_hostname}${format("%02d",count.index+1)}-nic01"
 location            = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
 resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"

ip_configuration {
    name                          = "${var.sql_base_hostname}${format("%02d",count.index+1)}-iip01"
    subnet_id                     = "${data.azurerm_subnet.tf-sn-erx-sql.id}"
    private_ip_address_allocation = "${var.env=="msdn"?"dynamic":"static"}"
    #private_ip_address            = "${var.env=="msdn"?"":"10.112.3.${count.index+10}"}"
    public_ip_address_id          = "${azurerm_public_ip.tf-pip-erx-sqlcl1.id}"
}
}
resource "azurerm_public_ip" "tf-pip-erx-sqlcl2" {
  count                     = "${var.count_sqlcl2_vm}"
  name                      = "${var.sql_base_hostname}${format("%02d",count.index+1)}-pip01"
  location                  = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
  resource_group_name       = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
  allocation_method         = "Dynamic"
}
resource "azurerm_network_interface" "tf-ni-erx-sqlcl2" {
 count               = "${var.count_sqlcl2_vm}"
 name                = "${var.sql_base_hostname}${format("%02d%s",count.index,var.count_sqlcl1_vm)}-nic01"
 location            = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
 resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"

ip_configuration {
    name                          = "${var.sql_base_hostname}${format("%02d",count.index+1)}-iip01"
    subnet_id                     = "${data.azurerm_subnet.tf-sn-erx-sql.id}"
    private_ip_address_allocation = "${var.env=="msdn"?"dynamic":"static"}"
    #private_ip_address           = "10.112.3.${count.index+15}"
    public_ip_address_id          = "${azurerm_public_ip.tf-pip-erx-sqlcl2.id}"
}
}

Я не могу понять, что такоепроблема, я специально добавил «зависящий_on» к сетевому интерфейсу, блок конфигурации ip, как показано нижеТакже не помогает.

Он сообщает об ошибке, как показано ниже,

Error: azurerm_network_interface.tf-ni-erx-sqlcl2[1]: ip_configuration.0: invalid or unknown key: depends_on

Любая помощь будет принята с благодарностью.

1 Ответ

1 голос
/ 27 мая 2019

Об ошибке, так как ваш ресурс "azurerm_network_interface" имеет счетчик, вы можете изменить public_ip_address_id следующим образом с element функцией:

public_ip_address_id          = "${element(azurerm_public_ip.tf-pip-erx-sqlcl1.*.id,count.index)}"

и

public_ip_address_id          = "${element(azurerm_public_ip.tf-pip-erx-sqlcl2.*.id,count.index)}"
...