Terratest assigning nested attributes to a variable

So I am picking up my first Go/Terratest changes and it seems pretty straight forward to capture attributes from the Terraform Plan and assign them to variables.

For example:

# module.adls.azurerm_resource_group.rg will be created
  + resource "azurerm_resource_group" "rg" {
  + id       = (known after apply)
  + location = "uksouth"
  + name     = "a-dummy-value"
  + tags     = {
      + "Application"      = "Foo"
      + "Business-Project" = "Bar"
      + "Environment"      = "TEST"
      + "Function"         = "Analytics"
      + "Name"             = "a-dummy-value"
    }
}

Then in the terratest go code assign attributes to variables like so:

resourceGroup := plan.ResourcePlannedValuesMap["module.adls.azurerm_resource_group.rg"]
resourceGroupTags := resourceGroup.AttributeValues["tags"].(map[string]interface{})

Then to actually use the new variables with attributes from the plan assigned:

assert.Equal(t, expectedApplication, resourceGroupTags["Application"], "Application tag should match Application")

The problem I have is with a new attribute that has been added (I won’t post the whole module output):

+ tags                               = {
      + "Application"      = "Foo"
      + "Business-Project" = "bar"
      + "Environment"      = "TEST"
      + "Function"         = "Analytics"
      + "Name"             = "a-dummy-value"
    }

  + queue_properties {
      + logging {
          + delete                = true
          + read                  = true
          + retention_policy_days = 90
          + version               = "2"
          + write                 = true
        }
    }

So I want to be able to assign delete, read, etc to variables and assert equals on them but I am not sure how to get at them (if that makes sense).

As a first thought I considered this:

resourceGroupQueue := resourceGroup.AttributeValues["queue_properties"].(map[string]interface{})
resourceGroupLogging := resourceGroupQueue.AttributeValues["logging"].(map[string]interface{})

I would then assert like so:

assert.Equal(t, "true", resourceGroupLogging["delete"], "delete should be true")

That fails (but not where I expected it to):

resourceGroupQueue.AttributeValues undefined (type map[string]interface{} has no field or method AttributeValues)

I am thinking that tag = { } is different to queue_properties { } but not sure what variable type that makes the queue_properties.

Any idea how to achieve this?

I haven’t used terratest myself, but maybe because queue_properties is a terraform block, and tags is a map?

I would look at their docs, and maybe look for some examples online, maybe something like
terratest/test/terraform_aws_example_test.go at main · gruntwork-io/terratest · GitHub?

Looks like maybe map[string]string? From a quick look at the terratest code, doesn’t look like they have a function like that for Azure resource groups, but hopefully this helps.

I couldn’t get that working the way that I thought it should but it seemed easier to assign the values to the Plan Output.

outputs.tf

output "logging_delete" {
  value       = azurerm_storage_account.storage_account.queue_properties[0].logging[0].delete
  description = "Storage logging options enabled - delete"
}

Also in examples/simple/output.tf

output "logging_delete" {
  value       = module.adls.logging_delete
  description = "Storage logging options enabled - delete"
}

Then I was able to write some very simple asserts that use the outputs created.

storageAccountDelete := terraform.Output(t, terraformPlanOptions, "logging_delete")

assert.Equal(t, "true", storageAccountDelete, "Delete logging enabled should be true")