Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ locals {
can(regex(".*hs-crypto.*", var.kms_key_crn)) ? "hs-crypto" : "unrecognized key type"
)
) : "no key crn"

create_kp_auth_policy = var.kms_encryption_enabled == false || var.skip_iam_authorization_policy ? 0 : 1
}

# Create IAM Access Policy to allow Key protect to access Elasticsearch instance
resource "ibm_iam_authorization_policy" "policy" {
count = var.kms_encryption_enabled == false || var.skip_iam_authorization_policy ? 0 : 1
count = local.create_kp_auth_policy
source_service_name = "databases-for-elasticsearch"
source_resource_group_id = var.resource_group_id
target_service_name = local.kms_service
Expand All @@ -45,6 +47,7 @@ resource "ibm_iam_authorization_policy" "policy" {

# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
resource "time_sleep" "wait_for_authorization_policy" {
count = local.create_kp_auth_policy
depends_on = [ibm_iam_authorization_policy.policy]

create_duration = "30s"
Expand Down
5 changes: 4 additions & 1 deletion solutions/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ locals {
use_existing_db_instance = var.existing_db_instance_crn != null

create_cross_account_auth_policy = !var.skip_iam_authorization_policy && var.ibmcloud_kms_api_key != null
create_sm_auth_policy = var.skip_es_sm_auth_policy || var.existing_secrets_manager_instance_crn == null ? 0 : 1
kms_service_name = local.kms_key_crn != null ? (
can(regex(".*kms.*", local.kms_key_crn)) ? "kms" : can(regex(".*hs-crypto.*", local.kms_key_crn)) ? "hs-crypto" : null
) : null
Expand Down Expand Up @@ -57,6 +58,7 @@ resource "ibm_iam_authorization_policy" "kms_policy" {

# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
resource "time_sleep" "wait_for_authorization_policy" {
count = local.create_cross_account_auth_policy ? 1 : 0
depends_on = [ibm_iam_authorization_policy.kms_policy]
create_duration = "30s"
}
Expand Down Expand Up @@ -131,7 +133,7 @@ resource "random_password" "admin_password" {

# create a service authorization between Secrets Manager and the target service (Elastic Search)
resource "ibm_iam_authorization_policy" "secrets_manager_key_manager" {
count = var.skip_es_sm_auth_policy || var.existing_secrets_manager_instance_crn == null ? 0 : 1
count = local.create_sm_auth_policy
depends_on = [module.elasticsearch]
source_service_name = "secrets-manager"
source_resource_instance_id = local.existing_secrets_manager_instance_guid
Expand All @@ -143,6 +145,7 @@ resource "ibm_iam_authorization_policy" "secrets_manager_key_manager" {

# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
resource "time_sleep" "wait_for_es_authorization_policy" {
count = local.create_sm_auth_policy
depends_on = [ibm_iam_authorization_policy.secrets_manager_key_manager]
create_duration = "30s"
}
Expand Down