From 459f2ad31d29414434c9c3521d529573e3264add Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 10:20:19 +0200 Subject: [PATCH 1/8] Update Fabric Workspace Test --- .../workflows/terraform-fabricworkspace.yml | 2 +- modules/fabricworkspace/tests/setup/locals.tf | 3 ++ modules/fabricworkspace/tests/setup/main.tf | 13 +++++ .../fabricworkspace/tests/setup/outputs.tf | 5 ++ .../fabricworkspace/tests/setup/terraform.tf | 10 ++++ .../fabricworkspace/tests/setup/variables.tf | 49 +++++++++++++++++++ modules/fabricworkspace/tests/test.tftest.hcl | 39 ++++++++++++++- 7 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 modules/fabricworkspace/tests/setup/locals.tf create mode 100644 modules/fabricworkspace/tests/setup/main.tf create mode 100644 modules/fabricworkspace/tests/setup/outputs.tf create mode 100644 modules/fabricworkspace/tests/setup/terraform.tf create mode 100644 modules/fabricworkspace/tests/setup/variables.tf diff --git a/.github/workflows/terraform-fabricworkspace.yml b/.github/workflows/terraform-fabricworkspace.yml index fbaecfd..38e8fbd 100644 --- a/.github/workflows/terraform-fabricworkspace.yml +++ b/.github/workflows/terraform-fabricworkspace.yml @@ -25,7 +25,7 @@ jobs: node_version: 20 tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452" subscription_id: "1fdab118-1638-419a-8b12-06c9543714a0" - run_test: false + run_test: true log_level_test: "DEBUG" secrets: CLIENT_ID: ${{ secrets.CLIENT_ID }} diff --git a/modules/fabricworkspace/tests/setup/locals.tf b/modules/fabricworkspace/tests/setup/locals.tf new file mode 100644 index 0000000..8ad5788 --- /dev/null +++ b/modules/fabricworkspace/tests/setup/locals.tf @@ -0,0 +1,3 @@ +locals { + prefix = "${lower(var.prefix)}-${var.environment}" +} diff --git a/modules/fabricworkspace/tests/setup/main.tf b/modules/fabricworkspace/tests/setup/main.tf new file mode 100644 index 0000000..47c74f4 --- /dev/null +++ b/modules/fabricworkspace/tests/setup/main.tf @@ -0,0 +1,13 @@ +module "fabric_capacity" { + source = "github.com/PerfectThymeTech/terraform-azurerm-modules//modules/fabriccapacity?ref=main" + providers = { + azurerm = azurerm + } + + 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" +} diff --git a/modules/fabricworkspace/tests/setup/outputs.tf b/modules/fabricworkspace/tests/setup/outputs.tf new file mode 100644 index 0000000..421204c --- /dev/null +++ b/modules/fabricworkspace/tests/setup/outputs.tf @@ -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 +} diff --git a/modules/fabricworkspace/tests/setup/terraform.tf b/modules/fabricworkspace/tests/setup/terraform.tf new file mode 100644 index 0000000..39f6216 --- /dev/null +++ b/modules/fabricworkspace/tests/setup/terraform.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">=0.13" + + required_providers { + azapi = { + source = "Azure/azapi" + version = ">= 1.14.0" + } + } +} diff --git a/modules/fabricworkspace/tests/setup/variables.tf b/modules/fabricworkspace/tests/setup/variables.tf new file mode 100644 index 0000000..b63123d --- /dev/null +++ b/modules/fabricworkspace/tests/setup/variables.tf @@ -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 diff --git a/modules/fabricworkspace/tests/test.tftest.hcl b/modules/fabricworkspace/tests/test.tftest.hcl index 9b19ada..b91e9d8 100644 --- a/modules/fabricworkspace/tests/test.tftest.hcl +++ b/modules/fabricworkspace/tests/test.tftest.hcl @@ -1,10 +1,47 @@ +variables { + location = "germanywestcentral" + resource_group_name = "tfmodule-test-rg" + tags = { + test = "fabric-workspace" + } +} + +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 = { + 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 From a86b798837977ae5a5c39945cb6e40fc216554e1 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 10:20:53 +0200 Subject: [PATCH 2/8] Update tf version --- .github/workflows/terraform-fabricworkspace.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-fabricworkspace.yml b/.github/workflows/terraform-fabricworkspace.yml index 38e8fbd..3bf6bf9 100644 --- a/.github/workflows/terraform-fabricworkspace.yml +++ b/.github/workflows/terraform-fabricworkspace.yml @@ -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" From 1b2ec0ac08428ffa6942377ff4dfe9ac71ec49d5 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 10:25:34 +0200 Subject: [PATCH 3/8] fix setup for workspace test --- modules/fabricworkspace/tests/setup/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fabricworkspace/tests/setup/main.tf b/modules/fabricworkspace/tests/setup/main.tf index 47c74f4..b7593c9 100644 --- a/modules/fabricworkspace/tests/setup/main.tf +++ b/modules/fabricworkspace/tests/setup/main.tf @@ -1,7 +1,7 @@ module "fabric_capacity" { source = "github.com/PerfectThymeTech/terraform-azurerm-modules//modules/fabriccapacity?ref=main" providers = { - azurerm = azurerm + azapi = azapi } location = var.location From 274057c8d93303d81d9e4646c02fd4510a7b93e8 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 10:30:55 +0200 Subject: [PATCH 4/8] Add azurerm provider --- modules/fabriccapacity/terraform.tf | 4 +++ modules/fabricworkspace/tests/setup/main.tf | 1 + .../fabricworkspace/tests/setup/terraform.tf | 4 +++ modules/fabricworkspace/tests/test.tftest.hcl | 31 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/modules/fabriccapacity/terraform.tf b/modules/fabriccapacity/terraform.tf index 2b1dbcb..2ad406a 100644 --- a/modules/fabriccapacity/terraform.tf +++ b/modules/fabriccapacity/terraform.tf @@ -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" diff --git a/modules/fabricworkspace/tests/setup/main.tf b/modules/fabricworkspace/tests/setup/main.tf index b7593c9..6345886 100644 --- a/modules/fabricworkspace/tests/setup/main.tf +++ b/modules/fabricworkspace/tests/setup/main.tf @@ -1,6 +1,7 @@ module "fabric_capacity" { source = "github.com/PerfectThymeTech/terraform-azurerm-modules//modules/fabriccapacity?ref=main" providers = { + azurerm = azurerm azapi = azapi } diff --git a/modules/fabricworkspace/tests/setup/terraform.tf b/modules/fabricworkspace/tests/setup/terraform.tf index 39f6216..b056ec1 100644 --- a/modules/fabricworkspace/tests/setup/terraform.tf +++ b/modules/fabricworkspace/tests/setup/terraform.tf @@ -2,6 +2,10 @@ terraform { required_version = ">=0.13" required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 4.0.0" + } azapi = { source = "Azure/azapi" version = ">= 1.14.0" diff --git a/modules/fabricworkspace/tests/test.tftest.hcl b/modules/fabricworkspace/tests/test.tftest.hcl index b91e9d8..8c3df14 100644 --- a/modules/fabricworkspace/tests/test.tftest.hcl +++ b/modules/fabricworkspace/tests/test.tftest.hcl @@ -6,6 +6,36 @@ variables { } } +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 @@ -25,6 +55,7 @@ run "setup" { } providers = { + azurerm = azurerm azapi = azapi } From 2e0e17285840f0fb47e9e78514d09a6b661f1b8e Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 10:33:06 +0200 Subject: [PATCH 5/8] Lint --- modules/fabriccapacity/README.md | 2 ++ modules/fabricworkspace/tests/setup/main.tf | 2 +- modules/fabricworkspace/tests/test.tftest.hcl | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/fabriccapacity/README.md b/modules/fabriccapacity/README.md index b70c884..a21321d 100644 --- a/modules/fabriccapacity/README.md +++ b/modules/fabriccapacity/README.md @@ -12,6 +12,8 @@ The following requirements are needed by this module: - [azapi](#requirement\_azapi) (>= 1.14.0) +- [azurerm](#requirement\_azurerm) (>= 4.0.0) + ## Modules No modules. diff --git a/modules/fabricworkspace/tests/setup/main.tf b/modules/fabricworkspace/tests/setup/main.tf index 6345886..9959cae 100644 --- a/modules/fabricworkspace/tests/setup/main.tf +++ b/modules/fabricworkspace/tests/setup/main.tf @@ -2,7 +2,7 @@ module "fabric_capacity" { source = "github.com/PerfectThymeTech/terraform-azurerm-modules//modules/fabriccapacity?ref=main" providers = { azurerm = azurerm - azapi = azapi + azapi = azapi } location = var.location diff --git a/modules/fabricworkspace/tests/test.tftest.hcl b/modules/fabricworkspace/tests/test.tftest.hcl index 8c3df14..40af970 100644 --- a/modules/fabricworkspace/tests/test.tftest.hcl +++ b/modules/fabricworkspace/tests/test.tftest.hcl @@ -56,7 +56,7 @@ run "setup" { providers = { azurerm = azurerm - azapi = azapi + azapi = azapi } variables { From 1fa4d29bab9f3951bf76bc763cc291b280539691 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 11:06:03 +0200 Subject: [PATCH 6/8] Fetch fabric capacity id --- modules/fabricworkspace/README.md | 2 ++ modules/fabricworkspace/data.tf | 11 +++++++++++ modules/fabricworkspace/locals.tf | 7 +++++++ modules/fabricworkspace/main.tf | 2 +- modules/fabricworkspace/terraform.tf | 4 ++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 modules/fabricworkspace/locals.tf diff --git a/modules/fabricworkspace/README.md b/modules/fabricworkspace/README.md index 19ae5be..3fc4202 100644 --- a/modules/fabricworkspace/README.md +++ b/modules/fabricworkspace/README.md @@ -10,6 +10,8 @@ The following requirements are needed by this module: - [terraform](#requirement\_terraform) (~> 1.8) +- [azapi](#requirement\_azapi) (>= 1.14.0) + - [fabric](#requirement\_fabric) (0.1.0-beta.2) ## Modules diff --git a/modules/fabricworkspace/data.tf b/modules/fabricworkspace/data.tf index 0e14b77..9b0dd44 100644 --- a/modules/fabricworkspace/data.tf +++ b/modules/fabricworkspace/data.tf @@ -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 diff --git a/modules/fabricworkspace/locals.tf b/modules/fabricworkspace/locals.tf new file mode 100644 index 0000000..5f36173 --- /dev/null +++ b/modules/fabricworkspace/locals.tf @@ -0,0 +1,7 @@ +locals { + fabric_capity_ids = [ + for value in data.fabric_capacities.capacities.values : + 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 +} diff --git a/modules/fabricworkspace/main.tf b/modules/fabricworkspace/main.tf index a75c371..69a9950 100644 --- a/modules/fabricworkspace/main.tf +++ b/modules/fabricworkspace/main.tf @@ -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 diff --git a/modules/fabricworkspace/terraform.tf b/modules/fabricworkspace/terraform.tf index a8a6c8a..6183560 100644 --- a/modules/fabricworkspace/terraform.tf +++ b/modules/fabricworkspace/terraform.tf @@ -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" From cea2bf4e84560b5fc300da1e1b1176fabd7bae9c Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 11:16:18 +0200 Subject: [PATCH 7/8] Fix minor bug --- modules/fabricworkspace/locals.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fabricworkspace/locals.tf b/modules/fabricworkspace/locals.tf index 5f36173..6feb0b4 100644 --- a/modules/fabricworkspace/locals.tf +++ b/modules/fabricworkspace/locals.tf @@ -1,7 +1,7 @@ locals { fabric_capity_ids = [ for value in data.fabric_capacities.capacities.values : - 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) + 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 } From 6288616a7c968425cc07d34ea6376d139aa4cd0f Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Mon, 30 Sep 2024 14:57:44 +0200 Subject: [PATCH 8/8] Update frbaic workspace workflow --- .github/workflows/terraform-fabricworkspace.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-fabricworkspace.yml b/.github/workflows/terraform-fabricworkspace.yml index 3bf6bf9..bbf2ba1 100644 --- a/.github/workflows/terraform-fabricworkspace.yml +++ b/.github/workflows/terraform-fabricworkspace.yml @@ -25,7 +25,7 @@ jobs: node_version: 20 tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452" subscription_id: "1fdab118-1638-419a-8b12-06c9543714a0" - run_test: true + run_test: false log_level_test: "DEBUG" secrets: CLIENT_ID: ${{ secrets.CLIENT_ID }}