diff --git a/modules/autokey/iam.tf b/modules/autokey/iam.tf index 5d762b0..29e9df6 100644 --- a/modules/autokey/iam.tf +++ b/modules/autokey/iam.tf @@ -20,7 +20,7 @@ data "google_project" "kms_project" { #Create KMS Service Agent resource "google_project_service_identity" "kms_service_agent" { - count = local.create_autokey_key_handles ? 1 : 0 + count = var.autokey_handles != null ? 1 : 0 provider = google-beta service = "cloudkms.googleapis.com" @@ -29,7 +29,7 @@ resource "google_project_service_identity" "kms_service_agent" { # Wait delay after creating service agent. resource "time_sleep" "wait_service_agent" { - count = local.create_autokey_key_handles ? 1 : 0 + count = var.autokey_handles != null ? 1 : 0 create_duration = "10s" depends_on = [google_project_service_identity.kms_service_agent] @@ -37,7 +37,7 @@ resource "time_sleep" "wait_service_agent" { #Grant the KMS Service Agent the Cloud KMS Admin role resource "google_project_iam_member" "autokey_project_admin" { - count = local.create_autokey_key_handles ? 1 : 0 + count = var.autokey_handles != null ? 1 : 0 provider = google-beta project = var.project_id @@ -48,7 +48,7 @@ resource "google_project_iam_member" "autokey_project_admin" { # Wait delay after granting IAM permissions resource "time_sleep" "wait_srv_acc_permissions" { - count = local.create_autokey_key_handles ? 1 : 0 + count = var.autokey_handles != null ? 1 : 0 create_duration = "10s" depends_on = [google_project_iam_member.autokey_project_admin] diff --git a/modules/autokey/main.tf b/modules/autokey/main.tf index 6a7a70d..f6d37ba 100644 --- a/modules/autokey/main.tf +++ b/modules/autokey/main.tf @@ -14,12 +14,7 @@ * limitations under the License. */ -locals { - create_autokey_key_handles = var.autokey_folder_number != null && var.autokey_handles != null -} - resource "google_kms_autokey_config" "primary" { - count = var.autokey_folder_number != null ? 1 : 0 provider = google-beta folder = var.autokey_folder_number @@ -33,7 +28,7 @@ resource "random_string" "suffix" { } resource "google_kms_key_handle" "primary" { - for_each = local.create_autokey_key_handles ? var.autokey_handles : tomap({}) + for_each = var.autokey_handles != null ? var.autokey_handles : tomap({}) provider = google-beta project = each.value.project diff --git a/modules/autokey/outputs.tf b/modules/autokey/outputs.tf index b04af0f..a198889 100644 --- a/modules/autokey/outputs.tf +++ b/modules/autokey/outputs.tf @@ -16,12 +16,12 @@ output "autokey_config_id" { description = "An Autokey configuration identifier." - value = var.autokey_folder_number != null ? google_kms_autokey_config.primary[0].id : "" + value = google_kms_autokey_config.primary.id } output "autokey_keyhandles" { description = "A map of KeyHandles created." - value = local.create_autokey_key_handles ? google_kms_key_handle.primary : {} + value = var.autokey_handles != null ? google_kms_key_handle.primary : {} } output "random_suffix" {