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

Fix #736: updated Azure VM tags map init #757

Merged
merged 11 commits into from
Feb 11, 2021
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