Skip to content

Commit

Permalink
Merge pull request #62 from PerfectThymeTech/marvinbuss/fabric-wspce
Browse files Browse the repository at this point in the history
Fabric Workspace Testing
  • Loading branch information
marvinbuss authored Oct 2, 2024
2 parents 4b64ab4 + feed672 commit 6ae158e
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 67 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/_terraformTestTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
required: true
type: string
description: "Specifies the environment of the deployment."
runner_label:
required: false
type: string
description: "Specifies the runner label."
default: "self-hosted"
config:
required: true
type: string
Expand Down Expand Up @@ -101,7 +106,7 @@ jobs:
test:
name: Terraform Test
runs-on: [self-hosted]
runs-on: ${{ inputs.runner_label }}
continue-on-error: false
environment: ${{ inputs.environment }}
if: inputs.run_test
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/terraform-fabricworkspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ jobs:
name: "Dev"
with:
environment: "dev"
runner_label: "ubuntu-latest"
config: "fabricworkspace"
terraform_version: "1.9.6"
node_version: 20
tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452"
subscription_id: "1fdab118-1638-419a-8b12-06c9543714a0"
run_test: false
log_level_test: "DEBUG"
secrets:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
2 changes: 1 addition & 1 deletion modules/fabriccapacity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "azapi_resource" "fabric_capacity" {
}

response_export_values = []
schema_validation_enabled = false # Can be reverted once this is closed: https://github.com/Azure/terraform-provider-azapi/issues/524
schema_validation_enabled = true
locks = []
ignore_casing = false
ignore_missing_property = true
Expand Down
13 changes: 4 additions & 9 deletions modules/fabricworkspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The following requirements are needed by this module:

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

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

## Modules

Expand All @@ -36,9 +36,9 @@ Type: `string`

The following input variables are optional (have default values):

### <a name="input_workspace_capacity_id"></a> [workspace\_capacity\_id](#input\_workspace\_capacity\_id)
### <a name="input_workspace_capacity_name"></a> [workspace\_capacity\_name](#input\_workspace\_capacity\_name)

Description: Specifies the resource id of a fabric capacity hosted in Azure to assign to the fabric workspace.
Description: Specifies the name of a fabric capacity hosted in Azure to assign to the fabric workspace.

Type: `string`

Expand All @@ -54,7 +54,7 @@ Default: `""`

### <a name="input_workspace_git"></a> [workspace\_git](#input\_workspace\_git)

Description: Specifies git config of the fabric workspace.
Description: Specifies git config of the fabric workspace. Not supported when deploying with service principal.

Type:

Expand Down Expand Up @@ -106,16 +106,11 @@ object({
automatic_log = optional(object({
enabled = optional(bool, true)
}), {})
environment = optional(object({
default_environment_name = optional(string, "")
runtime_version = optional(string, "1.3")
}), {})
high_concurrency = optional(object({
notebook_interactive_run_enabled = optional(bool, true)
}), {})
pool = optional(object({
customize_compute_enabled = optional(bool, true)
default_pool_name = optional(string, "defaultpool")
}), {})
})
```
Expand Down
11 changes: 2 additions & 9 deletions modules/fabricworkspace/data.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
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_capacity" "capacity" {
display_name = var.workspace_capacity_name
}

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: 0 additions & 7 deletions modules/fabricworkspace/locals.tf

This file was deleted.

20 changes: 10 additions & 10 deletions 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 = local.fabric_capity_id
capacity_id = data.fabric_capacity.capacity.id
identity = var.workspace_identity_enabled ? {
type = "SystemAssigned"
} : null
Expand All @@ -18,26 +18,26 @@ resource "fabric_workspace" "workspace" {
# }

resource "fabric_spark_workspace_settings" "workspace_settings" {
count = var.workspace_capacity_id == null ? 0 : 1
count = var.workspace_capacity_name == null ? 0 : 1

workspace_id = fabric_workspace.workspace.id

automatic_log = {
enabled = var.workspace_settings.automatic_log.enabled
}
environment = {
name = var.workspace_settings.environment.default_environment_name
runtime_version = var.workspace_settings.environment.runtime_version
}
# environment = {
# name = var.workspace_settings.environment.default_environment_name
# runtime_version = var.workspace_settings.environment.runtime_version
# }
high_concurrency = {
notebook_interactive_run_enabled = var.workspace_settings.high_concurrency.notebook_interactive_run_enabled
}
pool = {
customize_compute_enabled = var.workspace_settings.pool.customize_compute_enabled
default_pool = {
name = var.workspace_settings.pool.default_pool_name
type = var.workspace_capacity_id == null ? "Workspace" : "Capacity"
}
# default_pool = {
# name = var.workspace_settings.pool.default_pool_name
# type = var.workspace_capacity_name == null ? "Workspace" : "Capacity"
# }
# starter_pool = {
# max_executors = 3
# max_node_count = 1
Expand Down
2 changes: 1 addition & 1 deletion modules/fabricworkspace/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
}
fabric = {
source = "microsoft/fabric"
version = "0.1.0-beta.2"
version = "0.1.0-beta.3"
}
}
}
6 changes: 6 additions & 0 deletions modules/fabricworkspace/tests/setup/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ output "fabric_capacity_id" {
value = module.fabric_capacity.fabric_capacity_id
sensitive = false
}

output "fabric_capacity_name" {
description = "Specifies the name of the fabric capacity."
value = module.fabric_capacity.fabric_capacity_name
sensitive = false
}
30 changes: 18 additions & 12 deletions modules/fabricworkspace/tests/test.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,38 @@ run "create_fabric_workspace" {
command = apply

variables {
workspace_capacity_id = run.setup.fabric_capacity_id
workspace_capacity_name = run.setup.fabric_capacity_name
workspace_display_name = "MyTestWs"
workspace_description = "My Test Workspace"
workspace_identity_enabled = false
workspace_settings = {
automatic_log = {
enabled = true
}
environment = {
default_environment_name = ""
runtime_version = "1.3"
}
# environment = {
# default_environment_name = ""
# runtime_version = "1.3"
# }
high_concurrency = {
notebook_interactive_run_enabled = true
}
pool = {
customize_compute_enabled = true
default_pool_name = "defaultpool"
# default_pool_name = "starterPool"
}
}
workspace_git = null
workspace_role_assignments = {
my_sp = {
principal_id = "973df2ad-4e5e-4e8b-9df6-17f61e9efd55"
principal_type = "ServicePrincipal"
role = "Viewer"
}
}
workspace_git = null
workspace_role_assignments = {}
}

assert {
condition = fabric_workspace.workspace.display_name == "MyTestWs"
error_message = "Failed to deploy."
}
# assert {
# condition = fabric_workspace.workspace.display_name == "MyTestWs"
# error_message = "Failed to deploy."
# }
}
65 changes: 50 additions & 15 deletions modules/fabricworkspace/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# General variables

# Fabric workspace variables
variable "workspace_capacity_id" {
description = "Specifies the resource id of a fabric capacity hosted in Azure to assign to the fabric workspace."
variable "workspace_capacity_name" {
description = "Specifies the name of a fabric capacity hosted in Azure to assign to the fabric workspace."
type = string
sensitive = false
nullable = true
default = null
validation {
condition = var.workspace_capacity_id == null || can(length(split("/", var.workspace_capacity_id)) == 9)
error_message = "Please specify a valid capacity id."
condition = length(var.workspace_capacity_name) >= 2 && length(regexall("[^[:alnum:]]", var.workspace_capacity_name)) <= 0
error_message = "Please specify a valid name."
}
}

Expand Down Expand Up @@ -52,7 +52,7 @@ variable "workspace_identity_enabled" {
nullable = false
default = true
validation {
condition = !var.workspace_identity_enabled || var.workspace_identity_enabled && var.workspace_capacity_id != null
condition = !var.workspace_identity_enabled || var.workspace_identity_enabled && var.workspace_capacity_name != null
error_message = "Please specify a capacity id to enable the workspace identity."
}
}
Expand All @@ -63,29 +63,64 @@ variable "workspace_settings" {
automatic_log = optional(object({
enabled = optional(bool, true)
}), {})
environment = optional(object({
default_environment_name = optional(string, "")
runtime_version = optional(string, "1.3")
}), {})
high_concurrency = optional(object({
notebook_interactive_run_enabled = optional(bool, true)
}), {})
pool = optional(object({
customize_compute_enabled = optional(bool, true)
default_pool_name = optional(string, "defaultpool")
}), {})
})
sensitive = false
nullable = false
default = {}
validation {
condition = contains(["1.2", "1.3"], var.workspace_settings.environment.runtime_version)
error_message = "Please specify a valid runtime version. Version 1.1 should no longer be used."
}
}

# variable "workspace_settings" {
# description = "Specifies settings of the fabric workspace."
# type = object({
# automatic_log = optional(object({
# enabled = optional(bool, true)
# }), {})
# environment = optional(object({
# default_environment_enabled = optional(bool, false)
# runtime_version = optional(string, "1.3")
# default_environment_config = optional(object({
# publication_status = optional(string, "Published")
# driver_cores = optional(number, 4)
# driver_memory = optional(string, "28g")
# executor_cores = optional(number, 4)
# executor_memory = optional(string, "28g")
# dynamic_executor_allocation = optional(object({
# enabled = optional(bool, false)
# min_executors = optional(number, null)
# max_executors = optional(number, null)
# }), {})
# }), {})
# }), {})
# high_concurrency = optional(object({
# notebook_interactive_run_enabled = optional(bool, true)
# }), {})
# pool = optional(object({
# customize_compute_enabled = optional(bool, true)
# default_pool_enabled = optional(bool, false)
# default_pool_config = optional(object({
# node_family = optional(string, "MemoryOptimized")
# node_size = optional(string, "Small")

# }), {})
# }), {})
# })
# sensitive = false
# nullable = false
# default = {}
# validation {
# condition = contains(["1.2", "1.3"], var.workspace_settings.environment.runtime_version)
# error_message = "Please specify a valid runtime version. Version 1.1 should no longer be used."
# }
# }

variable "workspace_git" {
description = "Specifies git config of the fabric workspace."
description = "Specifies git config of the fabric workspace. Not supported when deploying with service principal."
type = object({
git_provider_type = optional(string, "AzureDevOps")
organization_name = string
Expand Down

0 comments on commit 6ae158e

Please sign in to comment.