|
| 1 | +# Retrieve the client configuration of the AzureRM provider |
| 2 | +data "azurerm_client_config" "example" {} |
| 3 | + |
| 4 | +# Check the directory object type |
| 5 | +data "azuread_directory_object" "example" { |
| 6 | + object_id = data.azurerm_client_config.example.object_id |
| 7 | +} |
| 8 | + |
| 9 | +# Get information about the Entra user |
| 10 | +data "azuread_user" "example" { |
| 11 | + object_id = data.azurerm_client_config.example.object_id |
| 12 | +} |
| 13 | + |
| 14 | +# Local value to determine if the client is a user or not |
| 15 | +locals { |
| 16 | + fabric_admin = can(data.azuread_directory_object.example.type == "User") ? data.azuread_user.example.user_principal_name : data.azurerm_client_config.example.object_id |
| 17 | +} |
| 18 | + |
| 19 | +# Create a resource group |
| 20 | +resource "azurerm_resource_group" "example" { |
| 21 | + name = var.resource_group_name # Name of the resource group |
| 22 | + location = var.location # Location of the resource group |
| 23 | +} |
| 24 | + |
| 25 | +# Create a storage account for remote state |
| 26 | +resource "azurerm_storage_account" "example" { |
| 27 | + name = var.storage_account_name |
| 28 | + resource_group_name = azurerm_resource_group.example.name |
| 29 | + location = azurerm_resource_group.example.location |
| 30 | + account_tier = "Standard" |
| 31 | + account_replication_type = "LRS" |
| 32 | + depends_on = [azurerm_resource_group.example] # Ensure resource group is created first |
| 33 | +} |
| 34 | + |
| 35 | +# Create a storage container for remote state |
| 36 | +resource "azurerm_storage_container" "example" { |
| 37 | + name = var.container_name |
| 38 | + storage_account_name = azurerm_storage_account.example.name |
| 39 | + container_access_type = "private" |
| 40 | + depends_on = [azurerm_storage_account.example] # Ensure storage account is created first |
| 41 | +} |
| 42 | + |
| 43 | +# Create an MSSQL Server |
| 44 | +resource "azurerm_mssql_server" "example" { |
| 45 | + name = var.sql_server_name # Name of the SQL Server |
| 46 | + resource_group_name = azurerm_resource_group.example.name # Resource group name |
| 47 | + location = azurerm_resource_group.example.location # Location of the SQL Server |
| 48 | + version = "12.0" # SQL Server version |
| 49 | + administrator_login = var.admin_username # Administrator username |
| 50 | + administrator_login_password = var.admin_password # Administrator password |
| 51 | + depends_on = [azurerm_resource_group.example] # Ensure resource group is created first |
| 52 | +} |
| 53 | + |
| 54 | +# Add a null resource to introduce a delay |
| 55 | +resource "null_resource" "wait_for_sql_server" { |
| 56 | + depends_on = [azurerm_mssql_server.example] |
| 57 | + |
| 58 | + provisioner "local-exec" { |
| 59 | + command = "Start-Sleep -Seconds 60" |
| 60 | + interpreter = ["PowerShell", "-Command"] |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +# Create an MSSQL Database |
| 65 | +resource "azurerm_mssql_database" "example" { |
| 66 | + name = var.sql_database_name # Name of the SQL Database |
| 67 | + server_id = azurerm_mssql_server.example.id # ID of the SQL Server |
| 68 | + sku_name = "Basic" # SKU name for the SQL Database |
| 69 | + depends_on = [null_resource.wait_for_sql_server] # Ensure SQL Server is fully provisioned first |
| 70 | +} |
| 71 | + |
| 72 | +# Create Microsoft Fabric Capacity |
| 73 | +resource "azurerm_fabric_capacity" "example" { |
| 74 | + name = "fc${var.solution_name}" |
| 75 | + resource_group_name = azurerm_resource_group.example.name |
| 76 | + location = var.location |
| 77 | + |
| 78 | + administration_members = setunion([local.fabric_admin], var.fabric_capacity_admin_upns) |
| 79 | + |
| 80 | + sku { |
| 81 | + name = var.fabric_capacity_sku |
| 82 | + tier = "Fabric" |
| 83 | + } |
| 84 | + depends_on = [azurerm_resource_group.example] # Ensure resource group is created first |
| 85 | +} |
| 86 | + |
| 87 | +# Get the Fabric Capacity details |
| 88 | +data "fabric_capacity" "example" { |
| 89 | + display_name = azurerm_fabric_capacity.example.name |
| 90 | + |
| 91 | + lifecycle { |
| 92 | + postcondition { |
| 93 | + condition = self.state == "Active" |
| 94 | + error_message = "Fabric Capacity is not in Active state. Please check the Fabric Capacity status." |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +# Create a Fabric Workspace |
| 100 | +resource "fabric_workspace" "example" { |
| 101 | + capacity_id = data.fabric_capacity.example.id |
| 102 | + display_name = "ws-${var.solution_name}" |
| 103 | + depends_on = [data.fabric_capacity.example] # Ensure Fabric Capacity data source is available first |
| 104 | +} |
0 commit comments