Skip to content

Commit

Permalink
Adding APM logging (oracle-terraform-modules#19)
Browse files Browse the repository at this point in the history
* feat: Adding APM logging
* fix: file headers
  • Loading branch information
karthicgit authored May 3, 2023
1 parent 968491b commit 523a9c9
Show file tree
Hide file tree
Showing 73 changed files with 337 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Learn how to [contribute][contributing].

## License

Copyright (c) 2019, 2021 Oracle and/or its associates.
Copyright (c) 2021 Oracle and/or its associates.

Licensed under the [Universal Permissive License 1.0][license] as shown at
[https://oss.oracle.com/licenses/upl][canonical_license].
Expand Down
7 changes: 5 additions & 2 deletions examples/lb_log/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0.0"
required_providers {
oci = {
source = "hashicorp/oci"
version = ">=4.38.0"
source = "oracle/oci"
version = ">= 4.67.3"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion examples/lb_log/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
compartment_id = ""
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

compartment_id = "<compartment OCID>"
lbname = ""
3 changes: 3 additions & 0 deletions examples/lb_log/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "compartment_id" {
type = string
description = "compartment id where to create the resources"
Expand Down
7 changes: 5 additions & 2 deletions examples/objectstorage_log/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0.0"
required_providers {
oci = {
source = "hashicorp/oci"
version = ">=4.38.0"
source = "oracle/oci"
version = ">= 4.67.3"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/objectstorage_log/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

bucket_name = "testbucket"
bucket_namespace = ""
compartment_id = ""
3 changes: 3 additions & 0 deletions examples/objectstorage_log/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "compartment_id" {
type = string
description = "compartment id where to create the resources"
Expand Down
7 changes: 5 additions & 2 deletions examples/vcnflow_log/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0.0"
required_providers {
oci = {
source = "hashicorp/oci"
version = ">=4.38.0"
source = "oracle/oci"
version = ">= 4.67.3"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/vcnflow_log/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

compartment_id = ""
3 changes: 3 additions & 0 deletions examples/vcnflow_log/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "compartment_id" {
type = string
description = "compartment id where to create the resources"
Expand Down
3 changes: 3 additions & 0 deletions examples/vcnflow_log/vcn/vcn.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

resource "oci_core_vcn" "test_vcn" {

compartment_id = var.compartment_id
Expand Down
6 changes: 6 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

locals {
apigwlogdef = { for k, v in var.service_logdef : k => v if v.service == "apigateway" }
apigwloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "apigateway"]

apmlogdef = { for k, v in var.service_logdef : k => v if v.service == "apm" }
apmloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "apm"]

devopslogdef = { for k, v in var.service_logdef : k => v if v.service == "devops" }
devopsloggroup = [for k, v in var.service_logdef : v.loggroup if v.service == "devops"]

Expand Down
27 changes: 27 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

#APIGateway loggroup resource
resource "oci_logging_log_group" "apigwloggroup" {

Expand All @@ -10,6 +13,18 @@ resource "oci_logging_log_group" "apigwloggroup" {

}

#APM loggroup resource
resource "oci_logging_log_group" "apmloggroup" {

for_each = toset(local.apmloggroup)

compartment_id = var.compartment_id
description = "APM Loggroup"
display_name = var.label_prefix == "none" ? each.value : format("%s-%s", var.label_prefix, each.value)
freeform_tags = var.loggroup_tags

}

#Devops loggroup
resource "oci_logging_log_group" "devopsloggroup" {

Expand Down Expand Up @@ -180,6 +195,18 @@ module "apigwlog" {

}

module "apmlog" {
source = "./modules/apm"
compartment_id = var.compartment_id
label_prefix = var.label_prefix
logdefinition = local.apmlogdef
log_retention_duration = var.log_retention_duration
loggroup = oci_logging_log_group.apmloggroup

count = length(local.apmlogdef) >= 1 ? 1 : 0

}

module "customlog" {
source = "./modules/custom"
compartment_id = var.compartment_id
Expand Down
3 changes: 3 additions & 0 deletions modules/apigateway/apigwlog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_apigateway_deployments" "apigw_deployments" {

for_each = var.logdefinition
Expand Down
3 changes: 3 additions & 0 deletions modules/apigateway/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "apigw_accesslogid" {
value = { for v in oci_logging_log.apigw_access_log : v.display_name => v.id }
}
Expand Down
3 changes: 3 additions & 0 deletions modules/apigateway/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "label_prefix" {
default = "none"
description = "A string that will be prepended to log resources."
Expand Down
3 changes: 3 additions & 0 deletions modules/apigateway/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
Expand Down
32 changes: 32 additions & 0 deletions modules/apm/apmlog.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_apm_apm_domains" "apm_domains" {
for_each = var.logdefinition
compartment_id = var.compartment_id

display_name = each.value.resource
state = "ACTIVE"
}

resource "oci_logging_log" "apm_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 = "dropped-data"
resource = data.oci_apm_apm_domains.apm_domains[each.key].apm_domains[0].id
service = "apm"
source_type = "OCISERVICE"
}
}

is_enabled = lookup(each.value, "enable", true)
retention_duration = var.log_retention_duration

}
10 changes: 10 additions & 0 deletions modules/apm/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "apm_logid" {
value = { for v in oci_logging_log.apm_log : v.display_name => v.id }
}

output "apm_loggroupid" {
value = { for k, v in var.loggroup : v.display_name => v.id }
}
26 changes: 26 additions & 0 deletions modules/apm/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

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"
}
12 changes: 12 additions & 0 deletions modules/apm/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.67.3"
}
}
required_version = ">= 1.0.0"
}
3 changes: 3 additions & 0 deletions modules/custom/customlog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

locals {
logdef = { for k, v in var.linux_logdef : k => v }
loggroup = [for k, v in var.linux_logdef : v.loggroup]
Expand Down
3 changes: 3 additions & 0 deletions modules/custom/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "linuxlogid" {
value = { for v in oci_logging_log.linux_log : v.display_name => v.id }
}
Expand Down
3 changes: 3 additions & 0 deletions modules/custom/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "label_prefix" {
default = "none"
description = "A string that will be prepended to log resources."
Expand Down
3 changes: 3 additions & 0 deletions modules/custom/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
Expand Down
3 changes: 3 additions & 0 deletions modules/devops/devopslog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_devops_projects" "devops_projects" {
for_each = var.logdefinition
compartment_id = var.compartment_id
Expand Down
3 changes: 3 additions & 0 deletions modules/devops/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "devops_logid" {
value = { for v in oci_logging_log.devops_log : v.display_name => v.id }
}
Expand Down
3 changes: 3 additions & 0 deletions modules/devops/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "label_prefix" {
default = "none"
description = "A string that will be prepended to log resources."
Expand Down
3 changes: 3 additions & 0 deletions modules/devops/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
Expand Down
3 changes: 3 additions & 0 deletions modules/emaildelivery/emaillog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_email_email_domains" "email_domains" {
for_each = var.logdefinition
compartment_id = var.compartment_id
Expand Down
3 changes: 3 additions & 0 deletions modules/emaildelivery/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "emaillogaccept_id" {
value = { for v in oci_logging_log.email_outboundaccepted_log : v.display_name => v.id }
}
Expand Down
3 changes: 3 additions & 0 deletions modules/emaildelivery/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "label_prefix" {
default = "none"
description = "A string that will be prepended to log resources."
Expand Down
3 changes: 3 additions & 0 deletions modules/emaildelivery/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
Expand Down
3 changes: 3 additions & 0 deletions modules/event/eventlog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_events_rules" "event_rules" {
for_each = var.logdefinition
compartment_id = var.compartment_id
Expand Down
3 changes: 3 additions & 0 deletions modules/event/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "event_logid" {
value = { for v in oci_logging_log.ruleexecution_log : v.display_name => v.id }
}
Expand Down
3 changes: 3 additions & 0 deletions modules/event/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "label_prefix" {
default = "none"
description = "A string that will be prepended to log resources."
Expand Down
3 changes: 3 additions & 0 deletions modules/event/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
Expand Down
3 changes: 3 additions & 0 deletions modules/function/functionlog.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

data "oci_functions_applications" "func_apps" {

for_each = var.logdefinition
Expand Down
Loading

0 comments on commit 523a9c9

Please sign in to comment.