Skip to content

Commit

Permalink
fix: Remove non-needed counts on Autokey submodule (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanini-ciandt authored Oct 16, 2024
1 parent 1d9fa83 commit c50e2d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
8 changes: 4 additions & 4 deletions modules/autokey/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,15 +29,15 @@ 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]
}

#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
Expand All @@ -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]
Expand Down
7 changes: 1 addition & 6 deletions modules/autokey/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/autokey/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit c50e2d5

Please sign in to comment.