Terraform实例枚举

时间:2019-02-18 15:41:47

标签: terraform terraform-provider-azure

我正在尝试将枚举的VM实例注册到Azure备份服务。但是,我得到一个错误:

* azurerm_recovery_services_protected_vm.consul_and_vault: source_vm_id must be a single value, not a list

这是我在Azure中创建VM实例的代码片段:

###############################################################################
# Deploy VMs and Configure Consul and Vault Services
###############################################################################

resource "azurerm_virtual_machine" "consul" {
  name                             = "consul${count.index + 1}"
  #name                             = "${var.consul_cluster_prefix}-consul-${count.index + 1}"
  location                         = "${var.deployment_location}"
  resource_group_name              = "${var.resource_group_name}"
  availability_set_id              = "${azurerm_availability_set.consul.id}"
  network_interface_ids            = ["${element(azurerm_network_interface.consul_nic.*.id, count.index + 1)}"]
  vm_size                          = "${var.consul_vm_size}"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true
  count                            = "${var.consul_instance_count}"
  tags {
    ownerinfo            = "${var.ownerinfo}"
    costcenter           = "${var.costcenter}"
    deploymenttype       = "${var.deploymenttype}"
    notificationdistlist = "${var.notificationdistlist}"
    env_info             = "${var.environmentinfo}"
    application_name     = "${var.applicationname}"
    platform             = "${var.platform}"
  }
  storage_image_reference {
    id  ="${var.consul_image_id}"
 }
...

后来,在创建备份集时,我试图引用枚举的VM实例:

##########################################################################################
# AzureRM Virtual Machine Into Azure Recovery Services Vault
##########################################################################################

resource "azurerm_recovery_services_vault" "backup2vault" {
    name    = "azurerecoveryvaulti1"
    location = "${var.deployment_location}"
    resource_group_name = "${var.resource_group_name}"
    sku     = "Standard"
}

resource "azurerm_recovery_services_protection_policy_vm" "consul_daily" {
  name                = "azurerecoveryvaultpolicy1"
  resource_group_name = "${var.resource_group_name}"
  recovery_vault_name = "${azurerm_recovery_services_vault.backup2vault.name}"

  backup = {
    frequency = "Daily"
    time      = "23:00"
  }

  retention_daily = {
    count = 1
  }
}

resource "azurerm_recovery_services_protected_vm" "consul_and_vault" {
  resource_group_name = "${var.resource_group_name}"
  recovery_vault_name = "${azurerm_recovery_services_vault.backup2vault.name}"
  source_vm_id        = "${azurerm_virtual_machine.consul.*.id}"
  backup_policy_id    = "${azurerm_recovery_services_protection_policy_vm.consul_daily.id}"
}

问题似乎在于变量source_vm_id如何引用枚举实例:

source_vm_id        = "${azurerm_virtual_machine.consul.*.id}"

...这会导致错误:

 azurerm_recovery_services_protected_vm.consul_and_vault: source_vm_id must be a single value, not a list

问题是,在我的案例中如何引用枚举实例?

非常感谢您提供任何反馈意见。

A。

1 个答案:

答案 0 :(得分:2)

您需要将*** Settings *** Library SeleniumLibrary Library cumulusci.robotframework.CumulusCI Library cumulusci.robotframework.Salesforce Library OperatingSystem Suite Setup Setup chromedriver variables variables.py *** Test Cases *** Create/Delete Account Setup chromedriver Login Verify Login Create New Account Teardown *** Keywords *** Login Open Browser https://login.salesforce.com/ chrome Input Text id:username ${USERNAME} Input Text id:password ${PASSWORD} Click Element Login Verify Login Wait Until Page Contains Home timeout=20 Teardown Close Browser Create New Account Wait Until Loading Is Complete Wait For Aura Click Link Accounts Wait For Aura Click Object Button New Setup chromedriver Set Environment Variable webdriver.chrome.driver ${EXECDIR}/chromedriver.exe ` 资源枚举为与azurerm_recovery_services_protected_vm.consul_and_vault资源相同的长度。然后,您可以将每个azurerm_virtual_machine.consul引用为azurerm_virtual_machine.consul.id中的元素,并使用与count.index相同的元素编号。然后看起来像:

azurerm_virtual_machine.consul

还要注意,resource "azurerm_recovery_services_protected_vm" "consul_and_vault" { count = "${var.consul_instance_count}" resource_group_name = "${var.resource_group_name}" recovery_vault_name = "${azurerm_recovery_services_vault.backup2vault.name}" source_vm_id = "${azurerm_virtual_machine.consul.*.id[count.index]}" backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.consul_daily.id}" } 语法将azurerm_virtual_machine.consul.*.id输出为列表。