Skip to content

Commit

Permalink
Fix #736: updated Azure VM tags map init (#757)
Browse files Browse the repository at this point in the history
* Updated VM tags module and tests

* Enforce complex password requirement

* Added tag variable

* Enforce complex password requirement mysqldb

* Added missing build tag resgrp_test

* Updated unit test

* Updated module and reverted unit test.

* Updated revert.

* Updated tag test

* Updated to use output, removed additional updates

* Removed extra changes
  • Loading branch information
davesee authored Feb 11, 2021
1 parent 6d329f3 commit fd8775e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/azure/terraform-azure-vm-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ resource "azurerm_virtual_machine" "vm_example" {
provision_vm_agent = true
}

tags = {
"Version" = "0.0.1"
"Environment" = "dev"
}

depends_on = [random_password.rand]
}

Expand Down
4 changes: 4 additions & 0 deletions examples/azure/terraform-azure-vm-example/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ output "vm_name" {
output "vm_size" {
value = azurerm_virtual_machine.vm_example.vm_size
}

output "vm_tags" {
value = azurerm_virtual_machine.vm_example.tags
}
4 changes: 2 additions & 2 deletions modules/azure/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ func GetVirtualMachineTags(t testing.TestingT, vmName string, resGroupName strin
// GetVirtualMachineTagsE gets the Tags of the specified Virtual Machine as a map.
func GetVirtualMachineTagsE(vmName string, resGroupName string, subscriptionID string) (map[string]string, error) {
// Setup a blank map to populate and return
var tags map[string]string
tags := make(map[string]string)

// Get VM Object
vm, err := GetVirtualMachineE(vmName, resGroupName, subscriptionID)
if err != nil {
return nil, err
return tags, err
}

// Range through existing tags and populate above map accordingly
Expand Down
5 changes: 5 additions & 0 deletions test/azure/terraform_azure_vm_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func testInformationOfVM(t *testing.T, terraformOptions *terraform.Options, subs
expectedImageSKU := terraform.OutputList(t, terraformOptions, "vm_image_sku")
expectedImageVersion := terraform.OutputList(t, terraformOptions, "vm_image_version")
expectedAvsName := terraform.Output(t, terraformOptions, "availability_set_name")
expectedVMTags := terraform.OutputMap(t, terraformOptions, "vm_tags")

// Check if the Virtual Machine exists.
assert.True(t, azure.VirtualMachineExists(t, virtualMachineName, resourceGroupName, subscriptionID))
Expand All @@ -131,6 +132,10 @@ func testInformationOfVM(t *testing.T, terraformOptions *terraform.Options, subs
// The AVS ID returned from the VM is always CAPS so ignoring case in the assertion.
actualexpectedAvsName := azure.GetVirtualMachineAvailabilitySetID(t, virtualMachineName, resourceGroupName, subscriptionID)
assert.True(t, strings.EqualFold(expectedAvsName, actualexpectedAvsName))

// Check the assigned Tags of the VM, assert empty if no tags.
actualVMTags := azure.GetVirtualMachineTags(t, virtualMachineName, resourceGroupName, "")
assert.Equal(t, expectedVMTags, actualVMTags)
}

// These tests check the OS Disk and Attached Managed Disks for the Azure Virtual Machine.
Expand Down

0 comments on commit fd8775e

Please sign in to comment.