I have a Terraform test which works locally but fails when I run it on a Azure DevOps Linux build server. The Terraform I am testing is adding a Azurerm Monitor Diagnostic Setting on a Key Vault like the one in the link. This is a module I am updating to add the diagnostic settings, which had worked with a basic terraform test.
The terraform test is
The log analytics workspace has already been created.
mock_provider "azurerm" {
mock_data "azurerm_log_analytics_workspace" {
defaults = {
name = "log-lz-storage-log-all-eus-001"
resource_group_name = "rg-lz-storage-log-all-eus"
}
}
override_data {
target = data.azurerm_log_analytics_workspace.log_workspace
values = {
id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-lz-storage-log-all-eus/providers/Microsoft.OperationalInsights/workspaces/log-storage-all-eus-001"
}
}
}
variables {
name = "test"
location = "cus"
environment = "tst"
resource_group_name = "rg-f5-test-01"
public_network_access_enabled = true
tenant_id = "12345678-1234-1234-1234-123456789abc"
}
## Test valid variables
run "key_vault_basic_asserts" {
command = plan
assert {
condition = try(azurerm_key_vault.kv.name == "kv-test-tst-cus-1", false)
error_message = "Key Vault name does not match expected format kv-test-tst-cus-1"
}
}
Even without the asserts it still fails as shown below.
Initializing the backend...
Initializing modules...
- test.tests.key-vault.setup_tests in tests/setup
Initializing provider plugins...
- Finding hashicorp/azurerm versions matching ">= 3.101.0"...
- Finding latest version of hashicorp/http...
- Finding hashicorp/random versions matching ">= 3.5.1"...
- Installing hashicorp/azurerm v4.46.0...
- Installed hashicorp/azurerm v4.46.0 (signed by HashiCorp)
- Installing hashicorp/http v3.5.0...
- Installed hashicorp/http v3.5.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
tests/key-vault.tftest.hcl... in progress
run "key_vault_basic_asserts"... fail
╷
##[error]PowerShell exited with code '1'.