Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVOPS-280 loganalytics terraform module initial commit #10

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions log-analytics-workspace/loganalytics.tf
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions log-analytics-workspace/output.tf
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 12 additions & 0 deletions log-analytics-workspace/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = "~> 1.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "<= 4.0"
}
}
}
provider "azurerm" {
features {}
}
55 changes: 55 additions & 0 deletions log-analytics-workspace/variables.tf
Original file line number Diff line number Diff line change
@@ -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 ."
}
}