diff --git a/.github/workflows/_terraformTestTemplate.yml b/.github/workflows/_terraformTestTemplate.yml index ac9b59d..a4b58ff 100644 --- a/.github/workflows/_terraformTestTemplate.yml +++ b/.github/workflows/_terraformTestTemplate.yml @@ -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 @@ -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 diff --git a/.github/workflows/terraform-fabricworkspace.yml b/.github/workflows/terraform-fabricworkspace.yml index bbf2ba1..0b3775f 100644 --- a/.github/workflows/terraform-fabricworkspace.yml +++ b/.github/workflows/terraform-fabricworkspace.yml @@ -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 }} diff --git a/modules/fabriccapacity/main.tf b/modules/fabriccapacity/main.tf index 8f00ef1..3b44872 100644 --- a/modules/fabriccapacity/main.tf +++ b/modules/fabriccapacity/main.tf @@ -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 diff --git a/modules/fabricworkspace/README.md b/modules/fabricworkspace/README.md index 48e7e1c..5876577 100644 --- a/modules/fabricworkspace/README.md +++ b/modules/fabricworkspace/README.md @@ -14,7 +14,7 @@ The following requirements are needed by this module: - [azapi](#requirement\_azapi) (>= 1.14.0) -- [fabric](#requirement\_fabric) (0.1.0-beta.2) +- [fabric](#requirement\_fabric) (0.1.0-beta.3) ## Modules @@ -36,9 +36,9 @@ Type: `string` The following input variables are optional (have default values): -### [workspace\_capacity\_id](#input\_workspace\_capacity\_id) +### [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` @@ -54,7 +54,7 @@ Default: `""` ### [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: @@ -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") }), {}) }) ``` diff --git a/modules/fabricworkspace/data.tf b/modules/fabricworkspace/data.tf index 9b0dd44..591fc0d 100644 --- a/modules/fabricworkspace/data.tf +++ b/modules/fabricworkspace/data.tf @@ -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 diff --git a/modules/fabricworkspace/locals.tf b/modules/fabricworkspace/locals.tf deleted file mode 100644 index 6feb0b4..0000000 --- a/modules/fabricworkspace/locals.tf +++ /dev/null @@ -1,7 +0,0 @@ -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 -} diff --git a/modules/fabricworkspace/main.tf b/modules/fabricworkspace/main.tf index 69a9950..73495f9 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 = local.fabric_capity_id + capacity_id = data.fabric_capacity.capacity.id identity = var.workspace_identity_enabled ? { type = "SystemAssigned" } : null @@ -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 diff --git a/modules/fabricworkspace/terraform.tf b/modules/fabricworkspace/terraform.tf index 6183560..f44254e 100644 --- a/modules/fabricworkspace/terraform.tf +++ b/modules/fabricworkspace/terraform.tf @@ -8,7 +8,7 @@ terraform { } fabric = { source = "microsoft/fabric" - version = "0.1.0-beta.2" + version = "0.1.0-beta.3" } } } diff --git a/modules/fabricworkspace/tests/setup/outputs.tf b/modules/fabricworkspace/tests/setup/outputs.tf index 421204c..06e8852 100644 --- a/modules/fabricworkspace/tests/setup/outputs.tf +++ b/modules/fabricworkspace/tests/setup/outputs.tf @@ -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 +} diff --git a/modules/fabricworkspace/tests/test.tftest.hcl b/modules/fabricworkspace/tests/test.tftest.hcl index 40af970..cde132b 100644 --- a/modules/fabricworkspace/tests/test.tftest.hcl +++ b/modules/fabricworkspace/tests/test.tftest.hcl @@ -72,7 +72,7 @@ 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 @@ -80,24 +80,30 @@ run "create_fabric_workspace" { 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." + # } } diff --git a/modules/fabricworkspace/variables.tf b/modules/fabricworkspace/variables.tf index 335af14..9e9b130 100644 --- a/modules/fabricworkspace/variables.tf +++ b/modules/fabricworkspace/variables.tf @@ -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." } } @@ -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." } } @@ -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