From addd61a102fc9dfd904ce58541ff4bb600a91c06 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 16:15:03 +0530 Subject: [PATCH 01/11] DEVOPS-353 azure datashare terraform module --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5c429cf..0496fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ terraform.rc # README./ *.out + +automation-account/ From 73dec3cef74982ed05732b2ac7682adc9410edd0 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 16:15:11 +0530 Subject: [PATCH 02/11] DEVOPS-353_data-share-module Terraform --- azure-data-share/datashare.tf | 26 ++++++++++++++++++++ azure-data-share/outputs.tf | 15 ++++++++++++ azure-data-share/providers.tf | 12 +++++++++ azure-data-share/variables.tf | 46 +++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 azure-data-share/datashare.tf create mode 100644 azure-data-share/outputs.tf create mode 100644 azure-data-share/providers.tf create mode 100644 azure-data-share/variables.tf diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf new file mode 100644 index 0000000..740995e --- /dev/null +++ b/azure-data-share/datashare.tf @@ -0,0 +1,26 @@ +resource "azurerm_resource_group" "datashare" { + name = 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) + Temporary = upper(var.temporary) + } +} + + +resource "azurerm_data_share_account" "datashare" { + name = var.data_share_name + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + # Usiny System Assigned Managed Identity + identity { + type = "SystemAssigned" + } + + tags = azurerm_resource_group.datashare.tags + +} \ No newline at end of file diff --git a/azure-data-share/outputs.tf b/azure-data-share/outputs.tf new file mode 100644 index 0000000..cce50c4 --- /dev/null +++ b/azure-data-share/outputs.tf @@ -0,0 +1,15 @@ +output "azure_datashare_rg" { + description = "value of the resource group" + value = azurerm_resource_group.datashare.name +} + +output "datashare_name" { + description = "value of the data share account" + value = azurerm_data_share_account.datashare.name +} + +output "datashare_id" { + description = "value of the data share account id" + value = azurerm_data_share_account.datashare.id + +} diff --git a/azure-data-share/providers.tf b/azure-data-share/providers.tf new file mode 100644 index 0000000..9a052c5 --- /dev/null +++ b/azure-data-share/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/azure-data-share/variables.tf b/azure-data-share/variables.tf new file mode 100644 index 0000000..368b3e7 --- /dev/null +++ b/azure-data-share/variables.tf @@ -0,0 +1,46 @@ +variable "resource_group_name" { + type = string + description = "Azure Data Share Rg" + default = "" +} + +variable "location" { + type = string + description = "Azure data share location" + default = "" +} + +variable "data_share_name" { + description = "Azure Data Share name" + type = string + default = "" + +} + + +variable "environment" { + default = "DEV" + 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 "application_name" { + default = "devwithkrishna" + description = "Azure application name tag" +} + +variable "temporary" { + default = "TRUE" + description = "Temporary tag value in Azure" + type = string + validation { + condition = contains(["TRUE", "FALSE"], upper(var.temporary)) + error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'." + } + +} + From 0be9a52597510a00c1591e13d784c1d3e3b54a9c Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 16:29:38 +0530 Subject: [PATCH 03/11] DEVOPS-353 fix rg name and dtashare ref --- azure-data-share/datashare.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index 740995e..d0b240d 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -13,8 +13,8 @@ resource "azurerm_resource_group" "datashare" { resource "azurerm_data_share_account" "datashare" { name = var.data_share_name - location = azurerm_resource_group.example.location - resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.datashare.location + resource_group_name = azurerm_resource_group.datashare.name # Usiny System Assigned Managed Identity identity { From 0389cc1e4dfc715a49a121ff06d95b3a8ccc632c Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 16:48:40 +0530 Subject: [PATCH 04/11] provider lock --- azure-data-share/providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-data-share/providers.tf b/azure-data-share/providers.tf index 9a052c5..45f79e0 100644 --- a/azure-data-share/providers.tf +++ b/azure-data-share/providers.tf @@ -3,7 +3,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">= 4.0" + version = "<= 4.0" } } } From c6ac341107ce4195faa40daf0d3b282338e2bc1c Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 17:03:45 +0530 Subject: [PATCH 05/11] Removing tags at datashare level as bug in terraform provider causing case sensitivity issue --- azure-data-share/datashare.tf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index c367e40..d1f20f7 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -22,6 +22,8 @@ resource "azurerm_data_share_account" "datashare" { type = "SystemAssigned" } - tags = azurerm_resource_group.datashare.tags + # https://github.com/Azure/azure-rest-api-specs/issues/9280 + + # tags = azurerm_resource_group.datashare.tags } \ No newline at end of file From 8c51d23e63ecde167108237dbbf14e0e58f1b3a9 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 21:10:02 +0530 Subject: [PATCH 06/11] DEVOPS-353 Data Share Module --- azure-data-share/datashare.tf | 17 +++++++++++- azure-data-share/locals.tf | 5 ++++ azure-data-share/providers.tf | 9 +++++- azure-data-share/variables.tf | 52 +++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 azure-data-share/locals.tf diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index d1f20f7..d870ce5 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -26,4 +26,19 @@ resource "azurerm_data_share_account" "datashare" { # tags = azurerm_resource_group.datashare.tags -} \ No newline at end of file +} + + +resource "azurerm_data_share" "datashare" { + name = var.shares_name + account_id = azurerm_data_share_account.datashare.id + kind = var.share_type + description = var.share_description + terms = var.datashare_terms + + snapshot_schedule { + name = var.snapshot_schedule_name + recurrence = var.snapshot_recurrence + start_time = local.computed_start_time + } +} diff --git a/azure-data-share/locals.tf b/azure-data-share/locals.tf new file mode 100644 index 0000000..24a79d9 --- /dev/null +++ b/azure-data-share/locals.tf @@ -0,0 +1,5 @@ +locals { + computed_start_time = var.snapshot_start_time != null ? + var.snapshot_start_time : + timeadd(timestamp(), "1h") +} diff --git a/azure-data-share/providers.tf b/azure-data-share/providers.tf index 45f79e0..d5bfeb0 100644 --- a/azure-data-share/providers.tf +++ b/azure-data-share/providers.tf @@ -5,8 +5,15 @@ terraform { source = "hashicorp/azurerm" version = "<= 4.0" } + time = { + source = "hashicorp/time" + version = ">= 0.9.1" + } + } } provider "azurerm" { features {} -} \ No newline at end of file +} + +provider "time" {} \ No newline at end of file diff --git a/azure-data-share/variables.tf b/azure-data-share/variables.tf index 368b3e7..5394817 100644 --- a/azure-data-share/variables.tf +++ b/azure-data-share/variables.tf @@ -44,3 +44,55 @@ variable "temporary" { } +variable "shares_name" { + default = "" + type = string + description = "Data share - Share's name" +} + +variable "share_type" { + default = "CopyBased" + type = string + description = "Data share - Share's type" + validation { + condition = contains(["CopyBased", "InPlace"], var.share_type) + error_message = "The share type must be either 'CopyBased' or 'InPlace'." + } +} + +variable "share_description" { + default = "" + type = string + description = "Data share - ${var.shares_name}" + +} + +variable "datashare_terms" { + type = string + description = "The terms of the Data Share." + default = "" +} + +variable "snapshot_schedule_name" { + type = string + description = "The name of the snapshot schedule." + default = "Data share terms of ${var.shares_name}" +} + +variable "snapshot_recurrence" { + type = string + description = "The recurrence of the snapshot schedule." + default = "" + validation { + condition = contains(["Hour", "Day"], var.snapshot_recurrence) + error_message = "The snapshot recurrence must be one of 'Hour', 'Day'." + } + +} + +variable "snapshot_start_time" { + type = string + description = "The start time of the snapshot schedule in UTC format (e.g., '2023-10-01T00:00:00Z'). If not provided, it defaults to one hour from the current time. This should be in RFC 3389 format." + default = null + +} \ No newline at end of file From ca7385e9e0847c4715fb071f500ae0b2568761a0 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 21:28:49 +0530 Subject: [PATCH 07/11] fixed variable name --- azure-data-share/locals.tf | 4 +--- azure-data-share/variables.tf | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/azure-data-share/locals.tf b/azure-data-share/locals.tf index 24a79d9..b75730d 100644 --- a/azure-data-share/locals.tf +++ b/azure-data-share/locals.tf @@ -1,5 +1,3 @@ locals { - computed_start_time = var.snapshot_start_time != null ? - var.snapshot_start_time : - timeadd(timestamp(), "1h") + computed_start_time = var.snapshot_start_time != null ? var.snapshot_start_time : timeadd(timestamp(), "1h") } diff --git a/azure-data-share/variables.tf b/azure-data-share/variables.tf index 5394817..35b902e 100644 --- a/azure-data-share/variables.tf +++ b/azure-data-share/variables.tf @@ -44,14 +44,14 @@ variable "temporary" { } -variable "shares_name" { - default = "" - type = string +variable "share_name" { + default = "" + type = string description = "Data share - Share's name" } variable "share_type" { - default = "CopyBased" + default = "CopyBased" type = string description = "Data share - Share's type" validation { @@ -64,35 +64,35 @@ variable "share_description" { default = "" type = string description = "Data share - ${var.shares_name}" - + } variable "datashare_terms" { type = string description = "The terms of the Data Share." - default = "" + default = "Data share terms of ${var.shares_name}" } variable "snapshot_schedule_name" { - type = string + type = string description = "The name of the snapshot schedule." - default = "Data share terms of ${var.shares_name}" + default = "" } variable "snapshot_recurrence" { - type = string + type = string description = "The recurrence of the snapshot schedule." - default = "" + default = "" validation { condition = contains(["Hour", "Day"], var.snapshot_recurrence) error_message = "The snapshot recurrence must be one of 'Hour', 'Day'." } - + } variable "snapshot_start_time" { type = string description = "The start time of the snapshot schedule in UTC format (e.g., '2023-10-01T00:00:00Z'). If not provided, it defaults to one hour from the current time. This should be in RFC 3389 format." default = null - + } \ No newline at end of file From 90b0519792781c24a9856899791d54dd5332afb3 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 21:36:49 +0530 Subject: [PATCH 08/11] fixed var name --- azure-data-share/datashare.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index d870ce5..e3892ca 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -30,7 +30,7 @@ resource "azurerm_data_share_account" "datashare" { resource "azurerm_data_share" "datashare" { - name = var.shares_name + name = var.share_name account_id = azurerm_data_share_account.datashare.id kind = var.share_type description = var.share_description From 378a143d659749944697803cb703aaa717da7778 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 23:49:03 +0530 Subject: [PATCH 09/11] added lifecycle ignore changes --- azure-data-share/datashare.tf | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index e3892ca..aa44e5f 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -8,6 +8,9 @@ resource "azurerm_resource_group" "datashare" { ApplicationName = lower(var.application_name) Temporary = upper(var.temporary) } + lifecycle { + ignore_changes = [tags] + } } @@ -25,6 +28,9 @@ resource "azurerm_data_share_account" "datashare" { # https://github.com/Azure/azure-rest-api-specs/issues/9280 # tags = azurerm_resource_group.datashare.tags + lifecycle { + ignore_changes = [tags] + } } @@ -41,4 +47,8 @@ resource "azurerm_data_share" "datashare" { recurrence = var.snapshot_recurrence start_time = local.computed_start_time } + + lifecycle { + ignore_changes = [tags] + } } From 9734a43d971c882bf319e8d2ef157e05706efb50 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 23:53:46 +0530 Subject: [PATCH 10/11] pull req --- .github/workflows/terraform-fmt.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/terraform-fmt.yaml b/.github/workflows/terraform-fmt.yaml index 1217fa7..9063449 100644 --- a/.github/workflows/terraform-fmt.yaml +++ b/.github/workflows/terraform-fmt.yaml @@ -11,6 +11,20 @@ on: - '**.tfvars' - '**.tfvars.json' + pull_request: + types: + - opened + - synchronize + - closed + - edited + + branches: + - main + paths: + - '**.tf' + - '**.tfvars' + - '**.tfvars.json' + permissions: contents: write From fed464d52e1e2ebe38284ffbf3a0a6751ecdc596 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Mon, 6 Oct 2025 23:55:51 +0530 Subject: [PATCH 11/11] terraform fmt --- .github/workflows/terraform-fmt.yaml | 2 +- azure-data-share/datashare.tf | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/terraform-fmt.yaml b/.github/workflows/terraform-fmt.yaml index 9063449..91d9746 100644 --- a/.github/workflows/terraform-fmt.yaml +++ b/.github/workflows/terraform-fmt.yaml @@ -51,7 +51,7 @@ jobs: - name: Run the tree generation script run: | - terraform fmt -recursive -check + terraform fmt -recursive - name: Commit and Push Changes env: diff --git a/azure-data-share/datashare.tf b/azure-data-share/datashare.tf index aa44e5f..e1e2c2a 100644 --- a/azure-data-share/datashare.tf +++ b/azure-data-share/datashare.tf @@ -9,7 +9,7 @@ resource "azurerm_resource_group" "datashare" { Temporary = upper(var.temporary) } lifecycle { - ignore_changes = [tags] + ignore_changes = [tags] } } @@ -29,7 +29,7 @@ resource "azurerm_data_share_account" "datashare" { # tags = azurerm_resource_group.datashare.tags lifecycle { - ignore_changes = [tags] + ignore_changes = [tags] } } @@ -49,6 +49,6 @@ resource "azurerm_data_share" "datashare" { } lifecycle { - ignore_changes = [tags] + ignore_changes = [tags] } }