{"record":{"id":"4cd55129e31289e5","repo":"opentofu/opentofu","slug":"invalid-storage-container-name-hyphens-in-a-stora","errorCode":null,"errorMessage":"invalid storage container name: Hyphens in a storage container name must be nonconsecutive. See documentation here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage","messagePattern":"invalid storage container name: Hyphens in a storage container name must be nonconsecutive\\. See documentation here: https://learn\\.microsoft\\.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/azure/backend.go","lineNumber":468,"sourceCode":"\t\treturn fmt.Errorf(\"error getting container client: %w\", err)\n\t}\n\n\tb.containerClient = containerClient\n\treturn nil\n}\n\nfunc checkAccountAndContainerNames(storageAccount, storageContainer string) error {\n\taccountPattern := regexp.MustCompile(`^[0-9a-z]{3,24}$`)\n\tcontainerPattern := regexp.MustCompile(`^[0-9a-z][0-9a-z\\-]{1,61}[0-9a-z]$`)\n\thyphenPattern := regexp.MustCompile(`\\-\\-`)\n\tif !accountPattern.Match([]byte(storageAccount)) {\n\t\treturn errors.New(\"invalid storage account name: Azure requires a storage account name consists of 3-24 lowercase characters and numbers only. See documentation here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage\")\n\t}\n\tif !containerPattern.Match([]byte(storageContainer)) {\n\t\treturn errors.New(\"invalid storage container name: Azure requires a storage container name consists of 3-63 lowercase characters, numbers, and hyphens only. It cannot start or end with a hyphen. See documentation here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage\")\n\t}\n\tif hyphenPattern.Match([]byte(storageContainer)) {\n\t\treturn errors.New(\"invalid storage container name: Hyphens in a storage container name must be nonconsecutive. See documentation here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":450,"sourceCodeEnd":472,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/backend/remote-state/azure/backend.go#L450-L472","documentation":"Validation error from checkAccountAndContainerNames (internal/backend/remote-state/azure/backend.go). After the general container pattern passes, the name is checked against \\-\\- (two consecutive hyphens); Azure container names must not contain consecutive hyphens, so e.g. \"prod--state\" is rejected even though it satisfies the character pattern.","triggerScenarios":"Setting `container_name` (or ARM_CONTAINER_NAME) that contains a double hyphen anywhere in the middle, usually produced by templating that joins two hyphen-delimited parts where one is empty.","commonSituations":"Name templates like \"${env}-${region}-state\" where env is empty; string concatenation in CI pipelines; refactors leaving stray hyphens.","solutions":["Remove the consecutive hyphens: use exactly one hyphen between segments","Fix the templating so empty segments don't collapse into '--'","If the container already exists, copy its real name from the Azure portal"],"exampleFix":"# before\nbackend \"azurerm\" {\n  container_name = \"prod--tf-state\"\n  ...\n}\n\n# after\nbackend \"azurerm\" {\n  container_name = \"prod-tf-state\"\n  ...\n}","handlingStrategy":"validation","validationCode":"var doubleHyphen = regexp.MustCompile(`--`)\n\nfunc validateNoConsecutiveHyphens(name string) error {\n    if doubleHyphen.MatchString(name) {\n        return fmt.Errorf(\"name %q contains consecutive hyphens\", name)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := checkAccountAndContainerNames(account, container); err != nil {\n    if strings.Contains(err.Error(), \"nonconsecutive\") {\n        // collapse '--' to '-' in the generated name\n    }\n    return err\n}","preventionTips":["Join name segments with filters that drop empty parts instead of concatenating blindly","Add a naming lint rule rejecting '--' in all Azure resource names"],"tags":["azure","storage","naming","validation"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}