From 4a4101bc8ce1ab68c7daa8e4542376d8282e6908 Mon Sep 17 00:00:00 2001 From: Archit Chopra <87892837+13archit@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:21:30 +0530 Subject: [PATCH] fix: Updates workflows and remove deprecation (#9) * fix: Updates workflows and remove deprecation * fix: Update tfcheck workflow directory --- .github/workflows/auto_assignee.yml | 14 ++++ .github/workflows/automerge.yml | 11 +++ .github/workflows/changelog.yml | 2 +- .github/workflows/readme.yml | 59 +++------------ .github/workflows/semantic-releaser.yml | 30 -------- .github/workflows/static-checks.yml | 74 ------------------- .github/workflows/tf-check.yml | 19 +++++ .github/workflows/tflint.yml | 11 +++ README.yaml | 23 +++--- _examples/AzMonitor-ActionGroups/outputs.tf | 1 - _examples/AzMonitor-ActionGroups/variables.tf | 0 _examples/AzMonitor-MetricAlerts/outputs.tf | 1 - _examples/AzMonitor-MetricAlerts/variables.tf | 0 _test/monitor_test.go | 33 --------- .../AzMonitor-ActionGroups/example.tf | 1 + examples/AzMonitor-ActionGroups/outputs.tf | 3 + .../AzMonitor-ActionGroups/versions.tf | 2 +- .../AzMonitor-ActivityLogAlerts/example.tf | 3 +- .../AzMonitor-ActivityLogAlerts}/versions.tf | 2 +- .../AzMonitor-MetricAlerts/example.tf | 4 +- examples/AzMonitor-MetricAlerts/versions.tf | 13 ++++ main.tf | 1 + versions.tf | 2 +- 23 files changed, 105 insertions(+), 204 deletions(-) create mode 100644 .github/workflows/auto_assignee.yml create mode 100644 .github/workflows/automerge.yml delete mode 100644 .github/workflows/semantic-releaser.yml delete mode 100644 .github/workflows/static-checks.yml create mode 100644 .github/workflows/tf-check.yml create mode 100644 .github/workflows/tflint.yml delete mode 100644 _examples/AzMonitor-ActionGroups/outputs.tf delete mode 100644 _examples/AzMonitor-ActionGroups/variables.tf delete mode 100644 _examples/AzMonitor-MetricAlerts/outputs.tf delete mode 100644 _examples/AzMonitor-MetricAlerts/variables.tf delete mode 100644 _test/monitor_test.go rename _examples/AzMonitor-ActionGroups/main.tf => examples/AzMonitor-ActionGroups/example.tf (94%) create mode 100644 examples/AzMonitor-ActionGroups/outputs.tf rename {_examples => examples}/AzMonitor-ActionGroups/versions.tf (86%) rename {_examples => examples}/AzMonitor-ActivityLogAlerts/example.tf (94%) rename {_examples/AzMonitor-MetricAlerts => examples/AzMonitor-ActivityLogAlerts}/versions.tf (86%) rename _examples/AzMonitor-MetricAlerts/main.tf => examples/AzMonitor-MetricAlerts/example.tf (97%) create mode 100644 examples/AzMonitor-MetricAlerts/versions.tf diff --git a/.github/workflows/auto_assignee.yml b/.github/workflows/auto_assignee.yml new file mode 100644 index 0000000..77d5fdf --- /dev/null +++ b/.github/workflows/auto_assignee.yml @@ -0,0 +1,14 @@ +name: Auto Assign PRs + +on: + pull_request: + types: [opened, reopened] + + workflow_dispatch: +jobs: + assignee: + uses: clouddrove/github-shared-workflows/.github/workflows/auto_assignee.yml@master + secrets: + GITHUB: ${{ secrets.GITHUB }} + with: + assignees: 'clouddrove-ci' \ No newline at end of file diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000..3711a47 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,11 @@ +--- + name: Auto merge + on: + pull_request: + jobs: + auto-merge: + uses: clouddrove/github-shared-workflows/.github/workflows/auto_merge.yml@master + secrets: + GITHUB: ${{ secrets.GITHUB }} + with: + tfcheck: 'example-action_group / Check code format' \ No newline at end of file diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 3e88b85..4b735f5 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -6,7 +6,7 @@ on: - "*" workflow_dispatch: jobs: - call-workflow-changelog: + changelog: uses: clouddrove/github-shared-workflows/.github/workflows/changelog.yml@master secrets: inherit with: diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index 8b60bee..444164d 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -1,54 +1,15 @@ -name: 'Create README.md file' +name: Readme Workflow on: push: branches: - master - + paths-ignore: + - 'README.md' + - 'docs/**' + workflow_dispatch: jobs: - readme-create: - name: 'readme-create' - runs-on: ubuntu-latest - steps: - - name: 'Checkout' - uses: actions/checkout@master - - - name: 'Set up Python 3.7' - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: 'create readme' - uses: 'clouddrove/github-actions@v9.0.2' - with: - actions_subcommand: 'readme' - github_token: '${{ secrets.GITHUB }}' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - - name: 'pre-commit check errors' - uses: pre-commit/action@v2.0.0 - continue-on-error: true - - - name: 'pre-commit fix erros' - uses: pre-commit/action@v2.0.0 - continue-on-error: true - - - name: 'push readme' - uses: 'clouddrove/github-actions@v9.0.2' - continue-on-error: true - with: - actions_subcommand: 'push' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: 'Slack Notification' - uses: clouddrove/action-slack@v2 - with: - status: ${{ job.status }} - fields: repo,author - author_name: 'CloudDrove' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required - if: always() + README: + uses: clouddrove/github-shared-workflows/.github/workflows/readme.yml@master + secrets: + TOKEN : ${{ secrets.GITHUB }} + SLACK_WEBHOOK_TERRAFORM: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} \ No newline at end of file diff --git a/.github/workflows/semantic-releaser.yml b/.github/workflows/semantic-releaser.yml deleted file mode 100644 index 6e685a0..0000000 --- a/.github/workflows/semantic-releaser.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Release - -on: - push: - branches: - - main - paths: - - '**.tf' - - '!examples/**.tf' - -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Setup Node.js - uses: actions/setup-node@v1 - with: - node-version: 14 - - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} - run: npx semantic-release diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml deleted file mode 100644 index 42429cb..0000000 --- a/.github/workflows/static-checks.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: static-checks - -on: - pull_request: - -jobs: - versionExtract: - name: Get min/max versions - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Terraform min/max versions - id: minMax - uses: clowdhaus/terraform-min-max@main - outputs: - minVersion: ${{ steps.minMax.outputs.minVersion }} - maxVersion: ${{ steps.minMax.outputs.maxVersion }} - - versionEvaluate: - name: Evaluate Terraform versions - runs-on: ubuntu-latest - needs: versionExtract - strategy: - fail-fast: false - matrix: - version: - - ${{ needs.versionExtract.outputs.minVersion }} - - ${{ needs.versionExtract.outputs.maxVersion }} - directory: - - _examples/ - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install Terraform v${{ matrix.version }} - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: ${{ matrix.version }} - - - name: Init & validate v${{ matrix.version }} - run: | - cd ${{ matrix.directory }} - terraform init - terraform validate - - name: tflint - uses: reviewdog/action-tflint@master - with: - tflint_version: v0.29.0 - github_token: ${{ secrets.GITHUB_TOKEN }} - working_directory: ${{ matrix.directory }} - fail_on_error: 'true' - filter_mode: 'nofilter' - flags: '--module' - - format: - name: Check code format - runs-on: ubuntu-latest - needs: versionExtract - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }} - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: ${{ needs.versionExtract.outputs.maxVersion }} - - - name: Check Terraform format changes - run: terraform fmt --recursive -check=true diff --git a/.github/workflows/tf-check.yml b/.github/workflows/tf-check.yml new file mode 100644 index 0000000..59cfc42 --- /dev/null +++ b/.github/workflows/tf-check.yml @@ -0,0 +1,19 @@ +name: tf-checks +on: + push: + branches: [ master ] + pull_request: + workflow_dispatch: +jobs: + example-action_group: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './examples/AzMonitor-ActionGroups' + example-activity_log_alert: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './examples/AzMonitor-ActivityLogAlerts' + example-metric_alerts: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './examples/AzMonitor-MetricAlerts' \ No newline at end of file diff --git a/.github/workflows/tflint.yml b/.github/workflows/tflint.yml new file mode 100644 index 0000000..ee98182 --- /dev/null +++ b/.github/workflows/tflint.yml @@ -0,0 +1,11 @@ +name: tf-lint +on: + push: + branches: [ master ] + pull_request: + workflow_dispatch: +jobs: + tf-lint: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-lint.yml@master + secrets: + GITHUB: ${{ secrets.GITHUB }} \ No newline at end of file diff --git a/README.yaml b/README.yaml index 252eae9..0220c09 100644 --- a/README.yaml +++ b/README.yaml @@ -4,8 +4,9 @@ # Run `make readme` to rebuild the `README.md` # + # Name of this project -name : Terraform AZURE MONITOR ALERTS +name: Terraform AZURE MONITOR ALERTS # License of this project license: "APACHE" @@ -15,21 +16,25 @@ github_repo: clouddrove/terraform-azure-monitor-alerts # Badges to display badges: - - name: "Terraform" - image: "https://img.shields.io/badge/Terraform-v1.1.7-green" - url: "https://www.terraform.io" + - name: "Latest Release" + image: "https://img.shields.io/github/release/clouddrove/terraform-azure-monitor-alerts.svg" + url: "https://github.com/clouddrove/terraform-azure-monitor-alerts/releases/latest" + - name: "tfsec" + image: "https://github.com/clouddrove/terraform-azure-monitor-alerts/actions/workflows/tfsec.yml/badge.svg" + url: "https://github.com/clouddrove/terraform-azure-monitor-alerts/actions/workflows/tfsec.yml" - name: "Licence" image: "https://img.shields.io/badge/License-APACHE-blue.svg" url: "LICENSE.md" # description of this project description: |- - Terraform module to create monitor alerts resource on AZURE. + Terraform module to create subnet resource on AZURE. # extra content include: - "terraform.md" # How to use this project +# yamllint disable rule:line-length usage: |- Here are some examples of how you can use this module in your inventory structure: ### action group @@ -50,12 +55,12 @@ usage: |- actionGroupEmailReceiver = [ { name = "example" - email_address = "example@gmail.com" + email_address = "myemail@example.com" use_common_alert_schema = "true" }, { name = "test" - email_address = "test@gmail.com" + email_address = "myemail@example.com" use_common_alert_schema = "true" } ] @@ -81,7 +86,7 @@ usage: |- actionGroupEmailReceiver = [ { name = "test" - email_address = "mahesh.yadav@clouddrove.com" + email_address = "myemail@example.com" use_common_alert_schema = "true" }, { @@ -119,4 +124,4 @@ usage: |- } - ``` + ``` \ No newline at end of file diff --git a/_examples/AzMonitor-ActionGroups/outputs.tf b/_examples/AzMonitor-ActionGroups/outputs.tf deleted file mode 100644 index 8b13789..0000000 --- a/_examples/AzMonitor-ActionGroups/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/_examples/AzMonitor-ActionGroups/variables.tf b/_examples/AzMonitor-ActionGroups/variables.tf deleted file mode 100644 index e69de29..0000000 diff --git a/_examples/AzMonitor-MetricAlerts/outputs.tf b/_examples/AzMonitor-MetricAlerts/outputs.tf deleted file mode 100644 index 8b13789..0000000 --- a/_examples/AzMonitor-MetricAlerts/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/_examples/AzMonitor-MetricAlerts/variables.tf b/_examples/AzMonitor-MetricAlerts/variables.tf deleted file mode 100644 index e69de29..0000000 diff --git a/_test/monitor_test.go b/_test/monitor_test.go deleted file mode 100644 index dc8b918..0000000 --- a/_test/monitor_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Managed By : CloudDrove -// Description : This Terratest is used to test the Terraform VPC module. -// Copyright @ CloudDrove. All Right Reserved. -package test - -import ( - "testing" - "github.com/gruntwork-io/terratest/modules/terraform" - "github.com/stretchr/testify/assert" -) - -func Test(t *testing.T) { - t.Parallel() - - terraformOptions := &terraform.Options{ - // Source path of Terraform directory. - TerraformDir: "../_example", - } - - // This will run 'terraform init' and 'terraform application' and will fail the test if any errors occur - terraform.InitAndApply(t, terraformOptions) - - // To clean up any resources that have been created, run 'terraform destroy' towards the end of the test - defer terraform.Destroy(t, terraformOptions) - - // To get the value of an output variable, run 'terraform output' - Id := terraform.Output(t, terraformOptions, "monitor_id") - Tags := terraform.OutputMap(t, terraformOptions, "tags") - - // Check that we get back the outputs that we expect - assert.Equal(t, "test-clouddrove-monitor", Tags["Name"]) - assert.Contains(t, Id, "/subscriptions") -} diff --git a/_examples/AzMonitor-ActionGroups/main.tf b/examples/AzMonitor-ActionGroups/example.tf similarity index 94% rename from _examples/AzMonitor-ActionGroups/main.tf rename to examples/AzMonitor-ActionGroups/example.tf index 6076d31..8908010 100644 --- a/_examples/AzMonitor-ActionGroups/main.tf +++ b/examples/AzMonitor-ActionGroups/example.tf @@ -1,6 +1,7 @@ provider "azurerm" { features { } + subscription_id = "000000-11111-1223-XXX-XXXXXXXXXXXX" } module "resource_group" { diff --git a/examples/AzMonitor-ActionGroups/outputs.tf b/examples/AzMonitor-ActionGroups/outputs.tf new file mode 100644 index 0000000..8756780 --- /dev/null +++ b/examples/AzMonitor-ActionGroups/outputs.tf @@ -0,0 +1,3 @@ +output "action-group" { + value = module.azmonitor-action-groups.ag +} \ No newline at end of file diff --git a/_examples/AzMonitor-ActionGroups/versions.tf b/examples/AzMonitor-ActionGroups/versions.tf similarity index 86% rename from _examples/AzMonitor-ActionGroups/versions.tf rename to examples/AzMonitor-ActionGroups/versions.tf index 55c5a8f..7b05c20 100644 --- a/_examples/AzMonitor-ActionGroups/versions.tf +++ b/examples/AzMonitor-ActionGroups/versions.tf @@ -7,7 +7,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">=2.90.0" + version = ">=4.0.0" } } } diff --git a/_examples/AzMonitor-ActivityLogAlerts/example.tf b/examples/AzMonitor-ActivityLogAlerts/example.tf similarity index 94% rename from _examples/AzMonitor-ActivityLogAlerts/example.tf rename to examples/AzMonitor-ActivityLogAlerts/example.tf index 8b0c235..06f2088 100644 --- a/_examples/AzMonitor-ActivityLogAlerts/example.tf +++ b/examples/AzMonitor-ActivityLogAlerts/example.tf @@ -1,5 +1,6 @@ provider "azurerm" { features {} + subscription_id = "000000-11111-1223-XXX-XXXXXXXXXXXX" } module "resource_group" { @@ -26,7 +27,7 @@ module "azmonitor-action-group" { actionGroupEmailReceiver = [ { name = "test" - email_address = "archit.chopra@clouddrove.com" + email_address = "myemail@example.com" use_common_alert_schema = "false" } ] diff --git a/_examples/AzMonitor-MetricAlerts/versions.tf b/examples/AzMonitor-ActivityLogAlerts/versions.tf similarity index 86% rename from _examples/AzMonitor-MetricAlerts/versions.tf rename to examples/AzMonitor-ActivityLogAlerts/versions.tf index 55c5a8f..7b05c20 100644 --- a/_examples/AzMonitor-MetricAlerts/versions.tf +++ b/examples/AzMonitor-ActivityLogAlerts/versions.tf @@ -7,7 +7,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">=2.90.0" + version = ">=4.0.0" } } } diff --git a/_examples/AzMonitor-MetricAlerts/main.tf b/examples/AzMonitor-MetricAlerts/example.tf similarity index 97% rename from _examples/AzMonitor-MetricAlerts/main.tf rename to examples/AzMonitor-MetricAlerts/example.tf index e588be0..9257943 100644 --- a/_examples/AzMonitor-MetricAlerts/main.tf +++ b/examples/AzMonitor-MetricAlerts/example.tf @@ -1,6 +1,7 @@ provider "azurerm" { features { } + subscription_id = "000000-11111-1223-XXX-XXXXXXXXXXXX" } module "resource_group" { @@ -49,7 +50,7 @@ data "azurerm_monitor_action_group" "example" { data "azurerm_kubernetes_cluster" "example" { depends_on = [module.resource_group] - name = "testing" + name = "mycluster" resource_group_name = module.resource_group.resource_group_name } @@ -99,6 +100,5 @@ module "azmonitor-metric-alerts" { alertTargetResourceLoc = data.azurerm_kubernetes_cluster.example.location actionGroupID = data.azurerm_monitor_action_group.example.id } - } } diff --git a/examples/AzMonitor-MetricAlerts/versions.tf b/examples/AzMonitor-MetricAlerts/versions.tf new file mode 100644 index 0000000..7b05c20 --- /dev/null +++ b/examples/AzMonitor-MetricAlerts/versions.tf @@ -0,0 +1,13 @@ +# Terraform version +terraform { + required_version = ">= 1.0.0" +} + +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">=4.0.0" + } + } +} diff --git a/main.tf b/main.tf index e9eb002..84976a9 100644 --- a/main.tf +++ b/main.tf @@ -58,6 +58,7 @@ resource "azurerm_monitor_activity_log_alert" "main" { for_each = var.activity_log_alert name = each.value.alertname resource_group_name = each.value.alertrg + location = lookup(each.value, "location", "global") scopes = each.value.alertscopes description = each.value.description diff --git a/versions.tf b/versions.tf index 55c5a8f..7b05c20 100644 --- a/versions.tf +++ b/versions.tf @@ -7,7 +7,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">=2.90.0" + version = ">=4.0.0" } } }