aztfmod / terraform-provider-azurecaf

Terraform provider for the Terraform platform engineering for Azure
172 stars 91 forks source link

azurecaf_name support for import #247

Open kmataru opened 11 months ago

kmataru commented 11 months ago

Is your feature request related to a problem? Please describe. Working with terraform-azurerm-caf and having to import lots of cloud resources it leaves azurecaf_name (even with passthrough = true) as a dependency to the actual resources.

Leaving the last ones in recreate state, even if the name is exactly the same.

  # module.solution.module.batch_accounts["batch_account"].azurecaf_name.account will be created
  + resource "azurecaf_name" "account" {
      + clean_input   = true
      + id            = (known after apply)
      + name          = "BA"
      + passthrough   = true
      + random_length = 0
      + resource_type = "azurerm_batch_account"
      + result        = (known after apply)
      + results       = (known after apply)
      + separator     = "-"
      + use_slug      = true
    }

  # module.solution.module.batch_accounts["batch_account"].azurerm_batch_account.account must be replaced
  # (imported from "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RG/providers/Microsoft.Batch/batchAccounts/BA")
  # Warning: this will destroy the imported resource
-/+ resource "azurerm_batch_account" "account" {
      ~ account_endpoint                    = "BA._.batch.azure.com" -> (known after apply)
      ~ id                                  = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RG/providers/Microsoft.Batch/batchAccounts/BA" -> (known after apply)
      ~ name                                = "BA" # forces replacement -> (known after apply) # forces replacement

Describe the solution you'd like Probably it would defeat the whole purpose to have the ability to run the import command (somehow). But I am raising this at a discussion level.

(Maybe this would be a topic for terraform-azurerm-caf project; and instead of resource "azurecaf_name" there should be data "azurecaf_name") Update: I was rethinking this and data "azurecaf_name" makes sense only when passthrough = true 😊

Describe alternatives you've considered As silly as it seemed, I tried running the import command: Error: resource azurecaf_name doesn't support import

dmunkovpax8 commented 2 months ago

I think the scope of this issue is more then just with import, - it's with unnecessary "known after apply" status of the result output of azurecaf_name resource. Even when all inputs are known upfront, for some reason it can't assemble the name until apply.