-
Notifications
You must be signed in to change notification settings - Fork 304
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
Add boot diagnostics option #7
Changes from 2 commits
50a869c
092753e
ed66005
84600bb
67a4dd3
29d98c7
21f40f3
0e6b530
5203610
4cc1a4a
ee7d8db
a7fcd85
ffae7f4
a265ddc
61941e0
9ee01ee
ca49841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,15 @@ resource "azurerm_resource_group" "vm" { | |
tags = "${var.tags}" | ||
} | ||
|
||
resource "azurerm_storage_account" "vm-sa" { | ||
count = "${var.boot_diagnostics == "true" ? 1 : 0}" | ||
name = "${lower(replace(var.vm_hostname,"/[[:^alpha:]]/",""))}" | ||
resource_group_name = "${azurerm_resource_group.vm.name}" | ||
location = "${var.location}" | ||
account_type = "${var.boot_diagnostics_sa_type}" | ||
tags = "${var.tags}" | ||
} | ||
|
||
resource "azurerm_virtual_machine" "vm-linux" { | ||
count = "${contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "WindowsServer") ? 0 : var.nb_instances}" | ||
name = "${var.vm_hostname}${count.index}" | ||
|
@@ -52,6 +61,10 @@ resource "azurerm_virtual_machine" "vm-linux" { | |
key_data = "${file("${var.ssh_key}")}" | ||
} | ||
} | ||
boot_diagnostics { | ||
enabled = "${var.boot_diagnostics}" | ||
storage_uri = "${azurerm_storage_account.vm-sa.primary_blob_endpoint}" | ||
} | ||
} | ||
|
||
resource "azurerm_virtual_machine" "vm-windows" { | ||
|
@@ -83,6 +96,10 @@ resource "azurerm_virtual_machine" "vm-windows" { | |
admin_username = "${var.admin_username}" | ||
admin_password = "${var.admin_password}" | ||
} | ||
boot_diagnostics { | ||
enabled = "${var.boot_diagnostics}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, it seems this code is not working for me because when I use the default of setting
When I set it to true, it works as expected. I'm using the latest terraform v0.10.7 with Azure module 0.2.2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review. I fixed this issue in commit 4cc1a4a. |
||
storage_uri = "${azurerm_storage_account.vm-sa.primary_blob_endpoint}" | ||
} | ||
} | ||
|
||
resource "azurerm_availability_set" "vm" { | ||
|
@@ -134,4 +151,4 @@ resource "azurerm_network_interface" "vm" { | |
private_ip_address_allocation = "Dynamic" | ||
public_ip_address_id = "${count.index == 0 ? azurerm_public_ip.vm.id : ""}" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This storage account name needs to be unique per subscription, so I worry it will easily become a problem for people using the
vm_hostname
.If we use the
public_ip_dns
value then we'd require people use a public IP address and we don't want that. If we add another variable with a default value then people would have to change it manually and that's not good. I'll just approve this as-is. Only thing which would be nice (not sure if its possible with hcl) is to append a random number to the storage account after the hostname. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The random value seems to be a good idea. I'll try to do something with the random module : https://www.terraform.io/docs/providers/random/index.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done some tests, and we can add a random id on the storage account name.
But, the storage account name is still base on vm hostname and we may go through the character limitation (between 3 and 24). What do you think about a full random name with a prefix like
bootdiagsa
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The random provider looks like it will work perfect! You can control the byte length so exceeding the characters won't be a problem. The safest route would be to use something like
bootdiag
plus the random string, which I'd be happy with. Only if you wanted to be fancy (not required ;)) then you could do something likeformat(var.vm_hostname, arg which uses only first # of characters)
+diag
+ random id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've choose the safest way :)