Is there a way to configure git for synapse using terraform or arm templates?

Viewed 318

'''

data "azurerm_client_config" "current" {}
resource "azurerm_synapse_workspace" "example" {
  name                                 = "example"
  resource_group_name                  = azurerm_resource_group.example.name
  location                             = azurerm_resource_group.example.location
  storage_data_lake_gen2_filesystem_id = data.azurerm_storage_container.example
  sql_administrator_login              = "sqladminuser"
  sql_administrator_login_password     = "admin@123"

  azure_devops_repo {
      account_name = "organizationaz440"
      branch_name = "Development"
      project_name = "TestProject"
      repository_name = "DataOps"
      root_folder = "/SynapseNew"
      tenant_id = data.azurerm_client_config.current.tenant_id
  }
  depends_on = [resource.azurerm_synapse_workspace.example]
}

'''

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/synapse_workspace

Error: Blocks of type "azure_devops_repo" are not expected here.

2 Answers

There are couple of things which needs to be fixed:

  1. You are giving storage_data_lake_gen2_filesystem_id = data.azurerm_storage_container.example instead you have to give storage_data_lake_gen2_filesystem_id = azurerm_storage_data_lake_gen2_filesystem.example.id. You have to create a datalake gen 2 filesystem using your exisitng storage account as data source for azurerm_storage_data_lake_gen2_filesystem is not supported.
  2. You can remove this tenant_id = data.azurerm_client_config.current.tenant_id as its optional and keeping it will give an error that An argument named "tenant_id" is not expected here.
  3. You can remove depends_on = [resource.azurerm_synapse_workspace.example] as its not required.

So, after the above changes are made the .tf file will be like below:

    provider "azurerm" {
        features{}
    }
    
    data "azurerm_storage_account" "name" {
      name = "ansumanstorageacc"
      resource_group_name = "yourresourcegroupname"
    }
    resource "azurerm_storage_data_lake_gen2_filesystem" "example" {
      name               = "example"
      storage_account_id = data.azurerm_storage_account.name.id
    }
    resource "azurerm_synapse_workspace" "example" {
      name                                 = "example"
      resource_group_name                  = "yourresourcegroupname"
      location                             = "West US 2"
      storage_data_lake_gen2_filesystem_id = azurerm_storage_data_lake_gen2_filesystem.example.id
      sql_administrator_login              = "sqladminuser"
      sql_administrator_login_password     = "admin@123"
    
      azure_devops_repo {
          account_name = "organizationaz440"
          branch_name = "Development"
          project_name = "TestProject"
          repository_name = "DataOps"
          root_folder = "/SynapseNew"
      }
    }

Outputs:

enter image description here

terraform apply -auto-approve:

enter image description here

Try setting up you azure_devops_repo inside azurerm_synapse_workspace as follow:

azure_devops_repo = [{
      account_name = "organizationaz440"
      branch_name = "Development"
      project_name = "TestProject"
      repository_name = "DataOps"
      root_folder = "/SynapseNew"
      tenant_id = data.azurerm_client_config.current.tenant_id
}]

Basically, as list of object.

Related