Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set "zero" value to azurerm_availability_set ID for a VM #17069

Closed
bigmyx opened this issue Jan 9, 2018 · 3 comments
Closed

Cannot set "zero" value to azurerm_availability_set ID for a VM #17069

bigmyx opened this issue Jan 9, 2018 · 3 comments

Comments

@bigmyx
Copy link

bigmyx commented Jan 9, 2018

Terraform Version

Terraform v0.11.1
+ provider.azurerm v1.0.0
+ provider.external v1.0.0
+ provider.null v1.0.0
+ provider.template v1.0.0

Terraform Configuration Files

resource "azurerm_availability_set" "ls-consumer-availset" {
  count               = "${var.service["num_consumer"] >= 2 ? 1 : 0}"
  name                = "${var.resource_group_name}-ls-consumer-${var.role}-availset"
  location            = "${var.azure_location}"
  managed             = true
  resource_group_name = "${var.resource_group_name}"
  platform_fault_domain_count = 2
}

resource "azurerm_virtual_machine" "ls-consumer" {
  count                 = "${var.service["num_consumer"]}"
  name                  = "${var.resource_group_name}-ls-consumer-${var.role}-${count.index}"
  location              = "${var.azure_location}"
  resource_group_name   = "${var.resource_group_name}"
  network_interface_ids = ["${element(azurerm_network_interface.ls-consumer.*.id, count.index)}"]
  availability_set_id   = "${azurerm_availability_set.ls-consumer-availset.count == 1 ? azurerm_availability_set.ls-consumer-availset.id : "" }"
  vm_size               = "${var.service["vm_type"]}"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true
  storage_os_disk {
    name              = "${var.resource_group_name}-ls-consumer-${var.role}-${count.index}-disk"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  storage_image_reference {
    publisher = "OpenLogic"
    offer     = "CentOS"
    sku       = "7.3"
    version   = "latest"
  }
  os_profile {
    computer_name  = "${var.resource_group_name}-ls-consumer-${var.role}-${count.index}"
    admin_username = "${var.params["ssh_user"]}"
  }
  os_profile_linux_config {
    disable_password_authentication = true
    ssh_keys {
      path = "/home/${var.params["ssh_user"]}/.ssh/authorized_keys"
      key_data = "${var.params["ssh_pub_key"]}"
    }
  }
}

Crash Output

...
module.logstash-ops.azurerm_virtual_machine.ls-consumer: Resource 'azurerm_availability_set.ls-consumer-availset' not found for variable 'azurerm_availability_set.ls-consumer-availset.id'
...

References

@bigmyx bigmyx changed the title Cannot set an "zero" value to azurerm_availability_set ID for a VM Cannot set "zero" value to azurerm_availability_set ID for a VM Jan 9, 2018
@bigmyx
Copy link
Author

bigmyx commented Jan 9, 2018

seems like it did not work because VM was created before the availability set.. so putting depends_on constraint for VM resource solved the issue for me.

@bigmyx bigmyx closed this as completed Jan 9, 2018
@rahulkp220
Copy link

@bigmyx Can you please paste the solution here? Or answer https://stackoverflow.com/questions/48306089/how-do-i-make-a-field-optional-inside-a-terraform-resource. I am facing the same issue.

@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants