Skip to content

Commit

Permalink
Add option to create availability_set
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Cheney committed Jun 29, 2020
1 parent 2880863 commit 8f15848
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 10 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ locals {
identity_id = try(coalesce(var.identity_id, var.defaults.identity_id), null)
storage_account_type = coalesce(var.storage_account_type, var.defaults.storage_account_type, "Standard_LRS")

// application_security_group = var.application_security_group_id != "" || var.load_balancer_object.application_security_group_id != "" ? true : false
// application_security_group_id = try(coalesce(var.application_security_group_id, var.load_balancer_object.application_security_group_id), "")

application_security_group_ids = { for p in setproduct(local.names, keys(var.application_security_group_ids)) :
format("%s-%s", p[0], p[1]) => {
vm_name = p[0]
Expand All @@ -38,6 +35,15 @@ locals {
}
}

resource "azurerm_availability_set" "vm" {
depends_on = [var.module_depends_on]
for_each = toset(length(var.availability_set_name) > 0 ? [var.availability_set_name] : [])
name = each.value
resource_group_name = local.resource_group_name
location = local.location
tags = local.tags
}

resource "azurerm_network_interface" "vm" {
for_each = toset(local.names)
name = "${each.value}-nic"
Expand Down Expand Up @@ -85,7 +91,7 @@ resource "azurerm_linux_virtual_machine" "vm" {
admin_username = local.admin_username
disable_password_authentication = true
size = local.vm_size
availability_set_id = var.availability_set_id
availability_set_id = length(var.availability_set_name) > 0 ? azurerm_availability_set.vm[var.availability_set_name].id : var.availability_set_id
// zone = 'A'

network_interface_ids = [azurerm_network_interface.vm[each.key].id]
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ variable "boot_diagnostics_uri" {

// ==============================================================================

variable "availability_set_name" {
description = "Create an availability set with the specified name. Do not use both availability_set_name and availability_set_id."
type = string
default = ""
}

variable "availability_set_id" {
description = "Availability set resource ID"
description = "Availability set resource ID - attaches NIC. Do not use both availability_set_name and availability_set_id."
type = string
default = null
}
Expand Down

0 comments on commit 8f15848

Please sign in to comment.