Got following terraform code, and it worked weeks ago, all the sudden start to throw errors:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.89.0"
}
}
}
# Configure the Microsoft Azure Provider
provider "azurerm" {
features {}
}
variable "region" {
default = "East US"
}
resource "azurerm_resource_group" "this" {
name = "test"
location = var.region
}
resource "random_string" "random" {
length = 10
special = false
lower = true
numeric = true
upper = false
}
resource "azurerm_storage_account" "this" {
resource_group_name = azurerm_resource_group.this.name
location = var.region
name = "test${random_string.random.id}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_share" "this" {
name = "share"
storage_account_name = azurerm_storage_account.this.name
quota = 1
}
resource "azurerm_storage_share_directory" "this" {
name = "subdir"
storage_share_id = azurerm_storage_share.this.id
}
resource "azurerm_storage_share_file" "this" {
name = "test.txt"
path = azurerm_storage_share_directory.this.name
storage_share_id = azurerm_storage_share.this.id
source = "test.txt"
content_md5 = filemd5("test.txt")
}
To test, you just need to create a test.txt under the same folder as the root module.
When run terraform apply, following plan and error would show up
Terraform will perform the following actions:
# azurerm_storage_share_file.this will be created
+ resource "azurerm_storage_share_file" "this" {
+ content_length = (known after apply)
+ content_md5 = "99d729c7ca431a2df97778cc3ff7696a"
+ content_type = "application/octet-stream"
+ id = (known after apply)
+ name = "test.txt"
+ path = "subdir"
+ source = "test.txt"
+ storage_share_id = "https://teste6d49fe9y7.file.core.windows.net/share"
}
Plan: 1 to add, 0 to change, 0 to destroy.
azurerm_storage_share_file.this: Creating...
╷
│ Error: checking for existing File "test.txt" (Directory Path "subdir" / Share Name "share" / Account "Account \"teste6d49fe9y7\" (IsEdgeZone false / ZoneName \"\" / Subdomain Type \"file\" / DomainSuffix \"core.windows.net\")"): executing request: unexpected status 400 (400 The specifed resource name contains invalid characters.) received with no body
│
│ with azurerm_storage_share_file.this,
│ on main.tf line 52, in resource "azurerm_storage_share_file" "this":
│ 52: resource "azurerm_storage_share_file" "this" {
If I remove path parameter from azurerm_storage_share_file, the file would be uploaded to the root of the share successfully. However the intent is the have the file upload underneath ‘subdir’ folder.