I have seen a lot of question on this topic in the forum but none of them seem to be solved properly.
I’m trying to deploy a Storage Account using Terraform, and in that SA I want to create a Container. When I deploy it, I get the following error:
Error: containers.Client#GetProperties: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailure" Message="This request is not authorized to perform this operation.nRequestId:51828c6f-d01e-0037-297b-b2f7b5000000nTime:2024-05-30T10:25:34.2404478Z"
│
│ with module.global.module.stxxst01xxenv-containers.azurerm_storage_container.main["custom_container_name"],
│ on ../../modules/storage-account/storage-container/main.tf line 4, in resource "azurerm_storage_container" "main":
│ 4: resource "azurerm_storage_container" "main" {
The service principal I’m using has Contributor and Storage Blob Data Contributor in the Subscription, which should be enough.
However, if I execute a terraform apply
again, this second time it is able to create the container.
My suspicion is that when it tries to create the container, the SA is not finished or something like that. Here is the .tf file I’m using:
# Create the RG
module "rg-da-stmain-xxxx-env" {
source = "../modules/resource-group"
resource_group_name = "rg-da-stmain-xxxx-${var.environment}"
location = "West Europe"
tags = {
application = "x"
created-by = "x"
deployer = "x"
stage = var.environment
team = "x"
}
}
# Create the Storage Account
module "stxxst01xxenv" {
source = "../modules/storage-account"
resource_group_name = module.rg-da-stmain-xxxx-env.resource_group_name
location = module.rg-da-stmain-xxxx-env.resource_group_location
storage_account_name = "stxxst01xx${var.environment}"
storage_account_replication_type = "RAGRS"
storage_account_tier = "Standard"
public_network_access_enabled = false
tags = {
application = "x"
created-by = "x"
deployer = "x"
stage = var.environment
team = "x"
}
depends_on = [module.rg-da-stmain-xxxx-env]
}
# Create the Containers
module "stxxst01xxenv-containers" {
source = "../modules/storage-account/storage-container"
storage_account_name = module.stxxst01xxenv.storage_account_name
container_access_type = "private"
storage_containers = ["custom_container_name"]
depends_on = [module.stxxst01xxenv]
}
Does anybody has an idea of what is happening? Thanks in advance.
P.S. If you need some more code let me know in the comments.