Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a nested folder structure more than 2 levels deep #5398

Closed
cloud-dan opened this issue Jan 14, 2020 · 5 comments
Closed

Unable to create a nested folder structure more than 2 levels deep #5398

cloud-dan opened this issue Jan 14, 2020 · 5 comments

Comments

@cloud-dan
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

  • Terraform v0.12.19
  • + provider.AzureRM v1.40.0

Affected Resource(s)

  • azurerm_storage_share_directory

Terraform Configuration Files

locals {
  folder_sructure = [
    "Folder1",
    "Folder1/Folder2",
    "Folder1/Folder2/Folder3"
  ]
}

resource "azurerm_storage_share" "files" {
  name                 = "files"
  storage_account_name = data.azurerm_storage_account.Data.name
  quota                = 50
}

resource "azurerm_storage_share_directory" "folder_sructure" {
  for_each = toset(local.folder_sructure)

  name                 = each.key
  share_name           = azurerm_storage_share.files.name
  storage_account_name = data.azurerm_storage_account.data.name
}

Panic Output

Error: name must contain only uppercase and lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter

  on storage._shares.tf line 146, in resource "azurerm_storage_share_directory" "files":
 146: resource "azurerm_storage_share_directory" "files" {

Expected Behavior

It should have created a directory structure starting with Folder1, then a sub folder Folder2 and finally Folder3 underneath that.

├── Folder1
│   └── Folder2
│       └── Folder3

I would have also expected the following plan.

# azurerm_storage_share.files will be created
+ resource "azurerm_storage_share" "files" {
    + id                   = (known after apply)
    + name                 = "files"
    + quota                = 50
    + resource_group_name  = (known after apply)
    + storage_account_name = "jamdevdata01"
    + url                  = (known after apply)
  }

# azurerm_storage_share_directory.files["Folder1"] will be created
+ resource "azurerm_storage_share_directory" "files" {
    + id                   = (known after apply)
    + name                 = "Folder1"
    + share_name           = "files"
    + storage_account_name = "jamdevdata01"
  }

# azurerm_storage_share_directory.files["Folder1/Folder2"] will be created
+ resource "azurerm_storage_share_directory" "files" {
    + id                   = (known after apply)
    + name                 = "Folder1/Folder2"
    + share_name           = "files"
    + storage_account_name = "jamdevdata01"
  }

# azurerm_storage_share_directory.files["Folder1/Folder2/Folder3"] will be created
+ resource "azurerm_storage_share_directory" "files" {
    + id                   = (known after apply)
    + name                 = "Folder1/Folder2/Folder3"
    + share_name           = "files"
    + storage_account_name = "jamdevdata01"
  }

Actual Behavior

It says the directory name has failed validation. However, I believe this is actually caused by this regex not being able to handle a 3 level nested folder structure.

Storage.go Line 15

if !regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`).MatchString(value) && !regexp.MustCompile(`^[A-Za-z0-9]{1,}/[A-Za-z0-9]{1,}$`).MatchString(value) {
  errors = append(errors, fmt.Errorf("%s must contain only uppercase and lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter", k))
}

Steps to Reproduce

  1. terraform init
  2. terraform apply

Important Factoids

I tested this with a 2 level nested structure and Terraform was able to deploy it.

├── Folder1
│   └── Folder2

References

@JeremiahInMN
Copy link

JeremiahInMN commented Jun 11, 2020

This regex mentioned above, also will cause anything with nested folders and a hyphen in the name to fail with the same error as mentioned above.

Example:
This works "folder-name"
This will not work, but should "parent/folder-name"

@jogleasonjr
Copy link
Contributor

jogleasonjr commented Jun 17, 2020

I added a PR #7382 to fix the hyphen bug in the comment from @JeremiahInMN

I adjusted the regex to allow this provider to accept multiple levels of nested directories, but the Azure API rejected it. This provider would have to implement some looping to get it to work -- not just a regex fix.

Error: Error creating Directory "parent/child-two/grand-child" (File Share "fileshare" / Account "redacted"): directories.Client#Create: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ParentNotFound" Message="The specified parent path does not exist.\nRequestId:0ea534ae-f01a-00e4-61d8-44c4d8123456\nTime:2020-06-17T18:51:14.1181258Z"

@mbfrahry mbfrahry added this to the v2.15.0 milestone Jun 18, 2020
@katbyte katbyte modified the milestones: v2.15.0, v2.16.0 Jun 18, 2020
@tombuildsstuff
Copy link
Member

Fixed via #7382

@ghost
Copy link

ghost commented Jun 25, 2020

This has been released in version 2.16.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.16.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jul 25, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Jul 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants