@all
I have written a code to create a vault secret using null_resource but I am getting one error when I run terraform validate
provisioner "local-exec" {
when = create
command = "curl -k -H 'X-Vault-Token: ${var.VAULT_TOKEN}' -X POST --data @$PWD/config/kubeconfig.json ${var.VAULT_ADDR}/v1/secret/aws/tsys${module.init.current_account_name_lower}/${local.region}/eks_linux/${local.cluster_name}/kubeconfig"
}
depends_on = [
null_resource.copy_kube_config
]
}
resource "null_resource" "delete_vault_config" {
provisioner "local-exec" {
when = destroy
command = "curl -k -H 'X-Vault-Token: ${var.VAULT_TOKEN}' -X DELETE ${var.VAULT_ADDR}/v1/secret/aws/vkhello${module.init.current_account_name_lower}/${local.region}/eks_linux/${local.cluster_name}/kubeconfig"
}
}
Error: Invalid reference from destroy provisioner
│
│ on main.tf line 42, in resource "null_resource" "delete_vault_config":
│ 42: command = "curl -k -H 'X-Vault-Token: ${var.VAULT_TOKEN}' -X DELETE ${var.VAULT_ADDR}/v1/secret/aws/vkhello${module.init.current_account_name_lower}/${local.region}/eks_linux/${local.cluster_name}/kubeconfig"
│
│ Destroy-time provisioners and their connection configurations may only reference attributes of the related resource, via 'self', 'count.index', or 'each.key'.
│
│ References to other resources during the destroy phase can cause dependency cycles and interact poorly with create_before_destroy.
Is there a way to delete the vault secret using null resource only when I run terraform destroy?