skip to Main Content

I am new to Terraform.

I am looking online for example in Terraform (provider "hashicorp/azurerm") for creating a linked service in Synapse linking to:

Azure datalake storage account
Azure sql server

My code which doesn’t work…

>    resource "azurerm_synapse_linked_service"
> "synapse_linked_service_datalake" {
>       depends_on           = [module.add_synapse_firewall_rule0, azurerm_storage_data_lake_gen2_filesystem.datalake_fs,
> data.azurerm_storage_account.datalake, module.set_role_storage]
>       name                 = "linked-service-to_${data.azurerm_storage_account.datalake.name}"
>       synapse_workspace_id = azurerm_synapse_workspace.synapse.id
>       type                 = "AzureBlobFS"
>       type_properties_json = <<JSON
>         {
>           "connectionString": "DefaultEndpointsProtocol=https;AccountName=${data.azurerm_storage_account.datalake.name};AccountKey=${data.azurerm_storage_account.datalake.primary_access_key};EndpointSuffix=core.windows.net" 
>         }
>         JSON }

The error I get….

2023-07-15T12:55:58.2894784Z [31m│[0m [0m  "Name": "linked-service-to_XXXXXXXXX",
2023-07-15T12:55:58.2895043Z [31m│[0m [0m  "Properties": {
2023-07-15T12:55:58.2895237Z [31m│[0m [0m    "type": "AzureBlobFS",
2023-07-15T12:55:58.2895441Z [31m│[0m [0m    "typeProperties": {}
2023-07-15T12:55:58.2895614Z [31m│[0m [0m  }
2023-07-15T12:55:58.2895910Z [31m│[0m [0m} and error is Invalid linked service payload, the 'typeProperties' nested in payload is

null..

=============================

I found this online, need to modify for the Az storage account….

Here’s an example…

resource "azurerm_synapse_linked_service" "cosmos" {
  name                 = "synsv-powerbi-uksouth"
  synapse_workspace_id = azurerm_synapse_workspace.synapse.id
  type                 = "Azure Cosmos DB (SQL API)"
  type_properties_json = <<JSON
{
  "connectionString": "${azurerm_cosmosdb_account.cosmos.connection_strings[0]}Database=${azurerm_cosmosdb_sql_database.cosmos.name}"
}
JSON

  depends_on = [
    azurerm_synapse_firewall_rule.synapse
  ]
}

==============================================

According the Terraform logs the below TF worked although I can’t see the newly created Synapse ‘linked service’ in the Azure Synapse Studio…

resource "azurerm_synapse_linked_service" "synapse_linked_service_datalake" {
  depends_on           = [module.add_synapse_firewall_rule0, azurerm_storage_data_lake_gen2_filesystem.datalake_fs, data.azurerm_storage_account.datalake, module.set_role_storage]
  name                 = "linked-service-to_${data.azurerm_storage_account.datalake.name}"
  synapse_workspace_id = azurerm_synapse_workspace.synapse.id
  type                 = "AzureBlobStorage"
  type_properties_json = <<JSON
    {
      "connectionString": "DefaultEndpointsProtocol=https;AccountName=${data.azurerm_storage_account.datalake.name};AccountKey=${data.azurerm_storage_account.datalake.primary_access_key};EndpointSuffix=core.windows.net" 
    }
    JSON

  /* integration_runtime {
    name = azurerm_synapse_integration_runtime_azure.synapse_integration_runtime.name
  } */

}

2

Answers


  1. Chosen as BEST ANSWER

    Terraform for Azure storage account (datalake) using 'default intergration runtime'....

    resource "azurerm_synapse_linked_service" "synapse_linked_service_datalake" {
      depends_on           = [module.add_synapse_firewall_rule, data.azurerm_storage_account.datalake, module.set_role_storage, azurerm_synapse_role_assignment.role_synapse_role_assignments]
      name                 = "linked-service-to_${data.azurerm_storage_account.datalake.name}"
      synapse_workspace_id = azurerm_synapse_workspace.synapse.id
      #type                 = "AzureStorage"
      type                 = "AzureBlobFS"
      type_properties_json = <<JSON
        {
          "url": "https://${data.azurerm_storage_account.datalake.name}.dfs.core.windows.net"
        }
        JSON
    
      /* integration_runtime {
        name = azurerm_synapse_integration_runtime_azure.synapse_integration_runtime.name
      } */
    

    }


  2. It could be something like this:

    resource "azurerm_synapse_linked_service_azure_sql_database" "example" {
      name                = "example"
      workspace_name      = azurerm_synapse_workspace.example.name
      resource_group_name = azurerm_resource_group.example.name
    
      connection_string = "Data Source=tcp:<your_server>.database.windows.net,1433;Initial Catalog=<your_database>;User ID=<your_username>;Password=<your_password>;Encrypt=true;TrustServerCertificate=false;Connection Timeout=30;"
    }
    
    resource "azurerm_synapse_linked_service_azure_data_lake_storage_gen2" "example" {
      name                = "example"
      workspace_name      = azurerm_synapse_workspace.example.name
      resource_group_name = azurerm_resource_group.example.name
    
      storage_account_name = azurerm_storage_account.example.name
    }
    

    }

    You can also check out the official documentation on the Terraform Registry for more information on how to use this provider:

    Let me know if it helps by accepting the answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search