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

Add boot diagnostics option #7

Merged
merged 17 commits into from
Oct 11, 2017
Merged

Conversation

jmapro
Copy link

@jmapro jmapro commented Oct 3, 2017

Allow to add boot diagnostics option.

Copy link
Contributor

@dtzar dtzar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did some testing to try and make this work. count does not work and if you go down the path to do a conditional on the storage_uri you'll run into this limitation of HCL: hashicorp/terraform#15605

@@ -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}"
Copy link
Contributor

Choose a reason for hiding this comment

The 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 boot_diagnostics to false, I still get these errors:

Error running plan: 1 error(s) occurred:

* module.mycompute.azurerm_virtual_machine.vm-windows: 2 error(s) occurred:

* module.mycompute.azurerm_virtual_machine.vm-windows[1]: Resource 'azurerm_storage_account.vm-sa' not found for variable 'azurerm_storage_account.vm-sa.primary_blob_endpoint'
* module.mycompute.azurerm_virtual_machine.vm-windows[0]: Resource 'azurerm_storage_account.vm-sa' not found for variable 'azurerm_storage_account.vm-sa.primary_blob_endpoint'

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. I fixed this issue in commit 4cc1a4a.

dtzar and others added 4 commits October 9, 2017 15:26
Add vm_hostname to nic interface name for more comprehension
Add vm_hostname to os_disk name
Allow delete_os_disk_on_termination to be specified in variables
Copy link
Contributor

@dtzar dtzar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So close, thanks for your contribution! I think after this one change we should be good to merge.

main.tf Outdated
@@ -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:]]/",""))}"
Copy link
Contributor

@dtzar dtzar Oct 10, 2017

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.

* azurerm_storage_account.vm-sa: Error creating Azure Storage Account 'myvm': storage.AccountsClient#Create: Failure responding to request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=409 Code="StorageAccountAlreadyExists" Message="The storage account named myvm already exists under the subscription."

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?

Copy link
Author

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

Copy link
Author

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 ?

Copy link
Contributor

@dtzar dtzar Oct 11, 2017

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 like format(var.vm_hostname, arg which uses only first # of characters) + diag + random id.

Copy link
Author

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 :)

@dtzar
Copy link
Contributor

dtzar commented Oct 11, 2017

LGTM

@dtzar dtzar merged commit 40cf893 into Azure:master Oct 11, 2017
@jmapro jmapro deleted the Add_boot_diagnostics_option branch October 18, 2017 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants