From dd8241fa496e2e0851664fd29f494a432267a78a Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Mon, 13 Feb 2023 17:49:49 +0100 Subject: [PATCH 01/16] Data Share Account and Data Share modules --- .../data-share/data-share-account/main.tf | 13 ++++ .../data-share/data-share-account/outputs.tf | 27 +++++++ .../test/data_share_account.tf | 16 ++++ .../data-share-account/test/locals.tf | 7 ++ .../data-share-account/test/outputs.tf | 15 ++++ .../data-share-account/test/providers.tf | 19 +++++ .../data-share-account/test/unit_test.go | 38 ++++++++++ .../data-share-account/test/variables.tf | 10 +++ .../data-share-account/variables.tf | 34 +++++++++ terraform/data-share/data-share/main.tf | 21 ++++++ terraform/data-share/data-share/outputs.tf | 13 ++++ .../data-share/data-share/test/data_share.tf | 22 ++++++ .../data-share/data-share/test/locals.tf | 7 ++ .../data-share/data-share/test/outputs.tf | 7 ++ .../data-share/data-share/test/providers.tf | 19 +++++ .../data-share/data-share/test/unit_test.go | 34 +++++++++ .../data-share/data-share/test/variables.tf | 10 +++ terraform/data-share/data-share/variables.tf | 73 +++++++++++++++++++ 18 files changed, 385 insertions(+) create mode 100644 terraform/data-share/data-share-account/main.tf create mode 100644 terraform/data-share/data-share-account/outputs.tf create mode 100644 terraform/data-share/data-share-account/test/data_share_account.tf create mode 100644 terraform/data-share/data-share-account/test/locals.tf create mode 100644 terraform/data-share/data-share-account/test/outputs.tf create mode 100644 terraform/data-share/data-share-account/test/providers.tf create mode 100644 terraform/data-share/data-share-account/test/unit_test.go create mode 100644 terraform/data-share/data-share-account/test/variables.tf create mode 100644 terraform/data-share/data-share-account/variables.tf create mode 100644 terraform/data-share/data-share/main.tf create mode 100644 terraform/data-share/data-share/outputs.tf create mode 100644 terraform/data-share/data-share/test/data_share.tf create mode 100644 terraform/data-share/data-share/test/locals.tf create mode 100644 terraform/data-share/data-share/test/outputs.tf create mode 100644 terraform/data-share/data-share/test/providers.tf create mode 100644 terraform/data-share/data-share/test/unit_test.go create mode 100644 terraform/data-share/data-share/test/variables.tf create mode 100644 terraform/data-share/data-share/variables.tf diff --git a/terraform/data-share/data-share-account/main.tf b/terraform/data-share/data-share-account/main.tf new file mode 100644 index 00000000..6e531c4c --- /dev/null +++ b/terraform/data-share/data-share-account/main.tf @@ -0,0 +1,13 @@ +# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_share_account + +resource "azurerm_data_share_account" "adl_dsa" { + name = "dsa-${var.basename}" + location = var.location + resource_group_name = var.rg_name + identity { + type = "SystemAssigned" + } + tags = var.tags + + count = var.module_enabled ? 1 : 0 +} diff --git a/terraform/data-share/data-share-account/outputs.tf b/terraform/data-share/data-share-account/outputs.tf new file mode 100644 index 00000000..9cca9088 --- /dev/null +++ b/terraform/data-share/data-share-account/outputs.tf @@ -0,0 +1,27 @@ +output "id" { + value = ( + length(azurerm_data_share_account.adl_dsa) > 0 ? + azurerm_data_share_account.adl_dsa[0].id : "" + ) +} + +output "name" { + value = ( + length(azurerm_data_share_account.adl_dsa) > 0 ? + azurerm_data_share_account.adl_dsa[0].name : "" + ) +} + +output "resource_group_name" { + value = ( + length(azurerm_data_share_account.adl_dsa) > 0 ? + azurerm_data_share_account.adl_dsa[0].resource_group_name : "" + ) +} + +output "identity" { + value = ( + length(azurerm_data_share_account.adl_dsa) > 0 ? + azurerm_data_share_account.adl_dsa[0].identity : [{}] + ) +} diff --git a/terraform/data-share/data-share-account/test/data_share_account.tf b/terraform/data-share/data-share-account/test/data_share_account.tf new file mode 100644 index 00000000..6b8b5752 --- /dev/null +++ b/terraform/data-share/data-share-account/test/data_share_account.tf @@ -0,0 +1,16 @@ +module "data_share_account" { + source = "../" + basename = random_string.postfix.result + rg_name = module.local_rg.name + location = var.location + tags = {} +} + +# Modules dependencies + +module "local_rg" { + source = "../../../resource-group" + basename = random_string.postfix.result + location = var.location + tags = local.tags +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/test/locals.tf b/terraform/data-share/data-share-account/test/locals.tf new file mode 100644 index 00000000..5a1867c8 --- /dev/null +++ b/terraform/data-share/data-share-account/test/locals.tf @@ -0,0 +1,7 @@ +locals { + tags = { + Project = "Azure/azure-data-labs-modules" + Module = "data-share-account" + Toolkit = "Terraform" + } +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/test/outputs.tf b/terraform/data-share/data-share-account/test/outputs.tf new file mode 100644 index 00000000..35b9c1eb --- /dev/null +++ b/terraform/data-share/data-share-account/test/outputs.tf @@ -0,0 +1,15 @@ +output "id" { + value = module.data_share_account.id +} + +output "name" { + value = module.data_share_account.name +} + +output "resource_group_name" { + value = module.data_share_account.resource_group_name +} + +output "identity" { + value = module.data_share_account.identity +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/test/providers.tf b/terraform/data-share/data-share-account/test/providers.tf new file mode 100644 index 00000000..f79a5295 --- /dev/null +++ b/terraform/data-share/data-share-account/test/providers.tf @@ -0,0 +1,19 @@ +terraform { + backend "azurerm" { + resource_group_name = "rg-adl-terraform-state" + storage_account_name = "stadlterraformstate" + container_name = "default" + key = "datashareaccount.terraform.tfstate" + } + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.42.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/test/unit_test.go b/terraform/data-share/data-share-account/test/unit_test.go new file mode 100644 index 00000000..f28655a8 --- /dev/null +++ b/terraform/data-share/data-share-account/test/unit_test.go @@ -0,0 +1,38 @@ +package test + +import ( + "testing" + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestModule(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + TerraformDir: "./", + Lock: true, + LockTimeout: "1800s", + // VarFiles: []string{"terraform_unitest.tfvars"}, + } + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer terraform.Destroy(t, terraformOptions) + + // Is used mainly for debugging, fail early if plan is not possible + terraform.InitAndPlan(t, terraformOptions) + + // This will run `terraform init` and `terraform apply` and fail the test if there are any errors + terraform.InitAndApply(t, terraformOptions) + + // Check if the outputs exist + assert := assert.New(t) + id := terraform.Output(t, terraformOptions, "id") + assert.NotNil(id) + name := terraform.Output(t, terraformOptions, "name") + assert.NotNil(name) + resource_group_name := terraform.Output(t, terraformOptions, "resource_group_name") + assert.NotNil(resource_group_name) + identity := terraform.Output(t, terraformOptions, "identity") + assert.NotNil(identity) +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/test/variables.tf b/terraform/data-share/data-share-account/test/variables.tf new file mode 100644 index 00000000..b025435b --- /dev/null +++ b/terraform/data-share/data-share-account/test/variables.tf @@ -0,0 +1,10 @@ +resource "random_string" "postfix" { + length = 8 + special = false + upper = false +} + +variable "location" { + type = string + default = "North Europe" +} \ No newline at end of file diff --git a/terraform/data-share/data-share-account/variables.tf b/terraform/data-share/data-share-account/variables.tf new file mode 100644 index 00000000..8544c465 --- /dev/null +++ b/terraform/data-share/data-share-account/variables.tf @@ -0,0 +1,34 @@ +variable "basename" { + type = string + description = "Basename of the module." + validation { + condition = can(regex("^[-\\w]{0,86}$", var.basename)) + error_message = "The name must be between 0 and 86 characters, can contain only letters, numbers, underscores, and hyphens." + } +} + +variable "rg_name" { + type = string + description = "Resource group name." + validation { + condition = can(regex("^[-\\w\\.\\(\\)]{1,90}$", var.rg_name)) && can(regex("[-\\w\\(\\)]+$", var.rg_name)) + error_message = "Resource group names must be between 1 and 90 characters and can only include alphanumeric, underscore, parentheses, hyphen, period (except at end)." + } +} + +variable "location" { + type = string + description = "Location of the resource group." +} + +variable "tags" { + type = map(string) + default = {} + description = "A mapping of tags which should be assigned to the deployed resource." +} + +variable "module_enabled" { + type = bool + description = "Variable to enable or disable the module." + default = true +} \ No newline at end of file diff --git a/terraform/data-share/data-share/main.tf b/terraform/data-share/data-share/main.tf new file mode 100644 index 00000000..a522375a --- /dev/null +++ b/terraform/data-share/data-share/main.tf @@ -0,0 +1,21 @@ +# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_share +# As of today, there is no support for Data Share invitation, subscription and dataset mapping: https://github.com/hashicorp/terraform-provider-azurerm/issues/14010 + +resource "azurerm_data_share" "adl_ds" { + name = "ds_${var.basename}" + account_id = var.account_id + kind = var.kind + description = var.description + terms = var.terms + + dynamic "snapshot_schedule" { + for_each = var.snapshot_schedule + content { + name = snapshot_schedule.value["name"] + recurrence = snapshot_schedule.value["recurrence"] + start_time = snapshot_schedule.value["start_time"] + } + } + + count = var.module_enabled ? 1 : 0 +} diff --git a/terraform/data-share/data-share/outputs.tf b/terraform/data-share/data-share/outputs.tf new file mode 100644 index 00000000..51c81dc3 --- /dev/null +++ b/terraform/data-share/data-share/outputs.tf @@ -0,0 +1,13 @@ +output "id" { + value = ( + length(azurerm_data_share.adl_ds) > 0 ? + azurerm_data_share.adl_ds[0].id : "" + ) +} + +output "name" { + value = ( + length(azurerm_data_share.adl_ds) > 0 ? + azurerm_data_share.adl_ds[0].name : "" + ) +} \ No newline at end of file diff --git a/terraform/data-share/data-share/test/data_share.tf b/terraform/data-share/data-share/test/data_share.tf new file mode 100644 index 00000000..96089972 --- /dev/null +++ b/terraform/data-share/data-share/test/data_share.tf @@ -0,0 +1,22 @@ +module "data_share" { + source = "../" + basename = random_string.postfix.result + account_id = module.local_data_share_account.id +} + +# Module dependencies + +module "local_data_share_account" { + source = "../../data-share-account" + basename = random_string.postfix.result + rg_name = module.local_rg.name + location = var.location + tags = {} +} + +module "local_rg" { + source = "../../../resource-group" + basename = random_string.postfix.result + location = var.location + tags = local.tags +} diff --git a/terraform/data-share/data-share/test/locals.tf b/terraform/data-share/data-share/test/locals.tf new file mode 100644 index 00000000..7c8042ff --- /dev/null +++ b/terraform/data-share/data-share/test/locals.tf @@ -0,0 +1,7 @@ +locals { + tags = { + Project = "Azure/azure-data-labs-modules" + Module = "data-share" + Toolkit = "Terraform" + } +} \ No newline at end of file diff --git a/terraform/data-share/data-share/test/outputs.tf b/terraform/data-share/data-share/test/outputs.tf new file mode 100644 index 00000000..72418f57 --- /dev/null +++ b/terraform/data-share/data-share/test/outputs.tf @@ -0,0 +1,7 @@ +output "id" { + value = module.data_share.id +} + +output "name" { + value = module.data_share.name +} \ No newline at end of file diff --git a/terraform/data-share/data-share/test/providers.tf b/terraform/data-share/data-share/test/providers.tf new file mode 100644 index 00000000..d3952fe6 --- /dev/null +++ b/terraform/data-share/data-share/test/providers.tf @@ -0,0 +1,19 @@ +terraform { + backend "azurerm" { + resource_group_name = "rg-adl-terraform-state" + storage_account_name = "stadltfstate" + container_name = "default" + key = "eventhubs.terraform.tfstate" + } + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "= 3.42.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/terraform/data-share/data-share/test/unit_test.go b/terraform/data-share/data-share/test/unit_test.go new file mode 100644 index 00000000..745e336a --- /dev/null +++ b/terraform/data-share/data-share/test/unit_test.go @@ -0,0 +1,34 @@ +package test + +import ( + "testing" + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestModule(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + TerraformDir: "./", + Lock: true, + LockTimeout: "1800s", + // VarFiles: []string{"terraform_unitest.tfvars"}, + } + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer terraform.Destroy(t, terraformOptions) + + // Is used mainly for debugging, fail early if plan is not possible + terraform.InitAndPlan(t, terraformOptions) + + // This will run `terraform init` and `terraform apply` and fail the test if there are any errors + terraform.InitAndApply(t, terraformOptions) + + // Check if the outputs exist + assert := assert.New(t) + id := terraform.Output(t, terraformOptions, "id") + assert.NotNil(id) + name := terraform.Output(t, terraformOptions, "name") + assert.NotNil(name) +} \ No newline at end of file diff --git a/terraform/data-share/data-share/test/variables.tf b/terraform/data-share/data-share/test/variables.tf new file mode 100644 index 00000000..b025435b --- /dev/null +++ b/terraform/data-share/data-share/test/variables.tf @@ -0,0 +1,10 @@ +resource "random_string" "postfix" { + length = 8 + special = false + upper = false +} + +variable "location" { + type = string + default = "North Europe" +} \ No newline at end of file diff --git a/terraform/data-share/data-share/variables.tf b/terraform/data-share/data-share/variables.tf new file mode 100644 index 00000000..a6b4bac1 --- /dev/null +++ b/terraform/data-share/data-share/variables.tf @@ -0,0 +1,73 @@ +variable "basename" { + type = string + description = "Basename of the module." + validation { + condition = can(regex("^[\\w]{0,87}$", var.basename)) + error_message = "The name must be between 0 and 87 characters, can contain only letters, numbers, and underscores." + } +} + +variable "account_id" { + type = string + description = "The ID of the Data Share account in which the Data Share is created." +} + +variable "module_enabled" { + type = bool + description = "Variable to enable or disable the module." + default = true +} + +variable "kind" { + type = string + description = "The kind of the Data Share." + validation { + condition = contains(["copybased", "inplace"], lower(var.kind)) + error_message = "Valid values for kind are \"CopyBased\" or \"InPlace\"." + } + default = "InPlace" +} + +variable "description" { + type = string + description = "The Data Share's description." + validation { + condition = length(var.description) <= 100000 + error_message = "Length of description must not exceed 100,000 characters." + } + default = "" +} + +variable "terms" { + type = string + description = "The terms of the Data Share." + validation { + condition = length(var.terms) <= 100000 + error_message = "Length of terms must not exceed 100,000 characters." + } + default = "" +} + +variable "snapshot_schedule" { + type = map( + object( + { + name = optional(string) + recurrence = optional(string) + start_time = optional(string) + } + ) + ) + description = < 0])) + error_message = "Valid values for recurrence are \"Hour\" or \"Day\". Valid values for start_time are dates or date times in ISO 8601 format." + } + default = {} +} From 4deb493fa542af5ceeab0e586b67de526afd4038 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Mon, 13 Feb 2023 17:53:35 +0100 Subject: [PATCH 02/16] Add workflows for Data Share Account & Data Share --- .github/workflows/data-share-account.yml | 78 ++++++++++++++++++++++++ .github/workflows/data-share.yml | 78 ++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 .github/workflows/data-share-account.yml create mode 100644 .github/workflows/data-share.yml diff --git a/.github/workflows/data-share-account.yml b/.github/workflows/data-share-account.yml new file mode 100644 index 00000000..d6e49715 --- /dev/null +++ b/.github/workflows/data-share-account.yml @@ -0,0 +1,78 @@ +name: Module:data-share-account +on: + workflow_dispatch: + pull_request: + branches: + - main + paths: + - '.github/workflows/data-share-account.yml' + - 'terraform/data-share/data-share-account/**' + - '.github/actions/**' + +env: + terraform_workingdir: "terraform/data-share/data-share-account" + GH_TOKEN: ${{ secrets.GH_TOKEN }} + ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} + ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} + ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} + +jobs: + terraform-lint: + name: Run Terraform lint + runs-on: ubuntu-latest + defaults: + run: + working-directory: "${{ env.terraform_workingdir }}" + + steps: + - uses: actions/checkout@v3 + - uses: hashicorp/setup-terraform@v2 + + - name: Terraform fmt + id: fmt + run: terraform fmt -check + continue-on-error: false + + terraform-sec: + name: Run Terraform tfsec + needs: + - terraform-lint + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@main + + - name: Run tfsec with reviewdog output on the PR + uses: ./.github/actions/run-terraform-sec + + terratest: + name: Run Terratest + needs: + - terraform-sec + runs-on: ubuntu-latest + + defaults: + run: + working-directory: "${{ env.terraform_workingdir }}/test" + + steps: + - name: Check out code + uses: actions/checkout@v3 + + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.18.2 + + - name: Setup Dependencies + run: go mod init test && go mod tidy + env: + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" + + - name: Unit-test + run: go test -v -timeout 45m + env: + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" \ No newline at end of file diff --git a/.github/workflows/data-share.yml b/.github/workflows/data-share.yml new file mode 100644 index 00000000..ac6836f3 --- /dev/null +++ b/.github/workflows/data-share.yml @@ -0,0 +1,78 @@ +name: Module:data-share +on: + workflow_dispatch: + pull_request: + branches: + - main + paths: + - '.github/workflows/data-share.yml' + - 'terraform/data-share/data-share/**' + - '.github/actions/**' + +env: + terraform_workingdir: "terraform/data-share/data-share" + GH_TOKEN: ${{ secrets.GH_TOKEN }} + ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} + ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} + ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} + +jobs: + terraform-lint: + name: Run Terraform lint + runs-on: ubuntu-latest + defaults: + run: + working-directory: "${{ env.terraform_workingdir }}" + + steps: + - uses: actions/checkout@v3 + - uses: hashicorp/setup-terraform@v2 + + - name: Terraform fmt + id: fmt + run: terraform fmt -check + continue-on-error: false + + terraform-sec: + name: Run Terraform tfsec + needs: + - terraform-lint + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@main + + - name: Run tfsec with reviewdog output on the PR + uses: ./.github/actions/run-terraform-sec + + terratest: + name: Run Terratest + needs: + - terraform-sec + runs-on: ubuntu-latest + + defaults: + run: + working-directory: "${{ env.terraform_workingdir }}/test" + + steps: + - name: Check out code + uses: actions/checkout@v3 + + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.18.2 + + - name: Setup Dependencies + run: go mod init test && go mod tidy + env: + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" + + - name: Unit-test + run: go test -v -timeout 45m + env: + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" \ No newline at end of file From ca118e16bebaa094f508bbe1914bcfad710993b2 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Mon, 13 Feb 2023 18:01:01 +0100 Subject: [PATCH 03/16] TF FMT --- terraform/data-share/data-share-account/main.tf | 6 +++--- .../data-share-account/test/data_share_account.tf | 10 +++++----- terraform/data-share/data-share/variables.tf | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/terraform/data-share/data-share-account/main.tf b/terraform/data-share/data-share-account/main.tf index 6e531c4c..82e5698e 100644 --- a/terraform/data-share/data-share-account/main.tf +++ b/terraform/data-share/data-share-account/main.tf @@ -1,9 +1,9 @@ # https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_share_account resource "azurerm_data_share_account" "adl_dsa" { - name = "dsa-${var.basename}" - location = var.location - resource_group_name = var.rg_name + name = "dsa-${var.basename}" + location = var.location + resource_group_name = var.rg_name identity { type = "SystemAssigned" } diff --git a/terraform/data-share/data-share-account/test/data_share_account.tf b/terraform/data-share/data-share-account/test/data_share_account.tf index 6b8b5752..f86ea804 100644 --- a/terraform/data-share/data-share-account/test/data_share_account.tf +++ b/terraform/data-share/data-share-account/test/data_share_account.tf @@ -1,9 +1,9 @@ module "data_share_account" { - source = "../" - basename = random_string.postfix.result - rg_name = module.local_rg.name - location = var.location - tags = {} + source = "../" + basename = random_string.postfix.result + rg_name = module.local_rg.name + location = var.location + tags = {} } # Modules dependencies diff --git a/terraform/data-share/data-share/variables.tf b/terraform/data-share/data-share/variables.tf index a6b4bac1..b3d29c76 100644 --- a/terraform/data-share/data-share/variables.tf +++ b/terraform/data-share/data-share/variables.tf @@ -66,7 +66,7 @@ variable "snapshot_schedule" { " EOF validation { - condition = length(var.snapshot_schedule) == 0 || (length(var.snapshot_schedule) == 1 && alltrue([for v in var.snapshot_schedule : contains(["hour", "day"], lower(v.recurrence))]) && alltrue([for v in var.snapshot_schedule : can(regex("^(\\d{4})-(\\d{2})-(\\d{2})(T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*)?)((-(\\d{2}):(\\d{2})|Z)?))?$", v.start_time))]) && alltrue([for v in var.snapshot_schedule : length(v.name) > 0])) + condition = length(var.snapshot_schedule) == 0 || (length(var.snapshot_schedule) == 1 && alltrue([for v in var.snapshot_schedule : contains(["hour", "day"], lower(v.recurrence))]) && alltrue([for v in var.snapshot_schedule : can(regex("^(\\d{4})-(\\d{2})-(\\d{2})(T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*)?)((-(\\d{2}):(\\d{2})|Z)?))?$", v.start_time))]) && alltrue([for v in var.snapshot_schedule : length(v.name) > 0])) error_message = "Valid values for recurrence are \"Hour\" or \"Day\". Valid values for start_time are dates or date times in ISO 8601 format." } default = {} From 20c27b56415664f3779a6ace9e47bd2d134cbff8 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Mon, 13 Feb 2023 18:04:31 +0100 Subject: [PATCH 04/16] Fix TF state backend for Data Share module test --- terraform/data-share/data-share/test/providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/data-share/data-share/test/providers.tf b/terraform/data-share/data-share/test/providers.tf index d3952fe6..bf440a9e 100644 --- a/terraform/data-share/data-share/test/providers.tf +++ b/terraform/data-share/data-share/test/providers.tf @@ -1,7 +1,7 @@ terraform { backend "azurerm" { resource_group_name = "rg-adl-terraform-state" - storage_account_name = "stadltfstate" + storage_account_name = "stadlterraformstate" container_name = "default" key = "eventhubs.terraform.tfstate" } From 3a1e6f2f6f64fc13fc2b2de99d42c6b43a3acf51 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Mon, 13 Feb 2023 18:18:22 +0100 Subject: [PATCH 05/16] Fix TF state backend key for Data Share module --- terraform/data-share/data-share/test/providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/data-share/data-share/test/providers.tf b/terraform/data-share/data-share/test/providers.tf index bf440a9e..8b7da8fa 100644 --- a/terraform/data-share/data-share/test/providers.tf +++ b/terraform/data-share/data-share/test/providers.tf @@ -3,7 +3,7 @@ terraform { resource_group_name = "rg-adl-terraform-state" storage_account_name = "stadlterraformstate" container_name = "default" - key = "eventhubs.terraform.tfstate" + key = "datashare.terraform.tfstate" } required_providers { From fbab3ab5da580aea0838442b70249875e8f21169 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo <41644064+nachoalonsoportillo@users.noreply.github.com> Date: Mon, 13 Feb 2023 23:18:07 +0100 Subject: [PATCH 06/16] Update providers.tf --- terraform/data-share/data-share-account/test/providers.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/data-share/data-share-account/test/providers.tf b/terraform/data-share/data-share-account/test/providers.tf index f79a5295..1843ed73 100644 --- a/terraform/data-share/data-share-account/test/providers.tf +++ b/terraform/data-share/data-share-account/test/providers.tf @@ -9,11 +9,11 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "= 3.42.0" + version = "= 3.43.0" } } } provider "azurerm" { features {} -} \ No newline at end of file +} From 2475b36fd41914f53554d8aea532235d092f9ba1 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo <41644064+nachoalonsoportillo@users.noreply.github.com> Date: Mon, 13 Feb 2023 23:18:25 +0100 Subject: [PATCH 07/16] Update providers.tf --- terraform/data-share/data-share/test/providers.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/data-share/data-share/test/providers.tf b/terraform/data-share/data-share/test/providers.tf index 8b7da8fa..025fbc90 100644 --- a/terraform/data-share/data-share/test/providers.tf +++ b/terraform/data-share/data-share/test/providers.tf @@ -9,11 +9,11 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "= 3.42.0" + version = "= 3.43.0" } } } provider "azurerm" { features {} -} \ No newline at end of file +} From 04885aad8ee32986fb5bed4c7fe586afee2ebe37 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Tue, 14 Feb 2023 16:17:22 +0100 Subject: [PATCH 08/16] Add descriptions to outputs --- .github/workflows/data-share-account.yml | 17 +++++++++++++++-- .github/workflows/data-share.yml | 17 +++++++++++++++-- .../data-share/data-share-account/outputs.tf | 6 +++++- terraform/data-share/data-share/outputs.tf | 2 ++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/data-share-account.yml b/.github/workflows/data-share-account.yml index d6e49715..c98a6870 100644 --- a/.github/workflows/data-share-account.yml +++ b/.github/workflows/data-share-account.yml @@ -7,7 +7,7 @@ on: paths: - '.github/workflows/data-share-account.yml' - 'terraform/data-share/data-share-account/**' - - '.github/actions/**' +# - '.github/actions/**' env: terraform_workingdir: "terraform/data-share/data-share-account" @@ -75,4 +75,17 @@ jobs: - name: Unit-test run: go test -v -timeout 45m env: - GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" \ No newline at end of file + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" + + terraform-docs: + name: Run Terraform Docs + needs: + - terratest + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Render terraform docs and push changes back to PR + uses: ./.github/actions/run-terraform-docs \ No newline at end of file diff --git a/.github/workflows/data-share.yml b/.github/workflows/data-share.yml index ac6836f3..e448b2ff 100644 --- a/.github/workflows/data-share.yml +++ b/.github/workflows/data-share.yml @@ -7,7 +7,7 @@ on: paths: - '.github/workflows/data-share.yml' - 'terraform/data-share/data-share/**' - - '.github/actions/**' +# - '.github/actions/**' env: terraform_workingdir: "terraform/data-share/data-share" @@ -75,4 +75,17 @@ jobs: - name: Unit-test run: go test -v -timeout 45m env: - GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" \ No newline at end of file + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" + + terraform-docs: + name: Run Terraform Docs + needs: + - terratest + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Render terraform docs and push changes back to PR + uses: ./.github/actions/run-terraform-docs \ No newline at end of file diff --git a/terraform/data-share/data-share-account/outputs.tf b/terraform/data-share/data-share-account/outputs.tf index 9cca9088..0838c980 100644 --- a/terraform/data-share/data-share-account/outputs.tf +++ b/terraform/data-share/data-share-account/outputs.tf @@ -3,6 +3,7 @@ output "id" { length(azurerm_data_share_account.adl_dsa) > 0 ? azurerm_data_share_account.adl_dsa[0].id : "" ) + description = "Resource identifier of the instance of Data Share account." } output "name" { @@ -10,6 +11,7 @@ output "name" { length(azurerm_data_share_account.adl_dsa) > 0 ? azurerm_data_share_account.adl_dsa[0].name : "" ) + description = "The name of the Data Share account." } output "resource_group_name" { @@ -17,6 +19,7 @@ output "resource_group_name" { length(azurerm_data_share_account.adl_dsa) > 0 ? azurerm_data_share_account.adl_dsa[0].resource_group_name : "" ) + description = "Resource Group where the Data Share account exists." } output "identity" { @@ -24,4 +27,5 @@ output "identity" { length(azurerm_data_share_account.adl_dsa) > 0 ? azurerm_data_share_account.adl_dsa[0].identity : [{}] ) -} + description = "Principal ID and Tenant ID for the Service Principal associated with the identity of the Data Share account." +} \ No newline at end of file diff --git a/terraform/data-share/data-share/outputs.tf b/terraform/data-share/data-share/outputs.tf index 51c81dc3..240b1c6c 100644 --- a/terraform/data-share/data-share/outputs.tf +++ b/terraform/data-share/data-share/outputs.tf @@ -3,6 +3,7 @@ output "id" { length(azurerm_data_share.adl_ds) > 0 ? azurerm_data_share.adl_ds[0].id : "" ) + description = "Resource identifier of the instance of Data Share." } output "name" { @@ -10,4 +11,5 @@ output "name" { length(azurerm_data_share.adl_ds) > 0 ? azurerm_data_share.adl_ds[0].name : "" ) + description = "The name of the Data Share." } \ No newline at end of file From b9a431cf70549b53a58e4e7a83fa9b661fa73fb6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 14 Feb 2023 15:26:23 +0000 Subject: [PATCH 09/16] terraform-docs: automated action --- .../data-share/data-share-account/README.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 terraform/data-share/data-share-account/README.md diff --git a/terraform/data-share/data-share-account/README.md b/terraform/data-share/data-share-account/README.md new file mode 100644 index 00000000..6b378ac2 --- /dev/null +++ b/terraform/data-share/data-share-account/README.md @@ -0,0 +1,26 @@ + +## Resources + +| Name | Type | +|------|------| +| [azurerm_data_share_account.adl_dsa](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_share_account) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes | +| [location](#input\_location) | Location of the resource group. | `string` | n/a | yes | +| [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no | +| [rg\_name](#input\_rg\_name) | Resource group name. | `string` | n/a | yes | +| [tags](#input\_tags) | A mapping of tags which should be assigned to the deployed resource. | `map(string)` | `{}` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | Resource identifier of the instance of Data Share account. | +| [identity](#output\_identity) | Principal ID and Tenant ID for the Service Principal associated with the identity of the Data Share account. | +| [name](#output\_name) | The name of the Data Share account. | +| [resource\_group\_name](#output\_resource\_group\_name) | Resource Group where the Data Share account exists. | + \ No newline at end of file From 4499afefcf9c193b6bf92598d13707a9b10ff406 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 14 Feb 2023 15:26:54 +0000 Subject: [PATCH 10/16] terraform-docs: automated action --- terraform/data-share/data-share/README.md | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 terraform/data-share/data-share/README.md diff --git a/terraform/data-share/data-share/README.md b/terraform/data-share/data-share/README.md new file mode 100644 index 00000000..bf5dd791 --- /dev/null +++ b/terraform/data-share/data-share/README.md @@ -0,0 +1,26 @@ + +## Resources + +| Name | Type | +|------|------| +| [azurerm_data_share.adl_ds](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_share) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [account\_id](#input\_account\_id) | The ID of the Data Share account in which the Data Share is created. | `string` | n/a | yes | +| [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes | +| [description](#input\_description) | The Data Share's description. | `string` | `""` | no | +| [kind](#input\_kind) | The kind of the Data Share. | `string` | `"InPlace"` | no | +| [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no | +| [snapshot\_schedule](#input\_snapshot\_schedule) | "
name - The name of the snapshot schedule.
recurrence - The interval of the synchronization with the source data. Possible values are Hour and Day.
start\_time - The synchronization with the source data's start time.
" |
map(
object(
{
name = optional(string)
recurrence = optional(string)
start_time = optional(string)
}
)
)
| `{}` | no | +| [terms](#input\_terms) | The terms of the Data Share. | `string` | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | Resource identifier of the instance of Data Share. | +| [name](#output\_name) | The name of the Data Share. | + \ No newline at end of file From d86461b7f06cd1fdc7de97919db5a08baff7be44 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Tue, 14 Feb 2023 16:56:57 +0100 Subject: [PATCH 11/16] Add terraform docs action --- .github/actions/run-terraform-docs/action.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/actions/run-terraform-docs/action.yml diff --git a/.github/actions/run-terraform-docs/action.yml b/.github/actions/run-terraform-docs/action.yml new file mode 100644 index 00000000..84a34a5f --- /dev/null +++ b/.github/actions/run-terraform-docs/action.yml @@ -0,0 +1,18 @@ +name: Run Terraform Docs +description: -- + +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Render terraform docs and push changes back to PR + uses: terraform-docs/gh-actions@main + with: + working-dir: "${{ env.terraform_workingdir }}" + output-file: README.md + output-method: inject + git-push: "true" + args: --hide providers --hide requirements --hide modules \ No newline at end of file From f299d4021d2c2e4d566e9f49e386640bc3d8743a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 14 Feb 2023 16:08:21 +0000 Subject: [PATCH 12/16] terraform-docs: automated action --- terraform/application-insights/README.md | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 terraform/application-insights/README.md diff --git a/terraform/application-insights/README.md b/terraform/application-insights/README.md new file mode 100644 index 00000000..7c61d416 --- /dev/null +++ b/terraform/application-insights/README.md @@ -0,0 +1,29 @@ + +## Resources + +| Name | Type | +|------|------| +| [azurerm_application_insights.adl_appi](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [application\_type](#input\_application\_type) | Specifies the type of Application Insights to create. | `string` | `"web"` | no | +| [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes | +| [internet\_ingestion\_enabled](#input\_internet\_ingestion\_enabled) | Should the Application Insights component support ingestion over the Public Internet? | `bool` | `false` | no | +| [internet\_query\_enabled](#input\_internet\_query\_enabled) | Should the Application Insights component support querying over the Public Internet? | `bool` | `false` | no | +| [location](#input\_location) | Location of the resource group. | `string` | n/a | yes | +| [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no | +| [rg\_name](#input\_rg\_name) | Resource group name. | `string` | n/a | yes | +| [tags](#input\_tags) | A mapping of tags which should be assigned to the deployed resource. | `map(string)` | `{}` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | n/a | +| [instrumentation\_key](#output\_instrumentation\_key) | n/a | +| [name](#output\_name) | n/a | +| [resource\_group\_name](#output\_resource\_group\_name) | n/a | + \ No newline at end of file From f332d9d561a45819f5987d2befe5f61ec2719917 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Tue, 14 Feb 2023 18:34:58 +0100 Subject: [PATCH 13/16] trigger actions --- terraform/data-share/data-share/test/unit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/data-share/data-share/test/unit_test.go b/terraform/data-share/data-share/test/unit_test.go index 745e336a..7ed1307a 100644 --- a/terraform/data-share/data-share/test/unit_test.go +++ b/terraform/data-share/data-share/test/unit_test.go @@ -31,4 +31,4 @@ func TestModule(t *testing.T) { assert.NotNil(id) name := terraform.Output(t, terraformOptions, "name") assert.NotNil(name) -} \ No newline at end of file +} From a8b2db5423a050bb23c08c90182bebf53a9bdbd8 Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo <41644064+nachoalonsoportillo@users.noreply.github.com> Date: Wed, 15 Feb 2023 14:06:32 +0100 Subject: [PATCH 14/16] Disable PR trigger for Log Analytics Cluster module --- .github/workflows/log-analytics-cluster.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/log-analytics-cluster.yml b/.github/workflows/log-analytics-cluster.yml index fed47ce4..04ded29f 100644 --- a/.github/workflows/log-analytics-cluster.yml +++ b/.github/workflows/log-analytics-cluster.yml @@ -1,13 +1,13 @@ name: Module:log-analytics-cluster on: workflow_dispatch: - pull_request: - branches: - - main - paths: - - '.github/workflows/log-analytics-cluster.yml' - - 'terraform/log-analytics/log-analytics-cluster/**' - - '.github/actions/**' +# pull_request: +# branches: +# - main +# paths: +# - '.github/workflows/log-analytics-cluster.yml' +# - 'terraform/log-analytics/log-analytics-cluster/**' +# - '.github/actions/**' env: terraform_workingdir: "terraform/log-analytics/log-analytics-cluster" @@ -74,4 +74,4 @@ jobs: - name: Unit-test run: go test -v -timeout 45m env: - GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" \ No newline at end of file + GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" From 94c29acca82141a21ef7ee15ca574abcc7a37fdd Mon Sep 17 00:00:00 2001 From: nachoalonsoportillo Date: Wed, 15 Feb 2023 19:19:00 +0100 Subject: [PATCH 15/16] Implement suggestions from @jdocampo to test snapshot schedule --- .../data-share/data-share/test/data_share.tf | 1 + .../data-share/data-share/test/variables.tf | 21 ++++++++++++++++++- terraform/data-share/data-share/variables.tf | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/terraform/data-share/data-share/test/data_share.tf b/terraform/data-share/data-share/test/data_share.tf index 96089972..6a084802 100644 --- a/terraform/data-share/data-share/test/data_share.tf +++ b/terraform/data-share/data-share/test/data_share.tf @@ -2,6 +2,7 @@ module "data_share" { source = "../" basename = random_string.postfix.result account_id = module.local_data_share_account.id + snapshot_schedule = var.snapshot_schedule } # Module dependencies diff --git a/terraform/data-share/data-share/test/variables.tf b/terraform/data-share/data-share/test/variables.tf index b025435b..42cd657f 100644 --- a/terraform/data-share/data-share/test/variables.tf +++ b/terraform/data-share/data-share/test/variables.tf @@ -7,4 +7,23 @@ resource "random_string" "postfix" { variable "location" { type = string default = "North Europe" -} \ No newline at end of file +} + +variable "snapshot_schedule" { + type = map( + object( + { + name = optional(string) + recurrence = optional(string) + start_time = optional(string) + } + ) + ) + default = { + snap_sched = { + name = "example-ss" + recurrence = "Day" + start_time = "2020-04-17T04:47:52.9614956Z" + } + } +} diff --git a/terraform/data-share/data-share/variables.tf b/terraform/data-share/data-share/variables.tf index b3d29c76..b70d95ab 100644 --- a/terraform/data-share/data-share/variables.tf +++ b/terraform/data-share/data-share/variables.tf @@ -25,7 +25,7 @@ variable "kind" { condition = contains(["copybased", "inplace"], lower(var.kind)) error_message = "Valid values for kind are \"CopyBased\" or \"InPlace\"." } - default = "InPlace" + default = "CopyBased" } variable "description" { From 1023857ed1c8407fd369530841595682ab17558f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 Feb 2023 18:27:25 +0000 Subject: [PATCH 16/16] terraform-docs: automated action --- terraform/data-share/data-share/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/data-share/data-share/README.md b/terraform/data-share/data-share/README.md index bf5dd791..e7711098 100644 --- a/terraform/data-share/data-share/README.md +++ b/terraform/data-share/data-share/README.md @@ -12,7 +12,7 @@ | [account\_id](#input\_account\_id) | The ID of the Data Share account in which the Data Share is created. | `string` | n/a | yes | | [basename](#input\_basename) | Basename of the module. | `string` | n/a | yes | | [description](#input\_description) | The Data Share's description. | `string` | `""` | no | -| [kind](#input\_kind) | The kind of the Data Share. | `string` | `"InPlace"` | no | +| [kind](#input\_kind) | The kind of the Data Share. | `string` | `"CopyBased"` | no | | [module\_enabled](#input\_module\_enabled) | Variable to enable or disable the module. | `bool` | `true` | no | | [snapshot\_schedule](#input\_snapshot\_schedule) | "
name - The name of the snapshot schedule.
recurrence - The interval of the synchronization with the source data. Possible values are Hour and Day.
start\_time - The synchronization with the source data's start time.
" |
map(
object(
{
name = optional(string)
recurrence = optional(string)
start_time = optional(string)
}
)
)
| `{}` | no | | [terms](#input\_terms) | The terms of the Data Share. | `string` | `""` | no |