Skip to content

Commit

Permalink
Merge pull request #60 from PerfectThymeTech/marvinbuss/fabcric_works…
Browse files Browse the repository at this point in the history
…pace_test

Add Fabric Workspace Test with Capacity
  • Loading branch information
marvinbuss authored Sep 30, 2024
2 parents 44d6d7d + 6288616 commit 8c9eccd
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/terraform-fabricworkspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
environment: "dev"
config: "fabricworkspace"
terraform_version: "1.9.5"
terraform_version: "1.9.6"
node_version: 20
tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452"
subscription_id: "1fdab118-1638-419a-8b12-06c9543714a0"
Expand Down
2 changes: 2 additions & 0 deletions modules/fabriccapacity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The following requirements are needed by this module:

- <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) (>= 1.14.0)

- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (>= 4.0.0)

## Modules

No modules.
Expand Down
4 changes: 4 additions & 0 deletions modules/fabriccapacity/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ terraform {
required_version = ">=0.12"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 4.0.0"
}
azapi = {
source = "Azure/azapi"
version = ">= 1.14.0"
Expand Down
2 changes: 2 additions & 0 deletions modules/fabricworkspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The following requirements are needed by this module:

- <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) (~> 1.8)

- <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) (>= 1.14.0)

- <a name="requirement_fabric"></a> [fabric](#requirement\_fabric) (0.1.0-beta.2)

## Modules
Expand Down
11 changes: 11 additions & 0 deletions modules/fabricworkspace/data.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
data "azapi_resource" "fabric_capacity" {
count = var.workspace_capacity_id == null ? 0 : 1

type = "Microsoft.Fabric/capacities@2023-11-01"
resource_id = var.workspace_capacity_id

response_export_values = ["*"]
}

data "fabric_capacities" "capacities" {}

# Not enabled as other workspaces not in the list would be removed from the domain
# data "fabric_domain" "domain" {
# count = var.workspace_domain_id == null ? 0 : 1
Expand Down
7 changes: 7 additions & 0 deletions modules/fabricworkspace/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
locals {
fabric_capity_ids = [
for value in data.fabric_capacities.capacities.values :
value.id if value.display_name == one(data.azapi_resource.fabric_capacity[*].name) && value.region == one(data.azapi_resource.fabric_capacity[*].location) && value.sku == one(data.azapi_resource.fabric_capacity[*].sku)
]
fabric_capity_id = length(local.fabric_capity_ids) > 0 ? local.fabric_capity_ids[0] : null
}
2 changes: 1 addition & 1 deletion modules/fabricworkspace/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "fabric_workspace" "workspace" {
display_name = var.workspace_display_name
description = var.workspace_description
capacity_id = var.workspace_capacity_id == null ? null : var.workspace_capacity_id
capacity_id = local.fabric_capity_id
identity = var.workspace_identity_enabled ? {
type = "SystemAssigned"
} : null
Expand Down
4 changes: 4 additions & 0 deletions modules/fabricworkspace/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ terraform {
required_version = "~> 1.8"

required_providers {
azapi = {
source = "Azure/azapi"
version = ">= 1.14.0"
}
fabric = {
source = "microsoft/fabric"
version = "0.1.0-beta.2"
Expand Down
3 changes: 3 additions & 0 deletions modules/fabricworkspace/tests/setup/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
prefix = "${lower(var.prefix)}-${var.environment}"
}
14 changes: 14 additions & 0 deletions modules/fabricworkspace/tests/setup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module "fabric_capacity" {
source = "github.com/PerfectThymeTech/terraform-azurerm-modules//modules/fabriccapacity?ref=main"
providers = {
azurerm = azurerm
azapi = azapi
}

location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
fabric_capacity_name = replace("${local.prefix}-cpcty001", "-", "")
fabric_capacity_admin_emails = []
fabric_capacity_sku = "F2"
}
5 changes: 5 additions & 0 deletions modules/fabricworkspace/tests/setup/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "fabric_capacity_id" {
description = "Specifies the id of the fabric capacity."
value = module.fabric_capacity.fabric_capacity_id
sensitive = false
}
14 changes: 14 additions & 0 deletions modules/fabricworkspace/tests/setup/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">=0.13"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 4.0.0"
}
azapi = {
source = "Azure/azapi"
version = ">= 1.14.0"
}
}
}
49 changes: 49 additions & 0 deletions modules/fabricworkspace/tests/setup/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# General variables
variable "location" {
description = "Specifies the location of all resources."
type = string
sensitive = false
}

variable "environment" {
description = "Specifies the environment of the deployment."
type = string
sensitive = false
default = "dev"
validation {
condition = contains(["int", "dev", "tst", "qa", "prd"], var.environment)
error_message = "Please use an allowed value: \"int\", \"dev\", \"tst\", \"qa\" or \"prd\"."
}
}

variable "prefix" {
description = "Specifies the prefix for all resources created in this deployment."
type = string
sensitive = false
validation {
condition = length(var.prefix) >= 2 && length(var.prefix) <= 10
error_message = "Please specify a prefix with more than two and less than 10 characters."
}
}

variable "resource_group_name" {
description = "Specifies the resource group name in which all resources will get deployed."
type = string
sensitive = false
nullable = false
validation {
condition = length(var.resource_group_name) >= 2
error_message = "Please specify a valid resource group name."
}
}

variable "tags" {
description = "Specifies a key value map of tags to set on every taggable resources."
type = map(string)
sensitive = false
default = {}
}

# Service variables

# Network variables
70 changes: 69 additions & 1 deletion modules/fabricworkspace/tests/test.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,78 @@
variables {
location = "germanywestcentral"
resource_group_name = "tfmodule-test-rg"
tags = {
test = "fabric-workspace"
}
}

provider "azurerm" {
disable_correlation_request_id = false
environment = "public"
resource_provider_registrations = "none"
storage_use_azuread = true
use_oidc = true

features {
application_insights {
disable_generated_rule = false
}
machine_learning {
purge_soft_deleted_workspace_on_destroy = true
}
key_vault {
purge_soft_delete_on_destroy = false
purge_soft_deleted_certificates_on_destroy = false
purge_soft_deleted_keys_on_destroy = false
purge_soft_deleted_secrets_on_destroy = false
recover_soft_deleted_key_vaults = true
recover_soft_deleted_certificates = true
recover_soft_deleted_keys = true
recover_soft_deleted_secrets = true
}
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}

provider "azapi" {
default_location = var.location
default_tags = var.tags
disable_correlation_request_id = false
environment = "public"
skip_provider_registration = false
use_oidc = true
}

provider "fabric" {}

run "setup" {
command = apply

module {
source = "./tests/setup"
}

providers = {
azurerm = azurerm
azapi = azapi
}

variables {
location = var.location
environment = "int"
prefix = "tfmdlfbrc"
resource_group_name = var.resource_group_name
tags = var.tags
}
}

run "create_fabric_workspace" {
command = apply

variables {
workspace_capacity_id = null
workspace_capacity_id = run.setup.fabric_capacity_id
workspace_display_name = "MyTestWs"
workspace_description = "My Test Workspace"
workspace_identity_enabled = false
Expand Down

0 comments on commit 8c9eccd

Please sign in to comment.