# Customer-managed key for the bucket. # # Object Storage encrypts with the key as a service, per region, and that # service has to be named in a policy before it can use the key. On a first # apply the policy can take a minute to take effect and bucket creation can # fail. Running apply again is the fix. # # Deleting a vault or key in OCI schedules the deletion after a waiting period # of at least seven days, during which it can be cancelled. resource "oci_kms_vault" "audit" { compartment_id = var.compartment_ocid display_name = "${var.name}-vault" vault_type = "DEFAULT" freeform_tags = local.tags } resource "oci_kms_key" "audit" { compartment_id = var.compartment_ocid display_name = "${var.name}-storage" management_endpoint = oci_kms_vault.audit.management_endpoint protection_mode = "HSM" freeform_tags = local.tags key_shape { algorithm = "AES" length = 32 } } resource "oci_identity_policy" "storage_uses_key" { compartment_id = var.tenancy_ocid name = "${var.name}-storage-key" description = "Lets Object Storage in this region use the audit bucket key, and only that key." freeform_tags = local.tags statements = [ "Allow service objectstorage-${var.region} to use keys in compartment id ${var.compartment_ocid} where target.key.id = '${oci_kms_key.audit.id}'", ] }