Created
August 4, 2017 11:32
-
-
Save tombuildsstuff/1e214b15fe12664d175622c8a02fdf00 to your computer and use it in GitHub Desktop.
hashicorp/terraform-provider-azurerm#199 Linux Terraform Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "prefix" { | |
default = "issue199" | |
} | |
variable "configuration_json" { | |
default = "{\"diagnosticMonitorConfiguration\":{\"metrics\":{\"resourceId\":\"%VirtualMachineResourceId%\",\"metricAggregation\":[{\"scheduledTransferPeriod\":\"PT1H\"},{\"scheduledTransferPeriod\":\"PT1M\"}]},\"performanceCounters\":{\"performanceCounterConfiguration\":[{\"class\":\"Memory\",\"counterSpecifier\":\"PercentAvailableMemory\",\"table\":\"LinuxMemory\"},{\"class\":\"Memory\",\"counterSpecifier\":\"AvailableMemory\",\"table\":\"LinuxMemory\"},{\"class\":\"Memory\",\"counterSpecifier\":\"UsedMemory\",\"table\":\"LinuxMemory\"},{\"class\":\"Memory\",\"counterSpecifier\":\"PercentUsedSwap\",\"table\":\"LinuxMemory\"},{\"class\":\"Processor\",\"counterSpecifier\":\"PercentProcessorTime\",\"table\":\"LinuxCpu\"},{\"class\":\"Processor\",\"counterSpecifier\":\"PercentIOWaitTime\",\"table\":\"LinuxCpu\"},{\"class\":\"Processor\",\"counterSpecifier\":\"PercentIdleTime\",\"table\":\"LinuxCpu\"},{\"class\":\"PhysicalDisk\",\"counterSpecifier\":\"AverageWriteTime\",\"table\":\"LinuxDisk\"},{\"class\":\"PhysicalDisk\",\"counterSpecifier\":\"AverageReadTime\",\"table\":\"LinuxDisk\"},{\"class\":\"PhysicalDisk\",\"counterSpecifier\":\"ReadBytesPerSecond\",\"table\":\"LinuxDisk\"},{\"class\":\"PhysicalDisk\",\"counterSpecifier\":\"WriteBytesPerSecond\",\"table\":\"LinuxDisk\"}]}}}" | |
} | |
resource "azurerm_resource_group" "test" { | |
name = "${var.prefix}-dev" | |
location = "West Europe" | |
} | |
resource "azurerm_virtual_network" "test" { | |
name = "${var.prefix}vn" | |
address_space = ["10.0.0.0/16"] | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
} | |
resource "azurerm_subnet" "test" { | |
name = "main" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
virtual_network_name = "${azurerm_virtual_network.test.name}" | |
address_prefix = "10.0.2.0/24" | |
} | |
resource "azurerm_network_interface" "test" { | |
name = "${var.prefix}-ni" | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
ip_configuration { | |
name = "testconfiguration1" | |
subnet_id = "${azurerm_subnet.test.id}" | |
private_ip_address_allocation = "dynamic" | |
} | |
} | |
resource "azurerm_storage_account" "test" { | |
name = "${var.prefix}sa22" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
location = "${azurerm_resource_group.test.location}" | |
account_type = "Standard_LRS" | |
tags { | |
environment = "staging" | |
} | |
} | |
resource "azurerm_virtual_machine" "test" { | |
name = "${var.prefix}-vm" | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
network_interface_ids = ["${azurerm_network_interface.test.id}"] | |
vm_size = "Standard_DS1_v2" | |
storage_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "14.04.5-LTS" | |
version = "latest" | |
} | |
storage_os_disk { | |
name = "myosdisk1" | |
caching = "ReadWrite" | |
create_option = "FromImage" | |
managed_disk_type = "Standard_LRS" | |
} | |
os_profile { | |
computer_name = "hostname" | |
admin_username = "testadmin" | |
admin_password = "Password1234!" | |
} | |
os_profile_linux_config { | |
disable_password_authentication = false | |
} | |
tags { | |
environment = "staging" | |
} | |
} | |
data "template_file" "xml" { | |
template = "${file("template.xml.tpl")}" | |
vars { | |
virtual_machine_id = "${azurerm_virtual_machine.test.id}" | |
} | |
} | |
resource "azurerm_virtual_machine_extension" "test" { | |
name = "hostname" | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
virtual_machine_name = "${azurerm_virtual_machine.test.name}" | |
publisher = "Microsoft.OSTCExtensions" | |
type = "LinuxDiagnostic" | |
type_handler_version = "2.3" | |
settings = <<SETTINGS | |
{ | |
"ladCfg": "${base64encode(var.configuration_json)}", | |
"storageAccount": "${azurerm_storage_account.test.name}" | |
} | |
SETTINGS | |
protected_settings = <<SETTINGS | |
{ | |
"storageAccountName": "${azurerm_storage_account.test.name}", | |
"storageAccountKey": "${azurerm_storage_account.test.primary_access_key}" | |
} | |
SETTINGS | |
tags { | |
environment = "Production" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so, the "no default credentials" seems to indicate your protected_settings dont include the storageaccount and storageaccountkey (or possibly the SAS) or maybe not accurately?
as for the xmlCfg v ladCfg, yes.. xmlCfg is the way to go and I found this stackoverflow article helpful as that string is base64 encoded.
https://stackoverflow.com/questions/38732786/enable-vm-basic-metrics-via-arm-template
so, just create a VM and enable the diags from the portal, then decode the xmlCfg from base64 and then you understand what it wants for the structure, and config entries.. and voila you should be able to reproduce it from the REST, powershell.. or or or....
HTH
funny note: when you enable the diags from the portal... it creates a "wadcfg" in the XML for a linux system (i would have expected a ladcfg).. go figure. :)
Steven