Skip to content

Commit

Permalink
Merge pull request #8 from oracle-devrel/develop
Browse files Browse the repository at this point in the history
v2024.4.1
  • Loading branch information
xs2suruchi authored Sep 19, 2024
2 parents 7f319b6 + e60203a commit e037c31
Show file tree
Hide file tree
Showing 156 changed files with 11,893 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
.AppleDouble
.LSOverride
.terraform

# Icon must end with two \r
Icon
Expand Down
24 changes: 24 additions & 0 deletions examples/budget/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
/*This line will be removed when using remote state
# !!! WARNING !!! Terraform State Lock is not supported with OCI Object Storage.
# Pre-Requisite: Create a version enabled object storage bucket to store the state file.
# End Point Format: https://<namespace>.compat.objectstorage.<region>.oraclecloud.com
# Please look at the below doc for information about shared_credentials_file and other parameters:
# Reference: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformUsingObjectStore.htm
terraform {
backend "s3" {
key = "phoenix/budget/terraform.tfstate"
bucket = "<Object Storage Bucket Name>"
region = "<region>"
endpoint = "<Object Storage Bucket End Point>"
shared_credentials_file = "~/.aws/credentials"
skip_region_validation = true
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}
This line will be removed when using remote state*/
63 changes: 63 additions & 0 deletions examples/budget/budget.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
############################
# Module Block - Cost Management
# Create Budgets and Rule Alerts
############################

#locals {
# comp_ocids = {for key, val in var.budgets : key => [
# var.compartment_ocids[flatten([for targets in val.targets : targets])[0]]
# ] if val.target_type == "COMPARTMENT" }
#}



module "budget-alert-rules" {
source = "git::https://github.com/oracle-devrel/terraform-oci-cd3.git//modules/costmanagement/budget-alert-rule?ref=v2024.4.0"
for_each = var.budget_alert_rules

#Required
budget_id = length(regexall("ocid1.budget.oc*", each.value.budget_id)) > 0 ? each.value.budget_id : merge(module.budgets.*...)[each.value.budget_id]["budget_tf_id"]
threshold = each.value.threshold
threshold_type = each.value.threshold_type
type = each.value.type

#Optional
description = each.value.description
display_name = each.value.display_name
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
message = each.value.message
recipients = each.value.recipients
}

module "budgets" {
source = "git::https://github.com/oracle-devrel/terraform-oci-cd3.git//modules/costmanagement/budget?ref=v2024.4.0"
for_each = var.budgets

#Required
amount = each.value.amount
compartment_id = each.value.compartment_id != null ? (length(regexall("ocid1.compartment.oc*", each.value.compartment_id)) > 0 ? each.value.compartment_id : var.compartment_ocids[each.value.compartment_id]) : var.tenancy_ocid

reset_period = each.value.reset_period != null ? each.value.reset_period : "MONTHLY"

#Optional
budget_processing_period_start_offset = each.value.budget_processing_period_start_offset
description = each.value.description
display_name = each.value.display_name
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
processing_period_type = each.value.processing_period_type
budget_start_date = each.value.processing_period_type == "SINGLE_USE" ? each.value.budget_start_date : null
budget_end_date = each.value.processing_period_type == "SINGLE_USE" ? each.value.budget_end_date : null

#target_compartment_id = each.value.target_compartment_id != null ? (length(regexall("ocid1.compartment.oc*", each.value.target_compartment_id)) > 0 ? each.value.target_compartment_id : var.compartment_ocids[each.value.target_compartment_id]) : null

target_type = each.value.target_type
#targets = each.value.targets

targets = each.value.target_type == "COMPARTMENT" ? (length(regexall("ocid1.compartment.oc*", each.value.targets[0])) > 0 ? each.value.targets : [var.compartment_ocids[each.value.targets[0]]]) : each.value.targets

}
43 changes: 43 additions & 0 deletions examples/budget/oci-data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
############################
# Resource Block - Identity
# Fetch Compartments
############################

#Fetch Compartment Details
data "oci_identity_compartments" "compartments" {
#Required
compartment_id = var.tenancy_ocid

#Optional
#name = var.compartment_name
access_level = "ANY"
compartment_id_in_subtree = true
state = "ACTIVE"
}


############################
# Data Block - Network
# Fetch ADs
############################

data "oci_identity_availability_domains" "availability_domains" {
#Required
compartment_id = var.tenancy_ocid
}


/*
output "compartment_id_map" {
description = "Compartment ocid"
// This allows the compartment ID to be retrieved from the resource if it exists, and if not to use the data source.
value = zipmap(data.oci_identity_compartments.compartments.compartments.*.name,data.oci_identity_compartments.compartments.compartments.*.id)
}
output "ads" {
value = data.oci_identity_availability_domains.availability_domains.availability_domains.*.name
}
*/
25 changes: 25 additions & 0 deletions examples/budget/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
############################
# Provider Block
# OCI
############################

provider "oci" {
tenancy_ocid = var.tenancy_ocid
user_ocid = var.user_ocid
fingerprint = var.fingerprint
private_key_path = var.private_key_path
region = var.region
ignore_defined_tags = ["Oracle-Tags.CreatedBy", "Oracle-Tags.CreatedOn"]
}

terraform {
required_providers {
oci = {
source = "oracle/oci"
version = "6.3.0"
}
}
}
76 changes: 76 additions & 0 deletions examples/budget/sample_budgets.auto.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
############################
# Governance
# Create Budgets
# Allowed Values:
# compartment_id can be the ocid or the name of the compartment hierarchy delimited by double hiphens "--"
# budget_end_date and budget_start_date are mandatory for budgets of "SINGLE USE" type
# budget_processing_period_start_offset is mandatory for budgets of "MONTH" type
# target_type - supported values are "TAG"/"COMPARTMENT"
# for COMPARTMENT type target, targets value should be list of compartment ocid or the name of the compartment hierarchy delimited by double hiphens "--"
# for TAG type target, targets value should be list of <tag-namespace.tag-key.tag-value>
# Sample import command :
# terraform import "module.budgets[\"<<budget terraform variable name>>\"].oci_budget_budget.budget" <budget ocid>
############################
budgets = {
Budget1 = {
compartment_id = "root"
amount = 10
reset_period = "MONTHLY"
description = "demo budget1"
display_name = "Budget1"
processing_period_type = "SINGLE_USE"
budget_start_date = "2024-06-01"
budget_end_date = "2024-06-11"
target_type = "COMPARTMENT"
targets = ["root"]
},
Budget2 = {
compartment_id = "root"
amount = 100
reset_period = "MONTHLY"
description = "demo budget 2"
budget_processing_period_start_offset = "5"
display_name = "Budget2"
processing_period_type = "MONTH"
target_type = "TAG"
targets = ["Operations.CostCenter.01"]
},
}

############################
# Governance
# Create Budget Alert Rules
# Allowed Values:
# budget_id = <budget name or ocid>
# type = <ACTUAL/FORECAST>
# threshold = <threshold value>
# threshold_type = <ABSOLUTE/PERCENTAGE>
# Sample import command :
# terraform import "module.budget-alert-rules[\"<< budget alert rule terraform variable name>>\"].oci_budget_alert_rule.alert_rule" budgets/<budget ocid>/alertRules/<budget alert rule ocid>
############################
budget_alert_rules = {
"Budget2_ACTUAL_PERCENTAGE_70-0" = {
budget_id = "Budget2"
type = "ACTUAL"
threshold = "70.0"
threshold_type = "PERCENTAGE"
},
"Budget2_ACTUAL_PERCENTAGE_100" = {
budget_id = "Budget2"
type = "ACTUAL"
threshold = "100"
threshold_type = "PERCENTAGE"
message = "test message"
recipients = "[email protected],[email protected]"
},
"Budget2_FORECAST_ABSOLUTE_20-0" = {
budget_id = "Budget2"
type = "FORECAST"
threshold = "20.0"
threshold_type = "ABSOLUTE"
recipients = "[email protected]"
},
}
93 changes: 93 additions & 0 deletions examples/budget/variables_phoenix.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
############################
#
# Variables Block
# OCI
#
############################

variable "tenancy_ocid" {
type = string
default = "<TENANCY OCID HERE>"
}

variable "user_ocid" {
type = string
default = "<USER OCID HERE>"
}

variable "fingerprint" {
type = string
default = "<SSH KEY FINGERPRINT HERE>"
}

variable "private_key_path" {
type = string
default = "<SSH PRIVATE KEY FULL PATH HERE>"
}

variable "region" {
type = string
default = "<OCI TENANCY REGION HERE eg: us-phoenix-1 or us-ashburn-1>"
}

#################################
#
# Variables according to Services
# PLEASE DO NOT MODIFY
#
#################################

##########################
## Fetch Compartments ####
##########################

variable "compartment_ocids" {
type = map(any)
default = {
#START_compartment_ocids#
root = "ocid1.tenancy.oc1..aaaaaaaa5ob2e73i4bavdqrbrch25odbfbdbfbbcuxiies2dgpwdinmrmel3a"
compartment1 = "ocid1.compartment.oc1..aaaaaaaa5tx27cqohsryhdhdfdf6nubepnm6j3wsllkhxf4xjl4hoa"
#compartment_ocids_END#
}
}
###########################
######### Budgets #########
###########################

variable "budgets" {
type = map(object({
amount = string
compartment_id = string
reset_period = string
budget_processing_period_start_offset = optional(string)
defined_tags = optional(map(any))
description = optional(string)
display_name = optional(string)
freeform_tags = optional(map(any))
processing_period_type = optional(string)
budget_end_date = optional(string)
budget_start_date = optional(string)
target_type = optional(string)
targets = optional(list(any))
}))
default = {}
}

variable "budget_alert_rules" {
type = map(object({
budget_id = string
threshold = string
threshold_type = string
type = string
defined_tags = optional(map(any))
description = optional(string)
display_name = optional(string)
freeform_tags = optional(map(any))
message = optional(string)
recipients = optional(string)
}))
default = {}
}
24 changes: 24 additions & 0 deletions examples/compute/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
/*This line will be removed when using remote state
# !!! WARNING !!! Terraform State Lock is not supported with OCI Object Storage.
# Pre-Requisite: Create a version enabled object storage bucket to store the state file.
# End Point Format: https://<namespace>.compat.objectstorage.<region>.oraclecloud.com
# Please look at the below doc for information about shared_credentials_file and other parameters:
# Reference: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformUsingObjectStore.htm
terraform {
backend "s3" {
key = "phoenix/compute/terraform.tfstate"
bucket = "<Object Storage Bucket Name>"
region = "<region>"
endpoint = "<Object Storage Bucket End Point>"
shared_credentials_file = "~/.aws/credentials"
skip_region_validation = true
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}
This line will be removed when using remote state*/
Loading

0 comments on commit e037c31

Please sign in to comment.