hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.61k stars 4.65k forks source link

Error in function call try #18685

Open SyedAli-180 opened 2 years ago

SyedAli-180 commented 2 years ago

Is there an existing issue for this?

Community Note

│ on .terraform\modules\caf\virtual_machines.tf line 41, in module "virtual_machines": │ 41: boot_diagnostics_storage_account = try(local.combined_diagnostics.storage_accounts[each.value.boot_diagnostics_storage_account_key].primary_blob_endpoint,
│ 42: each.value.boot_diagnostics_storage_account_key == "" ? "" : each.value.throw_error, │ 43: can(tostring(each.value.boot_diagnostics_storage_account_key)) ? each.value.throw_error : null) │ ├──────────────── │ │ each.value is object with 7 attributes │ │ each.value.boot_diagnostics_storage_account_key is "bootdiag_region1gvgfvgfvg" │ │ local.combined_diagnostics.storage_accounts is object with no attributes │ │ Call to function "try" failed: no expression succeeded: │ - Invalid index (at .terraform\modules\caf\virtual_machines.tf:41,85-134) │ The given key does not identify an element in this collection value. │ - Unsupported attribute (at .terraform\modules\caf\virtual_machines.tf:42,76-88) │ This object does not have an attribute named "throw_error". │ - Unsupported attribute (at .terraform\modules\caf\virtual_machines.tf:43,78-90) │ This object does not have an attribute named "throw_error". │ │ At least one expression must produce a successful resul

Terraform Version

1.2.9

AzureRM Provider Version

2.99.0

Affected Resource(s)/Data Source(s)

azurerm_windows_virtual_machine

Terraform Configuration Files

terraform {
  required_providers {
  }
  required_version = ">= 0.15"
}

provider "azurerm" {
  features {
    key_vault {
      purge_soft_delete_on_destroy = var.provider_azurerm_features_keyvault.purge_soft_delete_on_destroy
    }
  }
}

provider "azurerm" {
  alias                      = "vhub"
  skip_provider_registration = true
  features {}
  subscription_id = data.azurerm_client_config.default.subscription_id
  tenant_id       = data.azurerm_client_config.default.tenant_id
}

data "azurerm_client_config" "default" {}

variable "global_settings" {
  default = {}
}

variable "resource_groups" {
  default = {}
}

variable "logged_user_objectId" {
  default = {}
}

variable "virtual_machines" {
  default = {}
}

variable "provider_azurerm_features_keyvault" {
  default = {
    purge_soft_delete_on_destroy = true
  }
}

# variable "resource_groups" {
#   default = {}
# }
variable "vnets" {
  default = {}
}
variable "public_ip_addresses" {
  default = {}
}
variable "keyvaults" {
  default = {}
}

module "caf" {
  source  = "aztfmod/caf/azurerm"
  version = ">=5.4.2"

  providers = {
    azurerm.vhub = azurerm.vhub
  }

  global_settings             = var.global_settings
  resource_groups             = var.resource_groups
  logged_user_objectId        = var.logged_user_objectId
  keyvaults       = var.keyvaults
  compute = {
    virtual_machines = var.virtual_machines
  }
   networking = {
    public_ip_addresses = var.public_ip_addresses
    vnets               = var.vnets
  }

}

Debug Output/Panic Output

╵
PS A:\CAF> terraform plan
module.caf.random_string.prefix[0]: Refreshing state... [id=zuxg]
module.caf.module.resource_groups["vm_region1"].azurecaf_name.rg: Refreshing state... [id=ontyvthsjsyucbuc]
module.caf.data.azurerm_subscription.primary: Reading...
module.caf.data.azurerm_client_config.current: Reading...
data.azurerm_client_config.default: Reading...
module.caf.module.resource_groups["vm_region1"].azurerm_resource_group.rg: Refreshing state... [id=/subscriptions/*******/resourceGroups/zuxg-rg-example-virtual-machine-rg1]
module.caf.data.azurerm_client_config.current: Read complete after 0s [id=2022-10-10 13:09:45.1040924 +0000 UTC]
data.azurerm_client_config.default: Read complete after 0s [id=2022-10-10 13:09:45.1035679 +0000 UTC]
module.caf.data.azurerm_subscription.primary: Read complete after 0s [id=/subscriptions/**************]
╷
│ Warning: Argument is deprecated
│
│   with module.caf.module.api_management_custom_domain.azurerm_api_management_custom_domain.apim,
│   on .terraform\modules\caf\modules\apim\api_management_custom_domain\module.tf line 1, in resource "azurerm_api_management_custom_domain" "apim":
│    1: resource "azurerm_api_management_custom_domain" "apim" {
│
│ `proxy` is deprecated and will be renamed to `gateway` in version 3.0 of the AzureRM provider
╵
╷
│ Error: Error in function call
│
│   on .terraform\modules\caf\virtual_machines.tf line 41, in module "virtual_machines":
│   41:   boot_diagnostics_storage_account = try(local.combined_diagnostics.storage_accounts[each.value.boot_diagnostics_storage_account_key].primary_blob_endpoint,      
│   42:     each.value.boot_diagnostics_storage_account_key == "" ? "" : each.value.throw_error,
│   43:   can(tostring(each.value.boot_diagnostics_storage_account_key)) ? each.value.throw_error : null)
│     ├────────────────
│     │ each.value is object with 7 attributes
│     │ each.value.boot_diagnostics_storage_account_key is "bootdiag_region1gvgfvgfvg"
│     │ local.combined_diagnostics.storage_accounts is object with no attributes
│
│ Call to function "try" failed: no expression succeeded:
│ - Invalid index (at .terraform\modules\caf\virtual_machines.tf:41,85-134)
│   The given key does not identify an element in this collection value.
│ - Unsupported attribute (at .terraform\modules\caf\virtual_machines.tf:42,76-88)
│   This object does not have an attribute named "throw_error".
│ - Unsupported attribute (at .terraform\modules\caf\virtual_machines.tf:43,78-90)
│   This object does not have an attribute named "throw_error".
│
│ At least one expression must produce a successful result.

Expected Behaviour

No response

Actual Behaviour

No response

Steps to Reproduce

No response

Important Factoids

No response

References

No response

myc2h6o commented 2 years ago

Hi @SyedAli-180 thanks for opening the issue! There seems to be some issue within the try function.

For the error The given key does not identify an element in this collection value., you may want to check https://discuss.hashicorp.com/t/the-given-key-does-not-identify-an-element-in-this-collection-value/33268/2

And for This object does not have an attribute named "throw_error"., it seems like each.value doesn't have a property named throw_error, you may need to check the properties in each.value