diff --git a/terraform/fabric/fabric-capacity/main.tf b/terraform/fabric/fabric-capacity/main.tf index 35a0b8e7..400bb182 100644 --- a/terraform/fabric/fabric-capacity/main.tf +++ b/terraform/fabric/fabric-capacity/main.tf @@ -1,22 +1,24 @@ -resource "azapi_resource" "fabric_capacity" { - type = "Microsoft.Fabric/capacities@2022-07-01-preview" - name = "fab${var.basename}" - parent_id = var.resource_group_id - location = var.location - schema_validation_enabled = false - - body = jsonencode({ - properties = { - administration = { - members = [ - var.admin_email - ] - } - } - sku = { - name = var.sku, - tier = "Fabric" - } - }) - tags = var.tags +resource "azapi_resource" "fab_capacity" { + type = "Microsoft.Fabric/capacities@2022-07-01-preview" + name = "fab${var.basename}" + parent_id = var.resource_group_id + location = var.location + schema_validation_enabled = false + + body = jsonencode({ + properties = { + administration = { + members = [ + var.admin_email + ] + } + } + sku = { + name = var.sku, + tier = "Fabric" + } + }) + tags = var.tags + + count = var.module_enabled ? 1 : 0 } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/outputs.tf b/terraform/fabric/fabric-capacity/outputs.tf index e69de29b..52e6d4dd 100644 --- a/terraform/fabric/fabric-capacity/outputs.tf +++ b/terraform/fabric/fabric-capacity/outputs.tf @@ -0,0 +1,7 @@ +output "id" { + value = ( + length(azapi_resource.fab_capacity) > 0 ? + azapi_resource.fab_capacity[0].id : "" + ) + description = "Resource identifier of the instance of Fabric Capacity." +} \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/providers.tf b/terraform/fabric/fabric-capacity/providers.tf index ee853a09..075d6f44 100644 --- a/terraform/fabric/fabric-capacity/providers.tf +++ b/terraform/fabric/fabric-capacity/providers.tf @@ -1,7 +1,7 @@ -terraform { - required_providers { - azapi = { - source = "Azure/azapi" - } - } +terraform { + required_providers { + azapi = { + source = "Azure/azapi" + } + } } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/test/fabric_capacity.tf b/terraform/fabric/fabric-capacity/test/fabric_capacity.tf index b632709a..99b2ed65 100644 --- a/terraform/fabric/fabric-capacity/test/fabric_capacity.tf +++ b/terraform/fabric/fabric-capacity/test/fabric_capacity.tf @@ -1,18 +1,18 @@ -module "fabric_capacity" { - source = "../" - basename = random_string.postfix.result - resource_group_id = module.local_rg.id - location = var.location - sku = var.sku - admin_email = var.admin_email - tags = {} -} - -# Modules dependencies - -module "local_rg" { - source = "../../../resource-group" - basename = random_string.postfix.result - location = var.location - tags = local.tags +module "fabric_capacity" { + source = "../" + basename = random_string.postfix.result + resource_group_id = module.local_rg.id + location = var.location + sku = var.sku + admin_email = var.admin_email + tags = {} +} + +# Modules dependencies + +module "local_rg" { + source = "../../../resource-group" + basename = random_string.postfix.result + location = var.location + tags = local.tags } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/test/locals.tf b/terraform/fabric/fabric-capacity/test/locals.tf index cf58c6d3..a0d65226 100644 --- a/terraform/fabric/fabric-capacity/test/locals.tf +++ b/terraform/fabric/fabric-capacity/test/locals.tf @@ -1,7 +1,7 @@ -locals { - tags = { - Project = "Azure/azure-data-labs-modules" - Module = "fabric-capacity" - Toolkit = "Terraform" - } +locals { + tags = { + Project = "Azure/azure-data-labs-modules" + Module = "fabric-capacity" + Toolkit = "Terraform" + } } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/test/outputs.tf b/terraform/fabric/fabric-capacity/test/outputs.tf index e69de29b..c275d58d 100644 --- a/terraform/fabric/fabric-capacity/test/outputs.tf +++ b/terraform/fabric/fabric-capacity/test/outputs.tf @@ -0,0 +1,3 @@ +output "id" { + value = module.fabric_capacity.id +} \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/test/providers.tf b/terraform/fabric/fabric-capacity/test/providers.tf index 3ad37f38..77cd034f 100644 --- a/terraform/fabric/fabric-capacity/test/providers.tf +++ b/terraform/fabric/fabric-capacity/test/providers.tf @@ -1,25 +1,25 @@ -terraform { - backend "azurerm" { - resource_group_name = "rg-adl-terraform-state" - storage_account_name = "stadlterraformstate" - container_name = "default" - key = "fabriccapacity.terraform.tfstate" - } - - required_providers { - azurerm = { - source = "hashicorp/azurerm" - version = "= 3.53.0" - } - azapi = { - source = "azure/azapi" - } - } -} - -provider "azurerm" { - features {} -} - -provider "azapi" { +terraform { + # backend "azurerm" { + # resource_group_name = "rg-adl-terraform-state" + # storage_account_name = "stadlterraformstate" + # container_name = "default" + # key = "fabriccapacity.terraform.tfstate" + # } + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.53.0" + } + azapi = { + source = "azure/azapi" + } + } +} + +provider "azurerm" { + features {} +} + +provider "azapi" { } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/test/variables.tf b/terraform/fabric/fabric-capacity/test/variables.tf index e02145e4..0f354ecc 100644 --- a/terraform/fabric/fabric-capacity/test/variables.tf +++ b/terraform/fabric/fabric-capacity/test/variables.tf @@ -1,20 +1,20 @@ -resource "random_string" "postfix" { - length = 8 - special = false - upper = false -} - -variable "location" { - type = string - default = "North Europe" -} - -variable "sku" { - type = string - default = "F2" -} - -variable "admin_email" { - type = string - default = "aimurg@microsoft.com" +resource "random_string" "postfix" { + length = 8 + special = false + upper = false +} + +variable "location" { + type = string + default = "North Europe" +} + +variable "sku" { + type = string + default = "F2" +} + +variable "admin_email" { + type = string + default = "aimurg@microsoft.com" } \ No newline at end of file diff --git a/terraform/fabric/fabric-capacity/variables.tf b/terraform/fabric/fabric-capacity/variables.tf index 53c44032..366e1f4e 100644 --- a/terraform/fabric/fabric-capacity/variables.tf +++ b/terraform/fabric/fabric-capacity/variables.tf @@ -1,35 +1,41 @@ -variable "basename" { - type = string - description = "Basename of the module." - validation { - condition = can(regex("^[-0-9a-zA-Z]{1,21}$", var.basename)) && can(regex("[0-9a-zA-Z]+$", var.basename)) - error_message = "The name must be between 1 and 21 characters, can contain only letters, numbers, and hyphens. Must end with a letter or number. Cannot contain consecutive hyphens." - } -} - -variable "resource_group_id" { - type = string - description = "Resource group id." -} - -variable "location" { - type = string - description = "Location of the resource group." -} - -variable "tags" { - type = map(string) - default = {} - description = "A mapping of tags which should be assigned to the deployed resource." -} - -variable "sku" { - type = string - default = "F2" - description = "" -} - -variable "admin_email" { - type = string - description = "" +variable "basename" { + type = string + description = "Basename of the module." + validation { + condition = can(regex("^[-0-9a-zA-Z]{1,21}$", var.basename)) && can(regex("[0-9a-zA-Z]+$", var.basename)) + error_message = "The name must be between 1 and 21 characters, can contain only letters, numbers, and hyphens. Must end with a letter or number. Cannot contain consecutive hyphens." + } +} + +variable "resource_group_id" { + type = string + description = "Resource group id." +} + +variable "location" { + type = string + description = "Location of the resource group." +} + +variable "tags" { + type = map(string) + default = {} + description = "A mapping of tags which should be assigned to the deployed resource." +} + +variable "module_enabled" { + type = bool + description = "Variable to enable or disable the module." + default = true +} + +variable "sku" { + type = string + default = "F2" + description = "SKU name" +} + +variable "admin_email" { + type = string + description = "Fabric administrator email" } \ No newline at end of file