terraform-provider-azapi: 1.13.1 jsonencode bug

howdy, we have an ssh-key generation azapi_resource_action:

resource "azapi_resource_action" "ssh_key_gen" {
  for_each    = local.vms
  type        = "Microsoft.Compute/sshPublicKeys@2022-11-01"
  resource_id = azapi_resource.ssh_key[each.key].id
  action      = "generateKeyPair"
  method      = "POST"

  response_export_values = ["publicKey", "privateKey"]
  lifecycle {
    ignore_changes = [
      body
    ]
  }
}

i’ve created a new vms with the code above and it throws:

| Error: Invalid function argument
│ 
│   on ../../modules/foundation/virtual_machine.tf line 146, in resource "azapi_resource" "ssh-key-udpate":
│  146:         ssh_key = jsondecode(azapi_resource_action.ssh_key_gen[each.key].output).publicKey
│     ├────────────────
│     │ while calling jsondecode(str)
│     │ azapi_resource_action.ssh_key_gen is object with 3 attributes
│     │ each.key is "globaldevweutemptest"
│ 
│ Invalid value for "str" parameter: string required.

╵
╷
│ Error: Invalid function argument
│ 
│   on ../../modules/foundation/virtual_machine.tf line 348, in resource "azurerm_key_vault_secret" "private_key":
│  348:   value         = jsondecode(azapi_resource_action.ssh_key_gen[each.key].output).privateKey
│     ├────────────────
│     │ while calling jsondecode(str)
│     │ azapi_resource_action.ssh_key_gen is object with 3 attributes
│     │ each.key is "globaldevweutemptest"
│ 
│ Invalid value for "str" parameter: string required.
╵
╷
│ Error: Invalid function argument
│ 
│   on ../../modules/foundation/virtual_machine.tf line 356, in resource "azurerm_key_vault_secret" "public_key":
│  356:   value         = jsondecode(azapi_resource_action.ssh_key_gen[each.key].output).publicKey
│     ├────────────────
│     │ while calling jsondecode(str)
│     │ azapi_resource_action.ssh_key_gen is object with 3 attributes
│     │ each.key is "globaldevweutemptest"
│ 
│ Invalid value for "str" parameter: string required.

I assume I dont need:

enable_hcl_output_for_data_source 

as i’m using 1.13.1? this was working prior to 1.13.0\1.13.1 drama this vm is part of the config that existed prior to 1.13.0 release and got upgraded to 1.13.0 and 1.13.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

we have like 100+ state files all only available via private networking 😦 i’ll prolly just leave this a lifecycle ignore tbh. i’ll check later today in regards to how it looks in the state file and update you

Yes, you could remove the ignore_changes and there will be no changes.