|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | + |
| 5 | +variable "tenancy_ocid" {} |
| 6 | +variable "user_ocid" {} |
| 7 | +variable "fingerprint" {} |
| 8 | +variable "private_key_path" {} |
| 9 | +variable "region" {} |
| 10 | +variable "compartment_ocid" {} |
| 11 | + |
| 12 | + |
| 13 | +provider "oci" { |
| 14 | + tenancy_ocid = var.tenancy_ocid |
| 15 | + user_ocid = var.user_ocid |
| 16 | + fingerprint = var.fingerprint |
| 17 | + private_key_path = var.private_key_path |
| 18 | + region = var.region |
| 19 | +} |
| 20 | + |
| 21 | +data "oci_objectstorage_namespace" "test_namespace" { |
| 22 | + compartment_id = var.compartment_ocid |
| 23 | +} |
| 24 | + |
| 25 | +variable "bucket_name" { |
| 26 | + default = "awrhub_bucket" |
| 27 | +} |
| 28 | + |
| 29 | +resource "oci_objectstorage_bucket" "test_bucket" { |
| 30 | + name = var.bucket_name |
| 31 | + compartment_id = var.compartment_ocid |
| 32 | + namespace = data.oci_objectstorage_namespace.test_namespace.namespace |
| 33 | +} |
| 34 | + |
| 35 | +resource "oci_identity_tag_namespace" "tag-namespace1" { |
| 36 | + compartment_id = var.tenancy_ocid |
| 37 | + description = "example tag namespace" |
| 38 | + name = "examples-tag-namespace-all" |
| 39 | + is_retired = false |
| 40 | +} |
| 41 | + |
| 42 | +resource "oci_identity_tag" "tag1" { |
| 43 | + description = "example tag" |
| 44 | + name = "example-tag" |
| 45 | + tag_namespace_id = oci_identity_tag_namespace.tag-namespace1.id |
| 46 | + is_cost_tracking = false |
| 47 | + is_retired = false |
| 48 | +} |
| 49 | + |
| 50 | +variable "awrhub_defined_tags_value" { |
| 51 | + default = "awrhub_tag_value" |
| 52 | +} |
| 53 | + |
| 54 | +variable "awrhub_display_name" { |
| 55 | + default = "TestAwrhubDisplayName" |
| 56 | +} |
| 57 | + |
| 58 | +variable "awrhub_freeform_tags" { |
| 59 | + default = { "bar-key" = "value" } |
| 60 | +} |
| 61 | + |
| 62 | +variable "awrhub_state" { |
| 63 | + default = ["ACTIVE"] |
| 64 | +} |
| 65 | + |
| 66 | +variable "warehouse_defined_tags_value" { |
| 67 | + default = "warehouse_tag_value" |
| 68 | +} |
| 69 | + |
| 70 | +variable "warehouse_freeform_tags" { |
| 71 | + default = { "bar-key" = "value" } |
| 72 | +} |
| 73 | + |
| 74 | +variable "warehouse_display_name" { |
| 75 | + default = "TestWarehouseDisplayName" |
| 76 | +} |
| 77 | + |
| 78 | +variable "warehouse_cpu_allocated" { |
| 79 | + default = 1.0 |
| 80 | +} |
| 81 | + |
| 82 | +variable "storage_allocated_in_gbs" { |
| 83 | + default = 1.0 |
| 84 | +} |
| 85 | + |
| 86 | +// To Create a Warehouse |
| 87 | +resource "oci_opsi_operations_insights_warehouse" "test_operations_insights_warehouse" { |
| 88 | + #Required |
| 89 | + compartment_id = var.compartment_ocid |
| 90 | + cpu_allocated = var.warehouse_cpu_allocated |
| 91 | + display_name = var.warehouse_display_name |
| 92 | + |
| 93 | + #Optional |
| 94 | + defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.warehouse_defined_tags_value}")}" |
| 95 | + freeform_tags = var.warehouse_freeform_tags |
| 96 | + storage_allocated_in_gbs = var.storage_allocated_in_gbs |
| 97 | +} |
| 98 | + |
| 99 | +// To Create a awrhub |
| 100 | +resource "oci_opsi_awr_hub" "test_awr_hub" { |
| 101 | + #Required |
| 102 | + compartment_id = var.compartment_ocid |
| 103 | + display_name = var.awrhub_display_name |
| 104 | + object_storage_bucket_name = oci_objectstorage_bucket.test_bucket.name |
| 105 | + operations_insights_warehouse_id = oci_opsi_operations_insights_warehouse.test_operations_insights_warehouse.id |
| 106 | + |
| 107 | + #Optional |
| 108 | + defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.awrhub_defined_tags_value}")}" |
| 109 | + freeform_tags = var.awrhub_freeform_tags |
| 110 | +} |
| 111 | + |
| 112 | +output "awr_hub_id" { |
| 113 | + value = oci_opsi_awr_hub.test_awr_hub.id |
| 114 | +} |
| 115 | + |
| 116 | +// List awrhub present under a compartment having state ACTIVE |
| 117 | +data "oci_opsi_awr_hubs" "test_awr_hubs" { |
| 118 | + operations_insights_warehouse_id = oci_opsi_operations_insights_warehouse.test_operations_insights_warehouse.id |
| 119 | + compartment_id = var.compartment_ocid |
| 120 | + state = var.awrhub_state |
| 121 | +} |
| 122 | + |
| 123 | +// Get awrhub for a particular id |
| 124 | +data "oci_opsi_awr_hub" "test_awr_hub" { |
| 125 | + awr_hub_id = oci_opsi_awr_hub.test_awr_hub.id |
| 126 | +} |
| 127 | + |
| 128 | +// Get source summary for a particular AWR Hub id |
| 129 | +data "oci_opsi_awr_hub_awr_sources_summary" "test_awr_hub_awr_sources_summary" { |
| 130 | + awr_hub_id = oci_opsi_awr_hub.test_awr_hub.id |
| 131 | +} |
| 132 | + |
| 133 | +output "source_summary_output" { |
| 134 | + value = length(data.oci_opsi_awr_hub_awr_sources_summary.test_awr_hub_awr_sources_summary) |
| 135 | +} |
| 136 | + |
| 137 | +variable "awr_source_database_identifier" { |
| 138 | + default = "12345" |
| 139 | +} |
| 140 | + |
| 141 | +// Get snapshots summary for a particular AWR Hub id |
| 142 | +data "oci_opsi_awr_hub_awr_snapshots" "test_awr_hub_awr_snapshots" { |
| 143 | + awr_hub_id = oci_opsi_awr_hub.test_awr_hub.id |
| 144 | + awr_source_database_identifier = var.awr_source_database_identifier |
| 145 | +} |
| 146 | + |
| 147 | +output "snapshots_summary_output" { |
| 148 | + value = length(data.oci_opsi_awr_hub_awr_snapshots.test_awr_hub_awr_snapshots) |
| 149 | +} |
0 commit comments