Azure / terraform-azurerm-avm-res-storage-storageaccount

This Terraform module is designed to create Azure Storage Accounts and its related resources, including blob containers, queues, tables, and file shares. It also supports the creation of a storage account private endpoint which provides secure and direct connectivity to Azure Storage over a private network.
https://registry.terraform.io/modules/Azure/avm-res-storage-storageaccount
MIT License
21 stars 33 forks source link

Data call for resource group breaks in some circumstances #68

Closed cfBrianMiller closed 4 months ago

cfBrianMiller commented 7 months ago

Is there an existing issue for this?

Greenfield/Brownfield provisioning

greenfield

Terraform Version

1.7.5

Module Version

0.1.1

AzureRM Provider Version

3.98.0

Affected Resource(s)/Data Source(s)

azurerm_resource_group

Terraform Configuration Files

terraform {
  required_version = ">= 1.0.11"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.98.0"
    }
  }
}

locals {
  subId = "xxxx"
}

provider "azurerm" {
  environment     = "Public"
  subscription_id = local.subId
  features {
    log_analytics_workspace {
      permanently_delete_on_destroy = true
    }
    key_vault {
      purge_soft_delete_on_destroy = true
    }
  }
}

resource "azurerm_resource_group" "sample" {
  location = "eastus"
  name     = "sample"
}

module "avm_res_storage_storageaccount" {
  source  = "Azure/avm-res-storage-storageaccount/azurerm"
  version = "0.1.1"
  name    = "sample"
  resource_group_name = azurerm_resource_group.sample.name
}

tfvars variables values

N/A

Debug Output/Panic Output

module.avm_res_storage_storageaccount.data.azurerm_client_config.this: Reading...
module.avm_res_storage_storageaccount.data.azurerm_client_config.this: Read complete after 0s [id=Y2xpZW50Q29uZmlncy9jbGllbnRJZD0wNGIwNzc5NS04ZGRiLTQ2MWEtYmJlZS0wMmY5ZTFiZjdiNDY7b2JqZWN0SWQ9OGE4N2ZmMGUtNzRhMi00MGZjLWIwMTAtMjNiNWZkMDBhNmQ2O3N1YnNjcmlwdGlvbklkPWFkZmQ5NjEyLWZmMmYtNGJlZC04YTQwLTYyNmMyZGFiZGQzNjt0ZW5hbnRJZD01N2Y5Y2UyYi1kNTMwLTQ1MDEtOWQ2Mi1jNzI0NzIwOGRlOGM=]
module.avm_res_storage_storageaccount.data.azurerm_resource_group.rg: Reading...

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform planned the following actions, but then encountered a problem:

  # azurerm_resource_group.sample will be created
  + resource "azurerm_resource_group" "sample" {
      + id       = (known after apply)
      + location = "eastus"
      + name     = "sample"
    }

  # module.avm_res_storage_storageaccount.azurerm_resource_group_template_deployment.telemetry[0] will be created
  + resource "azurerm_resource_group_template_deployment" "telemetry" {
      + deployment_mode     = "Incremental"
      + id                  = (known after apply)
      + name                = (known after apply)
      + output_content      = (known after apply)
      + parameters_content  = (known after apply)
      + resource_group_name = "sample"
      + template_content    = jsonencode(
            {
              + "$schema"      = "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"
              + contentVersion = "1.0.0.0"
              + outputs        = {
                  + telemetry = {
                      + type  = "String"
                      + value = "For more information, see https://aka.ms/avm/telemetry"
                    }
                }
              + parameters     = {}
              + resources      = []
              + variables      = {}
            }
        )
    }

  # module.avm_res_storage_storageaccount.random_id.telemetry[0] will be created
  + resource "random_id" "telemetry" {
      + b64_std     = (known after apply)
      + b64_url     = (known after apply)
      + byte_length = 4
      + dec         = (known after apply)
      + hex         = (known after apply)
      + id          = (known after apply)
    }

Plan: 3 to add, 0 to change, 0 to destroy.
╷
│ Error: Error: Resource Group "sample" was not found
│ 
│   with module.avm_res_storage_storageaccount.data.azurerm_resource_group.rg,
│   on .terraform/modules/avm_res_storage_storageaccount/main.tf line 3, in data "azurerm_resource_group" "rg":
│    3: data "azurerm_resource_group" "rg" {
│ 
╵

Expected Behaviour

Module deploys successfully

Actual Behaviour

Resource Group data module can't find resource group created in previous call

Steps to Reproduce

terraform plan

Important Factoids

No response

References

This appears to be related to: https://github.com/hashicorp/terraform-provider-azurerm/issues/5233

No response

matt-FFFFFF commented 6 months ago

I concur, if the resource group is created in the same apply then the data source fails - recommend removing the data source and making the location input mandatory

the-blesss commented 6 months ago

I'm also seeing this behavior when deploying the resource group when using the avm storage account module. Work-around is to create the resource group outside of the terraform apply and import it, which is not ideal, but a minor annoyance. I haven't experienced this with any other avms.

davidzenisu commented 6 months ago

Agreed, my workaround is adding a "depends_on" block for the module containing the resource group but obviously that's less than ideal. Agree with your approach @matt-FFFFFF.

matt-FFFFFF commented 5 months ago

Hi @chinthakaru any update here?

kewalaka commented 5 months ago

this has been fixed in #70, released in v0.1.2

kewalaka commented 5 months ago

the variable description for the location should be updated to removed the reference to it using the data source, and the commented out data source in main.tf should be removed.

chinthakaru commented 4 months ago

This has been fixed in #70.