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?