Skip to content

Commit

Permalink
adding integration service log (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthicgit authored Oct 18, 2021
1 parent a007c40 commit 9d24afb
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
23 changes: 23 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {

Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions modules/integration/intlog.tf
Original file line number Diff line number Diff line change
@@ -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

}
7 changes: 7 additions & 0 deletions modules/integration/outputs.tf
Original file line number Diff line number Diff line change
@@ -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 }
}
23 changes: 23 additions & 0 deletions modules/integration/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 11 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
1 change: 1 addition & 0 deletions terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ service_logdef = {
#vpnlog ={loggroup="vpnloggroup",service="vpn",resource="<ipsecname>"}
#devopslog = {loggroup="devopsloggroup",service="devops",resource="<projectname>"}
#emaillog = {loggroup="emailloggroup",service="email",resource="<emaildomain>"}
#intlog = {loggroup="intloggroup",service="integration",resource="<integrationinstance>"}

}

Expand Down

0 comments on commit 9d24afb

Please sign in to comment.