Skip to content

Commit 3023d2a

Browse files
DEVOPS-280 loganalytics terraform module initial commit (#10)
* DEVOPS-280 loganalytics terraform module initial commit * DEVOPS-280 loganalytics terraform module initial commit
1 parent d428fc0 commit 3023d2a

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "azurerm_resource_group" "rg" {
2+
name = upper(var.resource_group_name)
3+
location = var.location
4+
tags = {
5+
Environment = upper(var.environment)
6+
Orchestrator = "Terraform"
7+
DisplayName = upper(var.resource_group_name)
8+
ApplicationName = lower(var.application_name)
9+
}
10+
}
11+
12+
resource "azurerm_log_analytics_workspace" "loganalytics_ws" {
13+
name = upper(var.loganalytics_workspace_name)
14+
sku = var.loganalytics_sku
15+
resource_group_name = azurerm_resource_group.rg.name
16+
location = var.location
17+
retention_in_days = var.loganalytics_retention_period
18+
}

log-analytics-workspace/output.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "loganalytics_workspace_name" {
2+
value = azurerm_log_analytics_workspace.loganalytics_ws.name
3+
description = "Azure Log analytics workspace name"
4+
}
5+
6+
output "loganalytics_workspace_resource_group" {
7+
value = azurerm_log_analytics_workspace.loganalytics_ws.resource_group_name
8+
description = "Azure Log analytics workspace resource group name"
9+
}
10+
11+
output "loganalytics_retention_period" {
12+
value = azurerm_log_analytics_workspace.loganalytics_ws.retention_in_days
13+
description = "Azure loganalytics data retention in days"
14+
}
15+
16+
output "loganalytics_sku" {
17+
value = azurerm_log_analytics_workspace.loganalytics_ws.sku
18+
description = "Azure loganalytics SKU"
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = "<= 4.0"
7+
}
8+
}
9+
}
10+
provider "azurerm" {
11+
features {}
12+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variable "resource_group_name" {
2+
default = ""
3+
description = "Azure resource group name to create log analytics workspace"
4+
type = string
5+
}
6+
7+
variable "location" {
8+
default = ""
9+
description = "Azure location"
10+
type = string
11+
}
12+
13+
variable "loganalytics_workspace_name" {
14+
default = ""
15+
type = string
16+
description = "Loganalytics workspace name"
17+
}
18+
19+
variable "loganalytics_retention_period" {
20+
default = 7
21+
description = "Loganalytics logs retention period"
22+
type = number
23+
validation {
24+
condition = var.loganalytics_retention_period == 7 || (var.loganalytics_retention_period >= 30 && var.loganalytics_retention_period <= 730)
25+
error_message = "The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730."
26+
}
27+
28+
}
29+
30+
variable "application_name" {
31+
default = ""
32+
description = "Azure application name tag"
33+
type = string
34+
}
35+
36+
variable "environment" {
37+
default = ""
38+
description = "Environment tag value in Azure"
39+
type = string
40+
validation {
41+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
42+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
43+
}
44+
}
45+
46+
variable "loganalytics_sku" {
47+
default = "PerGB2018"
48+
type = string
49+
description = "Specifies the SKU of the Log Analytics Workspace"
50+
validation {
51+
condition = contains(["PerNode", "Premium", "Standard", "Standalone", "Unlimited", "CapacityReservation", "PerGB2018"], var.loganalytics_sku)
52+
error_message = "Log analytics SKU should be one among PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation or PerGB2018 ."
53+
}
54+
}
55+

0 commit comments

Comments
 (0)