0

We are trying to create an Azure Data Factory Linked Service for an Azure Batch account using Terraform. However, there is no native resource available in Terraform documentation for creating an Azure Batch Linked Service directly. To work around this, we attempted to use a custom-linked service. But, we are encountering an "Invalid Payload" error with the type "AzureBatch." We need assistance in resolving this issue and successfully creating the Azure Batch Linked Service using Terraform. Any guidance or solutions would be highly appreciated.

Reference:- https://learn.microsoft.com/en-us/azure/templates/microsoft.datafactory/factories/linkedservices?pivots=deployment-language-terraform#azurebatchlinkedservice-2

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • Can you provide the code here instead of image. @Karandeep Singh – Jahnavi Jul 20 '23 at 08:06
  • 1
    Hi@Jahnavi this is the code ### `resource "azurerm_data_factory_linked_custom_service" "example" { name = "azurebatch1" data_factory_id = azurerm_data_factory.example.id type = "AzureBatch" description = "test description" type_properties_json = < – Karandeep Singh Jul 20 '23 at 09:40

2 Answers2

0

According to the sample template from terraform registry, I checked your code and tried to create Azure Batch linked service in my environment using azurerm_data_factory_linked_custom_service resource and was able to run it successfully as follows.

resource "azurerm_resource_group" "main" {
  name     = "example-resources"
  location = "West Europe"
}
resource "azurerm_data_factory" "main" {
  name                = "examplejambar"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
  identity {
    type = "SystemAssigned"
  }
}
resource "azurerm_storage_account" "main" {
  name                     = "examplelocker"
  resource_group_name      = azurerm_resource_group.main.name
  location                 = azurerm_resource_group.main.location
  account_kind             = "BlobStorage"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}
resource "azurerm_data_factory_linked_custom_service" "main" {
  name                 = "mainsample"
  data_factory_id      = azurerm_data_factory.main.id
  type                 = "AzureBlobStorage"
  description          = "test description"
  type_properties_json = <<JSON
{
 "connectionString":"${azurerm_storage_account.main.primary_connection_string}"
}
JSON

  parameters = {
    "foo" : "bar"
    "Env" : "Test"
  }

  annotations = [
    "test1",
    "test2",
    "test3"
  ]
}

Initialized & validated the configuration:

enter image description here

Executed terraform plan:

enter image description here

Executed terraform apply:

enter image description here

Deployed successfully:

enter image description here

Jahnavi
  • 3,076
  • 1
  • 3
  • 10
  • Hi Jahnavi thanks for your suggestion but the example that you have provided it will create a linked service for blob storage not for batch account. we want to create a linked service for batch account, please see the description carefully. Thanks – Karandeep Singh Jul 20 '23 at 10:42
  • But in the connection string I can see that it is linking to storage account. How are you trying to link it with the batch account? @KarandeepSingh – Jahnavi Jul 21 '23 at 05:56
  • okay, so can u give me the solution for this, I want to link it with the batch account – Karandeep Singh Jul 21 '23 at 10:24
  • Did you try adding the connection string of batch account under `connection_string` property. @KarandeepSingh – Jahnavi Jul 22 '23 at 03:40
  • We have found the solution for this. There is no need to provide a connection string. – Karandeep Singh Jul 22 '23 at 08:08
0

The error is Invalid linked service payload, the "typeProperties" nested in payload is null.. shows that you have an issue with "connectionString":"${data.azurerm_storage_account.example.primary_connection_string}" config line.

Please double check that you have needed azurerm_storage_account, and data.azurerm_storage_account.example.primary_connection_string return correct connection string.

zombi_man
  • 1,804
  • 3
  • 16
  • 22
  • yes @zombi_man , so can u please give me a solution for this – Karandeep Singh Jul 21 '23 at 10:26
  • what should be the correct value for the string if we are creating a linked service for a batch account? – Karandeep Singh Jul 21 '23 at 10:27
  • @KarandeepSingh, if you don't have storage account, please check the answer of @jahnavi and add `resource azurerm_storage_account` to your terraform config – zombi_man Jul 21 '23 at 11:26
  • we have a storage account and batch account is using that storage account, but now we want to link that batch account with the data factory using a linked service. – Karandeep Singh Jul 21 '23 at 12:18
  • ok, if you already have it please use the correct data resource for getting proper `connection string`. you can use `terraform console` command and run something like `data.azurerm_storage_account.example.primary_connection_string` and you should have the right `connection string`, if no - you need to update your terraform config. I believe you can check the connection string in the Azure UI. – zombi_man Jul 21 '23 at 12:51
  • We have found the solution for this. – Karandeep Singh Jul 22 '23 at 08:06