Open ZoeSecondmind opened 1 year ago
The issue happens with me regardless if using depends_on or not.
Terraform v1.6.4 on linux_amd64
provider registry.terraform.io/hashicorp/kubernetes v2.24.0
k8s: AKS v1.26.6
data "kubernetes_persistent_volume_claim_v1" "claim_to_disk" {
metadata {
name = "<redacted>-0"
namespace = "<redacted>"
#name = local.volumeclaim_name
#namespace = local.volumeclaim_namespace_name
}
}
data "azurerm_managed_disk" "disk_to_backup" {
name = "pvc-345ba363-<redacted>"
#TODO: uncomment when this issue is resolved: https://github.com/hashicorp/terraform-provider-kubernetes/issues/2305
#name = data.kubernetes_persistent_volume_claim_v1.claim_to_disk.spec[0].volume_name
resource_group_name = local.configuration.compute_resourcegroup_name
}
Error: Invalid index
on ../../../modules/templates/backup_policy/data.tf line 11, in data "azurerm_managed_disk" "disk_to_backup":
11: name = data.kubernetes_persistent_volume_claim_v1.claim_to_disk.spec[0].volume_name
├────────────────
│ data.kubernetes_persistent_volume_claim_v1.claim_to_disk.spec is empty list of object
The given key does not identify an element in this collection value: the collection has no elements.
data "kubernetes_persistent_volume_claim_v1" "<redacted>" {
id = "<redacted>/<redacted>-0"
metadata {
annotations = {}
generation = 0
labels = <redacted>
name = "<redacted>-0"
namespace = "<redacted>"
resource_version = "34246249"
uid = "345ba363-<redacted>"
}
spec {
access_modes = [
"ReadWriteOnce",
]
resources = [
{
limits = {}
requests = {
"storage" = "16Gi"
}
},
]
storage_class_name = "managed-csi-premium-zrs-noretain"
volume_name = "pvc-345ba363-<redacted>"
}
}
No idea how to work around this issue, except hardcoding the volume_name where needed. It doesn't make sense to me as the data object in the state seems to be properly loaded. I do find strange that spec is considered a list of objects...
Terraform Version, Provider Version and Kubernetes Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
(https://gist.github.com/ZoeSecondmind/d953a9b61139be57fbaf50ce2991b438)
Steps to Reproduce
terraform plan
Expected Behavior
Successful plan, assuming the supplied PVC already exists.
Actual Behavior
data.kubernetes_persistent_volume_claim_v1.testing.spec is empty list of object
error returned. This error disappears if thedepends_on =
is removed.References
Community Note