Azure / Azure/terraform-provider-azapi

## Bug: 500 Internal Server Error when creating AzureFile Datastore via AzAPI – Works via CLI/YAML

Open
#880 0 comments 0 reactions 0 assignees View on GitHub
triaged upstream-api
Dominant language
Go
Stars
244
Forks
97
Avg merge
5d 9h
Merged PRs (30d)
9

Description

### Problem Description

When attempting to create an AzureFile Datastore using the `azapi_resource` in Terraform, I receive a 500 Internal Server Error from the Azure ML service.
However, using the exact same parameters and payload via CLI/YAML, the resource is created successfully.

---

### Functional YAML (CLI)

$schema: https://azuremlschemas.azureedge.net/latest/azureFile.schema.json
name: testworkingdircli
type: azure_file
description: Datastore created via CLI for testing
account_name: storageblobdev
file_share_name: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-code
credentials:
account_key:

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.79.0"
}
azapi = {
source = "azure/azapi"
version = "~> 2.4.0"
}
time = {
source = "hashicorp/time"
version = "~> 0.9.1"
}
random = {
source = "hashicorp/random"
version = "~> 3.7.2"
}
}
}

provider "azurerm" {
features {}
skip_provider_registration = true
}

provider "azapi" {}

resource "azapi_resource" "workspaceworkingdirectory" {
name = "workspaceworkingdirectory"
type = "Microsoft.MachineLearningServices/workspaces/datastores@2024-10-01"
parent_id = var.ml_workspace_id

body = {
properties = {
description = "Working directory for workspace"
datastoreType = "AzureFile"
accountName = var.storage_account_name
fileShareName = var.file_share_name
credentials = {
credentialsType = "AccountKey"
secrets = {
secretsType = "AccountKey"
key = data.azurerm_key_vault_secret.storage_key.value
}
}
}
}
depends_on = [
azurerm_storage_share.ml_code,
module.ml_workspace
]
}

---

### Error Output

RESPONSE 500: 500 Internal Server Error
ERROR CODE: ServiceError
correlationId: 52bf06639df9885f51a232594705fcf0
requestId: 1b55ace9ea9407cc
location: brazilsouth
time: 2025-05-21T03:04:36.067303+00:00

---

### What Has Been Checked

- The Key Vault secret is exactly the same storage account key used in the CLI (base64, no extra spaces or line breaks).
- The file share exists and is accessible.
- The storage account and workspace are correctly provisioned.
- The same resource is created successfully via CLI/YAML, but fails via AzAPI/Terraform.
- Region: `brazilsouth`

---

### Steps to Reproduce

1. Create a file share in the storage account.
2. Attempt to create the AzureFile Datastore via AzAPI/Terraform (observe 500 error).
3. Attempt to create the same Datastore via CLI/YAML (succeeds).

---

### Versions

- Terraform: [version = "~> 3.79.0"]
- AzAPI Provider: [version = "~> 2.4.0"]
- Azure CLI: [{
"azure-cli": "2.71.0",
"azure-cli-core": "2.71.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"bastion": "1.4.0",
"costmanagement": "1.0.0",
"ml": "2.36.5",
"quota": "1.0.0"
}
}]

---

### Expected Behavior

The resource should be created via AzAPI in the same way it is via CLI/YAML.

---

### Additional Notes

- No extra fields are present in the AzAPI body (no `serviceDataAccessAuthIdentity`, `tags`, etc.).
- All field names match the casing and structure of the CLI/YAML payload.
- The error is consistent and only occurs via AzAPI.

---

Thank you for your help!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the azapi_resource for Microsoft.MachineLearningServices/workspaces/datastores@2024-10-01 with the versions and brazilsouth configuration shown. Compare its request body and response with the successful Azure CLI/YAML payload; done means the AzureFile datastore is created successfully through AzAPI/Terraform.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, terraform
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.