diff --git a/locals.tf b/locals.tf index 5a85455..13a5e5d 100644 --- a/locals.tf +++ b/locals.tf @@ -14,6 +14,9 @@ locals { funclogdef = { for k, v in var.service_logdef : k => v if v.service == "functions" } funcloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "functions"] + intlogdef = { for k, v in var.service_logdef : k => v if v.service == "integration" } + intloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "integration"] + lblogdef = { for k, v in var.service_logdef : k => v if v.service == "loadbalancer" } lbloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "loadbalancer"] diff --git a/main.tf b/main.tf index c527936..f5d78ad 100644 --- a/main.tf +++ b/main.tf @@ -58,6 +58,18 @@ resource "oci_logging_log_group" "funcloggroup" { } +#Integration loggroup resource +resource "oci_logging_log_group" "intloggroup" { + + for_each = toset(local.intloggroup) + + compartment_id = var.compartment_id + description = "Integration Loggroup" + display_name = var.label_prefix == "none" ? each.value : format("%s-%s", var.label_prefix, each.value) + freeform_tags = var.loggroup_tags + +} + #Loadbalancer loggroup resource resource "oci_logging_log_group" "lbloggroup" { @@ -206,6 +218,17 @@ module "funclog" { } +module "intlog" { + source = "./modules/integration" + compartment_id = var.compartment_id + label_prefix = var.label_prefix + logdefinition = local.intlogdef + log_retention_duration = var.log_retention_duration + loggroup = oci_logging_log_group.intloggroup + + count = length(local.intlogdef) >= 1 ? 1 : 0 + +} module "lblog" { source = "./modules/lb" compartment_id = var.compartment_id diff --git a/modules/integration/intlog.tf b/modules/integration/intlog.tf new file mode 100644 index 0000000..9d6d6c5 --- /dev/null +++ b/modules/integration/intlog.tf @@ -0,0 +1,28 @@ +data "oci_integration_integration_instances" "integration_instances" { + for_each = var.logdefinition + compartment_id = var.compartment_id + + #Optional + display_name = each.value.resource + state = "ACTIVE" +} + +resource "oci_logging_log" "integration_log" { + for_each = var.logdefinition + + display_name = var.label_prefix == "none" ? each.key : format("%s-%s", var.label_prefix, each.key) + log_group_id = var.loggroup[each.value.loggroup].id + log_type = "SERVICE" + configuration { + source { + category = "activitystream" + resource = data.oci_integration_integration_instances.integration_instances[each.key].integration_instances.0.id + service = "integration" + source_type = "OCISERVICE" + } + } + + is_enabled = lookup(each.value, "enable", true) + retention_duration = var.log_retention_duration + +} diff --git a/modules/integration/outputs.tf b/modules/integration/outputs.tf new file mode 100644 index 0000000..6a8dec0 --- /dev/null +++ b/modules/integration/outputs.tf @@ -0,0 +1,7 @@ +output "int_logid" { + value = { for v in oci_logging_log.integration_log : v.display_name => v.id } +} + +output "int_loggroupid" { + value = { for k, v in var.loggroup : v.display_name => v.id } +} diff --git a/modules/integration/variables.tf b/modules/integration/variables.tf new file mode 100644 index 0000000..864efd5 --- /dev/null +++ b/modules/integration/variables.tf @@ -0,0 +1,23 @@ +variable "label_prefix" { + default = "none" + description = "A string that will be prepended to log resources." + type = string +} +variable "logdefinition" { + type = map(any) + description = "Log definition" +} +variable "log_retention_duration" { + type = string + description = "Duration to retain logs" +} + +variable "compartment_id" { + type = string + description = "Compartment ID where the resources will be created" +} + +variable "loggroup" { + type = map(any) + description = "Log Group" +} diff --git a/outputs.tf b/outputs.tf index 4b0791a..92f44b1 100644 --- a/outputs.tf +++ b/outputs.tf @@ -65,6 +65,17 @@ output "func_loggroupid" { description = "Function loggroup id" } +#Integration log and loggroup id +output "int_logid" { + value = try(module.intlog[0].int_logid, "") + description = "Integration logs id" +} + +output "int_loggroupid" { + value = try(module.intlog[0].int_loggroupid, "") + description = "Integration loggroup id" +} + #Loadbalancer log and loggroup id output "lb_accesslogid" { value = try(module.lblog[0].lb_accesslogid, "") diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 3642868..68075e6 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -28,6 +28,7 @@ service_logdef = { #vpnlog ={loggroup="vpnloggroup",service="vpn",resource=""} #devopslog = {loggroup="devopsloggroup",service="devops",resource=""} #emaillog = {loggroup="emailloggroup",service="email",resource=""} + #intlog = {loggroup="intloggroup",service="integration",resource=""} }