gpt4 book ai didi

azure - 属性值不适当 "network_interface_id": string required

转载 作者:行者123 更新时间:2023-12-03 03:56:06 28 4
gpt4 key购买 nike

Error: Incorrect attribute value type

on resources.tf line 387, in resource "azurerm_network_interface_backend_address_pool_association" "main":*
387: network_interface_id = module.linuxservers.vm_ids
|----------------
| module.linuxservers.vm_ids is tuple with 3 elements

Inappropriate value for attribute "network_interface_id": string required

您好,我正在尝试将我的 3 个 Azure VM 关联到 LoadBalancer 后端池,但遇到上述错误,您能否指导我,我的代码如下。

资源.tf

module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.main.name
vm_hostname = "Elastic"
nb_instances = 3
nb_public_ip = 0
remote_port = "22"
admin_username = var.admin_username
vm_os_publisher = "OpenLogic"
vm_os_offer = "CentOS"
vm_os_sku = "7.5"
vm_size = "Standard_D2as_v4"
ssh_key = "./putty_key.pub"
vnet_subnet_id = data.azurerm_subnet.elasticsearch.id
tags = var.tags

}
resource "azurerm_lb" "main"{
name = "Elastic_LB"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name

frontend_ip_configuration{
name = "FrontEndIP"
subnet_id = data.azurerm_subnet.elasticsearch.id
}

}
resource "azurerm_lb_backend_address_pool" "main" {
resource_group_name = azurerm_resource_group.main.name
loadbalancer_id = azurerm_lb.main.id
name = "BackEndAddressPool"
}

resource "azurerm_network_interface_backend_address_pool_association" "main" {
ip_configuration_name = "Configuration-VMs"
network_interface_id = module.linuxservers.vm_ids
backend_address_pool_id = azurerm_lb_backend_address_pool.main.id
}

模块/main.tf

resource "azurerm_virtual_machine" "vm-linux" {
count = ! contains(list(var.vm_os_simple, var.vm_os_offer), "WindowsServer") && ! var.is_windows_image ? var.nb_instances : 0
name = "${var.vm_hostname}-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
delete_os_disk_on_termination = var.delete_os_disk_on_termination



dynamic identity {
for_each = length(var.identity_ids) == 0 && var.identity_type == "SystemAssigned" ? [var.identity_type] : []
content {
type = var.identity_type
}
}

dynamic identity {
for_each = length(var.identity_ids) > 0 || var.identity_type == "UserAssigned" ? [var.identity_type] : []
content {
type = var.identity_type
identity_ids = length(var.identity_ids) > 0 ? var.identity_ids : []
}
}

storage_image_reference {
id = var.vm_os_id
publisher = var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""
offer = var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""
sku = var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""
version = var.vm_os_id == "" ? var.vm_os_version : ""
}

storage_os_disk {
name = "osdisk-${var.vm_hostname}-${count.index}"
create_option = "FromImage"
caching = "ReadWrite"
managed_disk_type = var.storage_account_type
}

dynamic storage_data_disk {
for_each = range(var.nb_data_disk)
content {
name = "${var.vm_hostname}-datadisk-${count.index}-${storage_data_disk.value}"
create_option = "Empty"
lun = storage_data_disk.value
disk_size_gb = var.data_disk_size_gb
managed_disk_type = var.data_sa_type
}
}

os_profile {
computer_name = "${var.vm_hostname}-${count.index}"
admin_username = var.admin_username
admin_password = var.admin_password
custom_data = var.custom_data
}

}
}

tags = var.tags

boot_diagnostics {
enabled = var.boot_diagnostics
storage_uri = var.boot_diagnostics ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : ""
}
}

模块/output.tf

output "vm_ids" {
description = "Virtual machine ids created."
value = concat(azurerm_virtual_machine.vm-windows.*.id, azurerm_virtual_machine.vm-linux.*.id)
}

output "network_security_group_id" {
description = "id of the security group provisioned"
value = azurerm_network_security_group.vm.id
}

output "network_security_group_name" {
description = "name of the security group provisioned"
value = azurerm_network_security_group.vm.name
}

output "network_interface_ids" {
description = "ids of the vm nics provisoned."
value = azurerm_network_interface.vm.*.id
}

output "network_interface_private_ip" {
description = "private ip addresses of the vm nics"
value = azurerm_network_interface.vm.*.private_ip_address
}

最佳答案

您需要为“ids”中的每个元素进行配置,因此它应该如下所示:

resource "azurerm_network_interface_backend_address_pool_association" "main" {
count = var.node_count
ip_configuration_name = "Configuration-VMs-${count.index}"
network_interface_id = element(module.linuxservers.vm_ids, count.index)
backend_address_pool_id = azurerm_lb_backend_address_pool.main.id
}

我不确定这里的语法element(module.linuxservers.vm_ids, count.index),因为我不知道这个输出是在哪里定义的(也许我是瞎子)。但这正是您所需要的。

关于azure - 属性值不适当 "network_interface_id": string required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64552185/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com