Phyxx
Phyxx

Reputation: 16108

Terraform can not create a storage account in Azure

I have a Terraform script that used to be able to create a storage account in Azure ok, but today started to return the error message:

azurerm_storage_account.testsa: 1 error(s) occurred: 
* azurerm_storage_account.testsa: Error waiting for Azure Storage Account "terraformtesthubb" to be created: Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=400 -- Original Error: Code="AadClientCredentialsGrantFailure" Message="Failure in AAD Client Credentials Grant Flow."

The trace logs don't show anything useful, and the term AadClientCredentialsGrantFailure literally returns nothing in Google. What is the cause?

Upvotes: 0

Views: 2515

Answers (1)

Phyxx
Phyxx

Reputation: 16108

Answering this one for myself because Google totally failed me.

This turned out to be an issue with Azure. Despite there being no errors listed in any of the status pages, the script would work in US West, but fail in US West 2.

After a few days this issue went away, so it was an intermittent Azure issue.

Edit

For reference, this was the script. Markers like #{Principal.TenantId} are being replaced during the template deployment.

provider "azurerm" {
  client_id = "#{Principal.Client}"
  client_secret = "#{Principal.Password}"
  subscription_id = "#{Principal.SubscriptionNumber}"
  tenant_id = "#{Principal.TenantId}"
}

resource "azurerm_resource_group" "testrg" {
  name     = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  location = "#{Octopus.Environment.Name | ToLower}"
}

resource "azurerm_virtual_network" "test" {
  name                = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  address_space       = ["10.0.0.0/16"]
  location            = "${azurerm_resource_group.testrg.location}"
  resource_group_name = "${azurerm_resource_group.testrg.name}"
}

resource "azurerm_subnet" "test" {
  name                 = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  resource_group_name  = "${azurerm_resource_group.testrg.name}"
  virtual_network_name = "${azurerm_virtual_network.test.name}"
  address_prefix       = "10.0.2.0/24"
  service_endpoints    = ["Microsoft.Sql", "Microsoft.Storage"]
}

resource "azurerm_storage_account" "testsa" {
  name                     = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  resource_group_name      = "${azurerm_resource_group.testrg.name}"
  location                 = "#{Octopus.Environment.Name | ToLower}"
  account_tier             = "Standard"
  account_kind             = "StorageV2"
  account_replication_type = "RAGRS"
    lifecycle {
    prevent_destroy = true
  }
  network_rules {
    ip_rules                   = ["100.0.0.1"]
    virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"]
  }
}

Upvotes: 1

Related Questions