From 3023d2ac6cbe03bde2038104d694313d12342920 Mon Sep 17 00:00:00 2001 From: Krishnadhas N K <108367225+githubofkrishnadhas@users.noreply.github.com> Date: Sat, 21 Sep 2024 15:48:01 +0530 Subject: [PATCH] DEVOPS-280 loganalytics terraform module initial commit (#10) * DEVOPS-280 loganalytics terraform module initial commit * DEVOPS-280 loganalytics terraform module initial commit --- log-analytics-workspace/loganalytics.tf | 18 ++++++++ log-analytics-workspace/output.tf | 19 +++++++++ log-analytics-workspace/providers.tf | 12 ++++++ log-analytics-workspace/variables.tf | 55 +++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 log-analytics-workspace/loganalytics.tf create mode 100644 log-analytics-workspace/output.tf create mode 100644 log-analytics-workspace/providers.tf create mode 100644 log-analytics-workspace/variables.tf diff --git a/log-analytics-workspace/loganalytics.tf b/log-analytics-workspace/loganalytics.tf new file mode 100644 index 0000000..844aeaa --- /dev/null +++ b/log-analytics-workspace/loganalytics.tf @@ -0,0 +1,18 @@ +resource "azurerm_resource_group" "rg" { + name = upper(var.resource_group_name) + location = var.location + tags = { + Environment = upper(var.environment) + Orchestrator = "Terraform" + DisplayName = upper(var.resource_group_name) + ApplicationName = lower(var.application_name) + } +} + +resource "azurerm_log_analytics_workspace" "loganalytics_ws" { + name = upper(var.loganalytics_workspace_name) + sku = var.loganalytics_sku + resource_group_name = azurerm_resource_group.rg.name + location = var.location + retention_in_days = var.loganalytics_retention_period +} diff --git a/log-analytics-workspace/output.tf b/log-analytics-workspace/output.tf new file mode 100644 index 0000000..56738eb --- /dev/null +++ b/log-analytics-workspace/output.tf @@ -0,0 +1,19 @@ +output "loganalytics_workspace_name" { + value = azurerm_log_analytics_workspace.loganalytics_ws.name + description = "Azure Log analytics workspace name" +} + +output "loganalytics_workspace_resource_group" { + value = azurerm_log_analytics_workspace.loganalytics_ws.resource_group_name + description = "Azure Log analytics workspace resource group name" +} + +output "loganalytics_retention_period" { + value = azurerm_log_analytics_workspace.loganalytics_ws.retention_in_days + description = "Azure loganalytics data retention in days" +} + +output "loganalytics_sku" { + value = azurerm_log_analytics_workspace.loganalytics_ws.sku + description = "Azure loganalytics SKU" +} diff --git a/log-analytics-workspace/providers.tf b/log-analytics-workspace/providers.tf new file mode 100644 index 0000000..45f79e0 --- /dev/null +++ b/log-analytics-workspace/providers.tf @@ -0,0 +1,12 @@ +terraform { + required_version = "~> 1.3" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "<= 4.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/log-analytics-workspace/variables.tf b/log-analytics-workspace/variables.tf new file mode 100644 index 0000000..d01e1d0 --- /dev/null +++ b/log-analytics-workspace/variables.tf @@ -0,0 +1,55 @@ +variable "resource_group_name" { + default = "" + description = "Azure resource group name to create log analytics workspace" + type = string +} + +variable "location" { + default = "" + description = "Azure location" + type = string +} + +variable "loganalytics_workspace_name" { + default = "" + type = string + description = "Loganalytics workspace name" +} + +variable "loganalytics_retention_period" { + default = 7 + description = "Loganalytics logs retention period" + type = number + validation { + condition = var.loganalytics_retention_period == 7 || (var.loganalytics_retention_period >= 30 && var.loganalytics_retention_period <= 730) + error_message = "The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730." + } + +} + +variable "application_name" { + default = "" + description = "Azure application name tag" + type = string +} + +variable "environment" { + default = "" + description = "Environment tag value in Azure" + type = string + validation { + condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment) + error_message = "Environment value should be one among DEV or QA or UAT or PROD." + } +} + +variable "loganalytics_sku" { + default = "PerGB2018" + type = string + description = "Specifies the SKU of the Log Analytics Workspace" + validation { + condition = contains(["PerNode", "Premium", "Standard", "Standalone", "Unlimited", "CapacityReservation", "PerGB2018"], var.loganalytics_sku) + error_message = "Log analytics SKU should be one among PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation or PerGB2018 ." + } +} +