Skip to content

Commit

Permalink
fix: remove lookup of IAM account settings to fetch account ID as thi…
Browse files Browse the repository at this point in the history
…s requires admin privileges (#751)
  • Loading branch information
Soaib024 authored Oct 21, 2024
1 parent 62c5981 commit fb0cc4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions solutions/secure-cross-regional-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,22 @@ locals {
}]
}


#######################################################################################################################
# KMS Key
#######################################################################################################################

data "ibm_iam_account_settings" "iam_account_settings" {
count = local.create_cross_account_auth_policy ? 1 : 0
provider = ibm.cos
module "cos_crn_parser" {
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
version = "1.1.0"
crn = var.existing_cos_instance_id
}

# Create IAM Authorization Policy to allow COS to access KMS for the encryption key
resource "ibm_iam_authorization_policy" "cos_kms_policy" {
count = local.create_cross_account_auth_policy ? 1 : 0
provider = ibm.kms
source_service_account = data.ibm_iam_account_settings.iam_account_settings[0].account_id
source_service_account = module.cos_crn_parser.account_id
source_service_name = "cloud-object-storage"
source_resource_instance_id = local.cos_instance_guid
target_service_name = local.kms_service_name
Expand Down
9 changes: 5 additions & 4 deletions solutions/secure-regional-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ locals {
#######################################################################################################################
# KMS Key
#######################################################################################################################
data "ibm_iam_account_settings" "iam_account_settings" {
count = local.create_cross_account_auth_policy ? 1 : 0
provider = ibm.cos
module "cos_crn_parser" {
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
version = "1.1.0"
crn = var.existing_cos_instance_id
}

# Create IAM Authorization Policy to allow COS to access KMS for the encryption key
resource "ibm_iam_authorization_policy" "cos_kms_policy" {
count = local.create_cross_account_auth_policy ? 1 : 0
provider = ibm.kms
source_service_account = data.ibm_iam_account_settings.iam_account_settings[0].account_id
source_service_account = module.cos_crn_parser.account_id
source_service_name = "cloud-object-storage"
source_resource_instance_id = local.cos_instance_guid
target_service_name = local.kms_service_name
Expand Down

0 comments on commit fb0cc4d

Please sign in to comment.