Skip to content

Commit

Permalink
Revert "Remove purge function for azurerm 2.42"
Browse files Browse the repository at this point in the history
This reverts commit 136e509.
  • Loading branch information
Arnaud Lheureux committed Jan 14, 2021
1 parent 7bf3d67 commit 86783ed
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
4 changes: 3 additions & 1 deletion modules/security/dynamic_keyvault_secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ No requirements.

## Providers

No provider.
| Name | Version |
|------|---------|
| external | n/a |

## Inputs

Expand Down
15 changes: 9 additions & 6 deletions modules/security/dynamic_keyvault_secrets/keyvault.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "secret" {
source = "./secret"
module secret {
source = "./secret"
depends_on = [data.external.purge_secret]
for_each = {
for key, value in var.settings : key => value
if try(value.value, null) == null
Expand All @@ -10,8 +11,9 @@ module "secret" {
keyvault_id = var.keyvault.id
}

module "secret_value" {
source = "./secret"
module secret_value {
source = "./secret"
depends_on = [data.external.purge_secret]
for_each = {
for key, value in var.settings : key => value
if try(value.value, null) != null && try(value.value, null) != ""
Expand All @@ -22,8 +24,9 @@ module "secret_value" {
keyvault_id = var.keyvault.id
}

module "secret_immutable" {
source = "./secret_immutable"
module secret_immutable {
source = "./secret_immutable"
depends_on = [data.external.purge_secret]
for_each = {
for key, value in var.settings : key => value
if try(value.value, null) == ""
Expand Down
50 changes: 24 additions & 26 deletions modules/security/dynamic_keyvault_secrets/secret_purge.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
# Workaround until
#

# Commenting for azurerm 2.42 as secrets purge part of the provider.
data external deleted_secrets {
for_each = var.settings

# data external deleted_secrets {
# for_each = var.settings
program = [
"bash",
"-c",
format(
"az keyvault secret list-deleted --vault-name '%s' --query \"[?name=='%s'].{recoveryId: recoveryId}\" -o json | jq -rce '.[0] // {}'",
var.keyvault.name,
each.value.secret_name
)
]
}

# program = [
# "bash",
# "-c",
# format(
# "az keyvault secret list-deleted --vault-name '%s' --query \"[?name=='%s'].{recoveryId: recoveryId}\" -o json | jq -rce '.[0] // {}'",
# var.keyvault.name,
# each.value.secret_name
# )
# ]
# }
locals {
deleted_secrets = data.external.deleted_secrets
}

# locals {
# deleted_secrets = data.external.deleted_secrets
# }
data external purge_secret {
depends_on = [data.external.deleted_secrets]
for_each = var.settings

# data external purge_secret {
# depends_on = [data.external.deleted_secrets]
# for_each = var.settings

# program = [
# "bash",
# "-c",
# try(format("az keyvault secret purge --id %s -o json | jq -rce '. // {}'", local.deleted_secrets[each.key].result.recovery), "jq -nr '{}'")
# ]
# }
program = [
"bash",
"-c",
try(format("az keyvault secret purge --id %s -o json | jq -rce '. // {}'", local.deleted_secrets[each.key].result.recovery), "jq -nr '{}'")
]
}
6 changes: 3 additions & 3 deletions modules/security/dynamic_keyvault_secrets/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "settings" {}
variable "keyvault" {}
variable "objects" {
variable settings {}
variable keyvault {}
variable objects {
default = {}
}

0 comments on commit 86783ed

Please sign in to comment.