diff --git a/.secrets.baseline b/.secrets.baseline index fcab9952..ca54a3d6 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$", "lines": null }, - "generated_at": "2023-12-11T06:39:44Z", + "generated_at": "2023-12-12T06:39:44Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/solutions/instances/main.tf b/solutions/instances/main.tf index 96ab64f2..4c2fbbc9 100644 --- a/solutions/instances/main.tf +++ b/solutions/instances/main.tf @@ -38,7 +38,11 @@ locals { kms_region = ((length(coalesce(local.buckets_config, [])) != 0) ? (var.existing_cos_kms_key_crn == null ? module.kms_instance_crn_parser[0].region : null) : null) - cos_kms_key_crn = var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : length(coalesce(local.buckets_config, [])) != 0 ? module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn : null + cos_kms_key_crn = var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : length(coalesce(local.buckets_config, [])) != 0 ? module.kms[0].keys[format("%s.%s", local.cos_key_ring_name, local.cos_key_name)].crn : null + parsed_kms_key_crn = local.cos_kms_key_crn != null ? split(":", local.cos_kms_key_crn) : [] + cos_kms_key_id = length(local.parsed_kms_key_crn) > 0 ? local.parsed_kms_key_crn[9] : null + cos_kms_scope = length(local.parsed_kms_key_crn) > 0 ? local.parsed_kms_key_crn[6] : null + kms_account_id = length(local.parsed_kms_key_crn) > 0 ? split("/", local.cos_kms_scope)[1] : null cos_target_bucket_name = var.existing_at_cos_target_bucket_name != null ? var.existing_at_cos_target_bucket_name : var.enable_at_event_routing_to_cos_bucket ? module.cos_bucket[0].buckets[local.at_cos_target_bucket_name].bucket_name : null cos_resource_group_id = var.cos_resource_group_name != null ? module.cos_resource_group[0].resource_group_id : module.resource_group.resource_group_id @@ -350,7 +354,7 @@ resource "time_sleep" "wait_for_authorization_policy" { create_duration = "30s" } -# Data source to account settings for retrieving cross account id +# Data source to account settings for retrieving COS cross account id data "ibm_iam_account_settings" "iam_cos_account_settings" { provider = ibm.cos } @@ -365,10 +369,38 @@ resource "ibm_iam_authorization_policy" "policy" { source_service_account = data.ibm_iam_account_settings.iam_cos_account_settings.account_id source_service_name = "cloud-object-storage" source_resource_instance_id = local.cos_instance_guid - target_service_name = local.kms_service - target_resource_instance_id = local.existing_kms_guid roles = ["Reader"] - description = "Allow the COS instance with GUID ${local.cos_instance_guid} reader access to the kms_service instance GUID ${local.existing_kms_guid}" + description = "Allow the COS instance ${local.cos_instance_guid} to read the ${local.kms_service} key ${local.cos_kms_key_id} from the instance ${local.existing_kms_guid}" + resource_attributes { + name = "serviceName" + operator = "stringEquals" + value = local.kms_service + } + resource_attributes { + name = "accountId" + operator = "stringEquals" + value = local.kms_account_id + } + resource_attributes { + name = "serviceInstance" + operator = "stringEquals" + value = local.existing_kms_guid + } + resource_attributes { + name = "resourceType" + operator = "stringEquals" + value = "key" + } + resource_attributes { + name = "resource" + operator = "stringEquals" + value = local.cos_kms_key_id + } + # Scope of policy now includes the key, so ensure to create new policy before + # destroying old one to prevent any disruption to every day services. + lifecycle { + create_before_destroy = true + } } module "cos_instance" { @@ -377,7 +409,7 @@ module "cos_instance" { } count = var.existing_cos_instance_crn == null && length(coalesce(local.buckets_config, [])) != 0 ? 1 : 0 # no need to call COS module if consumer is using existing COS instance source = "terraform-ibm-modules/cos/ibm//modules/fscloud" - version = "8.11.11" + version = "8.14.1" resource_group_id = local.cos_resource_group_id create_cos_instance = true cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name @@ -394,7 +426,7 @@ module "cos_bucket" { } count = length(coalesce(local.buckets_config, [])) != 0 ? 1 : 0 # no need to call COS module if consumer is using existing COS bucket source = "terraform-ibm-modules/cos/ibm//modules/buckets" - version = "8.11.11" + version = "8.14.1" bucket_configs = [ for value in local.buckets_config : {