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
4 changes: 4 additions & 0 deletions examples/azure/terraform-azure-mysqldb-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
min_upper = "1"
davesee marked this conversation as resolved.
Show resolved Hide resolved
min_lower = "1"
min_numeric = "1"
min_special = "1"
}

resource "azurerm_mysql_server" "mysqlserver" {
Expand Down
4 changes: 4 additions & 0 deletions examples/azure/terraform-azure-sqldb-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
min_upper = "1"
min_lower = "1"
min_numeric = "1"
min_special = "1"
}

resource "azurerm_sql_server" "sqlserver" {
Expand Down
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
4 changes: 4 additions & 0 deletions modules/azure/resourcegroup_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// +build azure

// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for
// CircleCI.
package azure

import (
Expand Down
6 changes: 6 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,8 @@ 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")
expectedVMTag02Name := "Environment"
davesee marked this conversation as resolved.
Show resolved Hide resolved
expectedVMTag02Value := "dev"

// Check if the Virtual Machine exists.
assert.True(t, azure.VirtualMachineExists(t, virtualMachineName, resourceGroupName, subscriptionID))
Expand All @@ -131,6 +133,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, actualVMTags[expectedVMTag02Name], expectedVMTag02Value)
}

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