# compliance-evaluation / oci / t1 "Standard" # # Cloud Guard for the whole tenancy with Oracle's configuration, activity, and # threat detector recipes, an email for problems at the risk levels you pick, # and an email whenever someone dismisses a problem, since a dismissal is a # decision someone should be able to account for. locals { tags = merge({ owner = var.owner environment = var.environment data_classification = "internal" managed_by = "terraform" }, var.extra_tags) } # The permissions Oracle documents for Cloud Guard to read what it checks. resource "oci_identity_policy" "cloud_guard" { compartment_id = var.tenancy_ocid name = "cloud-guard" description = "Lets Cloud Guard read the resources it evaluates." freeform_tags = local.tags statements = [ "allow service cloudguard to manage cloudevents-rules in tenancy where target.rule.type='managed'", "allow service cloudguard to read audit-events in tenancy", "allow service cloudguard to read authentication-policies in tenancy", "allow service cloudguard to read autonomous-database-family in tenancy", "allow service cloudguard to read compartments in tenancy", "allow service cloudguard to read compute-management-family in tenancy", "allow service cloudguard to read database-family in tenancy", "allow service cloudguard to read data-safe-family in tenancy", "allow service cloudguard to read dynamic-groups in tenancy", "allow service cloudguard to read groups in tenancy", "allow service cloudguard to read instance-family in tenancy", "allow service cloudguard to read keys in tenancy", "allow service cloudguard to read load-balancers in tenancy", "allow service cloudguard to read log-groups in tenancy", "allow service cloudguard to read object-family in tenancy", "allow service cloudguard to read policies in tenancy", "allow service cloudguard to read tenancies in tenancy", "allow service cloudguard to read users in tenancy", "allow service cloudguard to read vaults in tenancy", "allow service cloudguard to read virtual-network-family in tenancy", "allow service cloudguard to read volume-family in tenancy", "allow service cloudguard to use network-security-groups in tenancy", ] } resource "oci_cloud_guard_cloud_guard_configuration" "this" { compartment_id = var.tenancy_ocid reporting_region = var.region status = "ENABLED" depends_on = [oci_identity_policy.cloud_guard] } data "oci_cloud_guard_detector_recipes" "oracle" { compartment_id = var.tenancy_ocid depends_on = [oci_cloud_guard_cloud_guard_configuration.this] } locals { oracle_recipes = { for r in data.oci_cloud_guard_detector_recipes.oracle.detector_recipe_collection[0].items : r.detector => r.id if r.owner == "ORACLE" } } resource "oci_cloud_guard_target" "tenancy" { compartment_id = var.tenancy_ocid display_name = "tenancy" target_resource_id = var.tenancy_ocid target_resource_type = "COMPARTMENT" freeform_tags = local.tags dynamic "target_detector_recipes" { for_each = var.detectors content { detector_recipe_id = local.oracle_recipes[target_detector_recipes.value] } } } resource "oci_ons_notification_topic" "problems" { compartment_id = var.tenancy_ocid name = "cloud-guard-problems" description = "Cloud Guard problems at the chosen risk levels, and dismissals." freeform_tags = local.tags } resource "oci_ons_subscription" "email" { compartment_id = var.tenancy_ocid topic_id = oci_ons_notification_topic.problems.id protocol = "EMAIL" endpoint = var.alert_email freeform_tags = local.tags } resource "oci_events_rule" "problems" { compartment_id = var.tenancy_ocid display_name = "cloud-guard-problem-detected" description = "Emails new Cloud Guard problems at the chosen risk levels." is_enabled = true freeform_tags = local.tags condition = jsonencode({ eventType = ["com.oraclecloud.cloudguard.problemdetected"] data = { additionalDetails = { riskLevel = var.alert_risk_levels } } }) actions { actions { action_type = "ONS" is_enabled = true topic_id = oci_ons_notification_topic.problems.id } } } resource "oci_events_rule" "dismissed" { compartment_id = var.tenancy_ocid display_name = "cloud-guard-problem-dismissed" description = "Emails every dismissed Cloud Guard problem, at any risk level." is_enabled = true freeform_tags = local.tags condition = jsonencode({ eventType = ["com.oraclecloud.cloudguard.problemdismissed"] }) actions { actions { action_type = "ONS" is_enabled = true topic_id = oci_ons_notification_topic.problems.id } } }