hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.49k stars 9.52k forks source link

Unable to access all the elements of a list from module output in 0.12 #22899

Open aditya-ambati opened 5 years ago

aditya-ambati commented 5 years ago
### Terraform Version
Terraform v0.12.7

Terraform Configuration Files

# Virtual Machine module main.tf
resource "azurerm_virtual_machine" "vm" {
  count                        = var.vm_instances_count
  name                         = "${var.vm_name}${format(var.count_format, var.count_offset + count.index + 1)}"
  location                     = var.location
  availability_set_id          = var.avset_id
  primary_network_interface_id = var.multi_nic == "true" ? var.primary_nic_id : null
  resource_group_name          = var.resource_group_name
  network_interface_ids        = [element(var.nic, count.index)]
  vm_size                      = var.vm_size
  }

# Virtual Machine module vars.tf
variable "nic" {
  default     = [""]
  description = "Network Interface ID"
}

# environments/dev/main.tf (calling nic module)
module "fw_nic" {
  source               = "../../nic"
  vm_name              = var.fw_vm_name
  location             = var.location
  resource_group_name  = module.resource_group.name
  vm_instances_count   = var.fw_vm_nic_count
  vnet_subnet_id       = module.fw_subnet.subnet_id[0]
  nsg_id               = module.fw_nsg.nsg_id[0]
  lb_enable            = "no"
  enable_ip_forwarding = "true"
}
# environments/dev/vars.tf
variable "fw_vm_nic_count" {
  description = "Firewall VM nic count"
}

# environments/dev/dev.tfvars
fw_vm_nic_count = "2"

# environments/dev/main.tf (calling vm module)
module "fw_vm" {
  source              = "../../virtual_machines"
  vm_name             = var.fw_vm_name
  location            = var.location
  resource_group_name = module.resource_group.name
  vm_instances_count  = var.fw_vm_instances_count
  vm_size             = var.fw_vm_size
  admin_username      = var.fw_vm_admin_username
  admin_password      = var.fw_vm_admin_password
  nic                 = [module.fw_nic.nic_id]
  primary_nic_id      = module.fw_nic.nic_id[0]
  avset_id            = module.fw_avset.id
  disk_size_gb        = var.fw_vm_disk_size_gb
  os_disk_type        = var.fw_vm_os_disk_type
  data_disk_type      = var.fw_vm_data_disk_type
  image_publisher     = var.fw_vm_image_publisher
  image_offer         = var.fw_vm_image_offer
  image_sku           = var.fw_vm_image_sku
  image_version       = var.fw_vm_image_version
  data_disk_enable    = "true
}

Debug Output

Crash Output

Expected Behavior

Attach two network interfaces to virutal machine

Actual Behavior

Only one network interface was attached

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply

    Additional Context

    I have also tried below syntax, it doesn't throw any error but only one nic gets attached to vm.

    nic = [module.fw_nic.nic_id[0], module.fw_nic.nic_id[1]]

    References