Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions modules/azure/storage-account/e2e/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
variable "test_context" {
type = object({
hub_git_ref = string
workspace = string
name_suffix = string

fixtures = object({
azure = object({
subscription_uuid = string
entra_tenant_id = string
})
})
})

nullable = false
}

locals {
# Derive the scope from the subscription ID — role definitions are scoped to the subscription.
azure_scope = "/subscriptions/${var.test_context.fixtures.azure.subscription_uuid}"

# storage_account_name must match ^[a-z0-9]{3,19}$ — building block appends a 5-char random suffix.
# name_suffix is "YYYYMMDDhhmmss" (14 digits), so "st" + first 12 digits = 14 chars total.
storage_account_name_prefix = "st${substr(var.test_context.name_suffix, 0, 12)}"
}

module "storage_account" {
source = "../"

meshstack = {
owning_workspace_identifier = var.test_context.workspace
tags = {
BBEnvironment = ["dev"]
}
}

hub = {
git_ref = var.test_context.hub_git_ref
bbd_draft = true
}

azure_tenant_id = var.test_context.fixtures.azure.entra_tenant_id
azure_subscription_id = var.test_context.fixtures.azure.subscription_uuid
azure_scope = local.azure_scope

# Unique backplane name per test run so role definitions don't clash across concurrent/retried runs.
backplane_name = "hub-e2e-stg-${var.test_context.name_suffix}"
}

resource "meshstack_building_block_v2" "this" {
# depend on the entire backplane to force correct resource ordering at the module boundary,not just individual resources in the backplane
depends_on = [module.storage_account]

wait_for_completion = true

spec = {
building_block_definition_version_ref = module.storage_account.building_block_definition.version_ref

display_name = "smoke-test-storage-account-${var.test_context.name_suffix}"
target_ref = {
kind = "meshWorkspace"
identifier = var.test_context.workspace
}

inputs = {
storage_account_name = { value_string = local.storage_account_name_prefix }
}
}
}
10 changes: 10 additions & 0 deletions modules/azure/storage-account/e2e/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
provider "azurerm" {
subscription_id = var.test_context.fixtures.azure.subscription_uuid
tenant_id = var.test_context.fixtures.azure.entra_tenant_id

features {}
}

provider "azuread" {
tenant_id = var.test_context.fixtures.azure.entra_tenant_id
}
15 changes: 15 additions & 0 deletions modules/azure/storage-account/e2e/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_version = ">= 1.0"

required_providers {
meshstack = {
source = "meshcloud/meshstack"
}
azurerm = {
source = "hashicorp/azurerm"
}
azuread = {
source = "hashicorp/azuread"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
run "azure_storage_account_hub" {
assert {
condition = meshstack_building_block_v2.this.status.status == "SUCCEEDED"
error_message = "azure/storage-account hub building block expected SUCCEEDED, got ${meshstack_building_block_v2.this.status.status}"
}

assert {
condition = can(regex(
"^/subscriptions/[^/]+/resourceGroups/[^/]+/providers/Microsoft\\.Storage/storageAccounts/",
meshstack_building_block_v2.this.status.outputs["storage_account_id"].value_string
))
error_message = "expected storage_account_id to be a valid Azure Storage Account resource ID, got ${meshstack_building_block_v2.this.status.outputs["storage_account_id"].value_string}"
}

assert {
condition = startswith(meshstack_building_block_v2.this.status.outputs["storage_account_name"].value_string, "st")
error_message = "expected storage_account_name to start with 'st', got ${meshstack_building_block_v2.this.status.outputs["storage_account_name"].value_string}"
}

assert {
condition = startswith(meshstack_building_block_v2.this.status.outputs["storage_account_resource_group"].value_string, "rg-st")
error_message = "expected storage_account_resource_group to start with 'rg-st', got ${meshstack_building_block_v2.this.status.outputs["storage_account_resource_group"].value_string}"
}
}