From 4a5b0b4e3d33076dbf21502fc0ae0c651513e3c9 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 1 Feb 2024 16:30:37 -0500 Subject: [PATCH 01/20] Issue #3: testing terraform pipeline workflow --- terraform/main.tf | 25 +++++++++++++++++++++++++ terraform/variables.tf | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 terraform/main.tf create mode 100644 terraform/variables.tf diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 00000000..880983cd --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,25 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 2.0" + } + + } + + backend "azurerm" { + resource_group_name = "rg-ai-cfia-terraform-state" + storage_account_name = "tfcfiastate" + container_name = "infra-terraform-state" + key = "tf/terraform.tfstate" + } +} + +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "testResourceGroup-tf-ai-cfia" + location = var.region +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 00000000..8312752d --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,5 @@ +variable "region" { + description = "The Azure Regions in which the resources are located." + type = string + default = "Canada East" +} From 97ddbe76377b46ce09fc4f3ba9855300d0708439 Mon Sep 17 00:00:00 2001 From: Jonathan Lopez Date: Thu, 1 Feb 2024 16:29:21 -0500 Subject: [PATCH 02/20] Issue #3: Set up terraform pipeline for our infra repo (gh) with Azure Pipelines [skip ci] --- apply-terraform.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 apply-terraform.yml diff --git a/apply-terraform.yml b/apply-terraform.yml new file mode 100644 index 00000000..6d9d5f05 --- /dev/null +++ b/apply-terraform.yml @@ -0,0 +1,31 @@ +trigger: +- 3-create-a-kubernetes-cluster-for-azure-w-the-ingress-nginx + +pool: + vmImage: 'ubuntu-latest' +steps: +- task: TerraformTaskV1@0 + displayName: Terra Init + inputs: + provider: 'azurerm' + command: 'init' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' + backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' + backendAzureRmStorageAccountName: 'tfcfiastate' + backendAzureRmContainerName: 'infra-terraform-state' + backendAzureRmKey: 'tf/terraform.tfstate' +- task: TerraformTaskV1@0 + displayName: Terra Plan + inputs: + provider: 'azurerm' + command: 'plan' + workingDirectory: $(System.DefaultWorkingDirectory) + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' +- task: TerraformTaskV1@0 + displayName: Terra Apply + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: $(System.DefaultWorkingDirectory) + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' \ No newline at end of file From deaed317d95c0845cf4f16da92e5391bfc986be3 Mon Sep 17 00:00:00 2001 From: Jonathan Lopez Date: Thu, 1 Feb 2024 16:30:17 -0500 Subject: [PATCH 03/20] Issue #3(gh-ai-cfia-infra): Update with branch trigger --- apply-terraform.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 6d9d5f05..c9547f70 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -1,5 +1,7 @@ trigger: -- 3-create-a-kubernetes-cluster-for-azure-w-the-ingress-nginx + branches: + include: + - 3-create-a-kubernetes-cluster-for-azure-w-the-ingress-nginx pool: vmImage: 'ubuntu-latest' From abd27bbbdfaa7e89ee0005720889c6d7ed5cb18a Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 1 Feb 2024 16:44:20 -0500 Subject: [PATCH 04/20] Issue #3: testing with region typo fix --- apply-terraform.yml | 53 +++++++++++++++++++++--------------------- terraform/main.tf | 2 +- terraform/variables.tf | 2 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index c9547f70..4bfd05ff 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -1,33 +1,34 @@ +--- trigger: branches: include: - - 3-create-a-kubernetes-cluster-for-azure-w-the-ingress-nginx + - 3-create-a-kubernetes-cluster-for-azure-w-the-ingress-nginx pool: vmImage: 'ubuntu-latest' steps: -- task: TerraformTaskV1@0 - displayName: Terra Init - inputs: - provider: 'azurerm' - command: 'init' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' - backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' - backendAzureRmStorageAccountName: 'tfcfiastate' - backendAzureRmContainerName: 'infra-terraform-state' - backendAzureRmKey: 'tf/terraform.tfstate' -- task: TerraformTaskV1@0 - displayName: Terra Plan - inputs: - provider: 'azurerm' - command: 'plan' - workingDirectory: $(System.DefaultWorkingDirectory) - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' -- task: TerraformTaskV1@0 - displayName: Terra Apply - inputs: - provider: 'azurerm' - command: 'apply' - workingDirectory: $(System.DefaultWorkingDirectory) - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' \ No newline at end of file + - task: TerraformTaskV1@0 + displayName: Terra Init + inputs: + provider: 'azurerm' + command: 'init' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' + backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' + backendAzureRmStorageAccountName: 'tfcfiastate' + backendAzureRmContainerName: 'infra-terraform-state' + backendAzureRmKey: 'tf/terraform.tfstate' + - task: TerraformTaskV1@0 + displayName: Terra Plan + inputs: + provider: 'azurerm' + command: 'plan' + workingDirectory: $(System.DefaultWorkingDirectory) + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + - task: TerraformTaskV1@0 + displayName: Terra Apply + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: $(System.DefaultWorkingDirectory) + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' diff --git a/terraform/main.tf b/terraform/main.tf index 880983cd..be9b374c 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "~> 2.0" + version = "~> 3.25.0" } } diff --git a/terraform/variables.tf b/terraform/variables.tf index 8312752d..dcdad9c2 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,5 +1,5 @@ variable "region" { description = "The Azure Regions in which the resources are located." type = string - default = "Canada East" + default = "canadaeast" } From d71b21dbd91a9084b77be81045baa27018d40547 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 1 Feb 2024 17:01:03 -0500 Subject: [PATCH 05/20] Issue #3: try with newer action version --- apply-terraform.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 4bfd05ff..baa21f27 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -7,7 +7,7 @@ trigger: pool: vmImage: 'ubuntu-latest' steps: - - task: TerraformTaskV1@0 + - task: TerraformTaskV2@2 displayName: Terra Init inputs: provider: 'azurerm' @@ -18,6 +18,7 @@ steps: backendAzureRmStorageAccountName: 'tfcfiastate' backendAzureRmContainerName: 'infra-terraform-state' backendAzureRmKey: 'tf/terraform.tfstate' + - task: TerraformTaskV1@0 displayName: Terra Plan inputs: @@ -25,6 +26,7 @@ steps: command: 'plan' workingDirectory: $(System.DefaultWorkingDirectory) environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + - task: TerraformTaskV1@0 displayName: Terra Apply inputs: From 51c57038defa55d8d1d28d4a98bbfeefce5a6bbc Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Thu, 1 Feb 2024 17:04:44 -0500 Subject: [PATCH 06/20] Issue #3: add proper workingDirectory for every steps --- apply-terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index baa21f27..6c8b1af0 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -24,7 +24,7 @@ steps: inputs: provider: 'azurerm' command: 'plan' - workingDirectory: $(System.DefaultWorkingDirectory) + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' - task: TerraformTaskV1@0 @@ -32,5 +32,5 @@ steps: inputs: provider: 'azurerm' command: 'apply' - workingDirectory: $(System.DefaultWorkingDirectory) + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' From 021790c456abf5b83bb7666c8d7457ab44439428 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 10:49:36 -0500 Subject: [PATCH 07/20] Issue #28: added integration workflow for markdown, yaml, terraform linting and repo standards --- .github/workflows/infra-ci-workflow.yaml | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/infra-ci-workflow.yaml diff --git a/.github/workflows/infra-ci-workflow.yaml b/.github/workflows/infra-ci-workflow.yaml new file mode 100644 index 00000000..70c1fff6 --- /dev/null +++ b/.github/workflows/infra-ci-workflow.yaml @@ -0,0 +1,42 @@ +--- +name: Infra integration workflow + +on: + pull_request: + types: + - opened + - closed + - synchronize + +jobs: + + markdown-check: + uses: + ai-cfia/github-workflows/.github/workflows/workflow-markdown-check.yml@76-as-a-devops-i-would-like-to-fix-the-markdown-lint-workflow + + yaml-check: + uses: + ai-cfia/github-workflows/.github/workflows/workflow-yaml-check.yml@main + + repo-standard: + uses: + ai-cfia/github-workflows/.github/workflows/workflow-repo-standards-validation.yml@main + secrets: inherit + + terraform-lint: + name: Terraform Lint + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: latest + + - name: Terraform Initialization + run: terraform init + + - name: Terraform Format Check + run: terraform fmt -check From 75e0e25e0a11df6d6b8957616f118944c5c3a7b0 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 10:49:56 -0500 Subject: [PATCH 08/20] Issue #28: Approval workflow for terraform apply --- apply-terraform.yml | 66 ++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 1a013ff5..cf056aa1 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -2,35 +2,47 @@ trigger: branches: include: - - 28-as-a-devops-i-would-like-to-automate-azure-infrastructure-deployment-using-terraform + - main pool: vmImage: 'ubuntu-latest' -steps: - - task: TerraformTaskV2@2 - displayName: Terra Init - inputs: - provider: 'azurerm' - command: 'init' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' - backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' - backendAzureRmStorageAccountName: 'tfcfiastate' - backendAzureRmContainerName: 'infra-terraform-state' - backendAzureRmKey: 'tf/terraform.tfstate' - - task: TerraformTaskV1@0 - displayName: Terra Plan - inputs: - provider: 'azurerm' - command: 'plan' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' +jobs: + - job: TerraformInitPlan + displayName: 'Terraform Init and Plan' + steps: + - task: TerraformTaskV2@2 + displayName: Terra Init + inputs: + provider: 'azurerm' + command: 'init' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' + backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' + backendAzureRmStorageAccountName: 'tfcfiastate' + backendAzureRmContainerName: 'infra-terraform-state' + backendAzureRmKey: 'tf/terraform.tfstate' - - task: TerraformTaskV1@0 - displayName: Terra Apply - inputs: - provider: 'azurerm' - command: 'apply' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + - task: TerraformTaskV1@0 + displayName: Terra Plan + inputs: + provider: 'azurerm' + command: 'plan' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + + - job: TerraformApply + displayName: 'Terraform Apply' + pool: + vmImage: 'ubuntu-latest' + dependsOn: TerraformInitPlan + condition: succeeded() + environment: 'ProductionApproval' + steps: + - task: TerraformTaskV1@0 + displayName: Terra Apply + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' From 52d3cbadcaf458fc50a69504ec271dec95846e7b Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 10:53:28 -0500 Subject: [PATCH 09/20] Issue #28: Fix markdown lint checks on README,md --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 004b027d..c8e526b1 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,24 @@ # Infrastructure Repository for ACIA-CFIA AI-Lab -This repository is dedicated to the infrastructure management of the ACIA-CFIA AI-Lab. It contains scripts, configurations, and documentation pertinent to infrastructure and DevOps practices within the lab, facilitating setup, deployment, and management across multiple cloud platforms including AWS, GCP, and Azure. +This repository is dedicated to the infrastructure management of the ACIA-CFIA +AI-Lab. It contains scripts, configurations, and documentation pertinent to +infrastructure and DevOps practices within the lab, facilitating setup, +deployment, and management across multiple cloud platforms including AWS, GCP, +and Azure. -## Contents: +## Contents -Cross-Cloud Setup Scripts: Automation scripts for seamless configuration across AWS, GCP, and Azure, covering project initiation, billing account association, artifact repository orchestration, and service account setup. -GitHub Repository Creation Guide: Detailed instructions for creating new repositories in alignment with ACIA-CFIA standards. -Getting Started: +Cross-Cloud Setup Scripts: Automation scripts for seamless configuration across +AWS, GCP, and Azure, covering project initiation, billing account association, +artifact repository orchestration, and service account setup. GitHub Repository +Creation Guide: Detailed instructions for creating new repositories in alignment +with ACIA-CFIA standards. Getting Started: + +## Clone this repository -## Clone this repository. 1. Navigate to the desired script or documentation. 2. Follow the provided instructions. 3. Related Repositories: -Dev-Rel-Docs: Contains introductory files and documentation related to developer relations at ACIA-CFIA AI-Lab. +Dev-Rel-Docs: Contains introductory files and documentation related to developer +relations at ACIA-CFIA AI-Lab. From 35f2ea58bf0ef2f1679a6a8b895874e9ee30cc2a Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 13:12:30 -0500 Subject: [PATCH 10/20] Issue #28: Change to reusable workflow for tf linting, add tflint config file and add tf required version --- .github/workflows/infra-ci-workflow.yaml | 22 +++++----------------- .tflint.hcl | 22 ++++++++++++++++++++++ terraform/main.tf | 15 +++++++++------ terraform/variables.tf | 6 +++--- 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 .tflint.hcl diff --git a/.github/workflows/infra-ci-workflow.yaml b/.github/workflows/infra-ci-workflow.yaml index 70c1fff6..a95387e1 100644 --- a/.github/workflows/infra-ci-workflow.yaml +++ b/.github/workflows/infra-ci-workflow.yaml @@ -23,20 +23,8 @@ jobs: ai-cfia/github-workflows/.github/workflows/workflow-repo-standards-validation.yml@main secrets: inherit - terraform-lint: - name: Terraform Lint - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: latest - - - name: Terraform Initialization - run: terraform init - - - name: Terraform Format Check - run: terraform fmt -check + terraform-check: + uses: + ai-cfia/github-workflows/.github/workflows/workflow-terraform-check.yml@87-as-a-devops-i-would-like-to-add-terraform-lint-job-to-our-ci-workflow + with: + config-file: '.tflint.hcl' diff --git a/.tflint.hcl b/.tflint.hcl new file mode 100644 index 00000000..2b645ce4 --- /dev/null +++ b/.tflint.hcl @@ -0,0 +1,22 @@ +plugin "terraform" { + enabled = true + preset = "recommended" +} + +plugin "azurerm" { + enabled = true + version = "0.25.1" + source = "github.com/terraform-linters/tflint-ruleset-azurerm" +} + +plugin "aws" { + enabled = true + version = "0.29.0" + source = "github.com/terraform-linters/tflint-ruleset-aws" +} + +plugin "google" { + enabled = true + version = "0.26.0" + source = "github.com/terraform-linters/tflint-ruleset-google" +} \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index be9b374c..34278d99 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,22 +1,25 @@ terraform { + + required_version = ">= 1.7.2" + required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 3.25.0" } - + } backend "azurerm" { - resource_group_name = "rg-ai-cfia-terraform-state" - storage_account_name = "tfcfiastate" - container_name = "infra-terraform-state" - key = "tf/terraform.tfstate" + resource_group_name = "rg-ai-cfia-terraform-state" + storage_account_name = "tfcfiastate" + container_name = "infra-terraform-state" + key = "tf/terraform.tfstate" } } provider "azurerm" { - features {} +features {} } resource "azurerm_resource_group" "test" { diff --git a/terraform/variables.tf b/terraform/variables.tf index dcdad9c2..64e208a0 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,5 +1,5 @@ variable "region" { - description = "The Azure Regions in which the resources are located." - type = string - default = "canadaeast" + description = "The Azure Regions in which the resources are located." + type = string + default = "canadaeast" } From f4329afe129c66c6a4a61063cd53a076bc64350f Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 13:15:02 -0500 Subject: [PATCH 11/20] Issue #28: fix workflow input name --- .github/workflows/infra-ci-workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/infra-ci-workflow.yaml b/.github/workflows/infra-ci-workflow.yaml index a95387e1..b47946d7 100644 --- a/.github/workflows/infra-ci-workflow.yaml +++ b/.github/workflows/infra-ci-workflow.yaml @@ -27,4 +27,4 @@ jobs: uses: ai-cfia/github-workflows/.github/workflows/workflow-terraform-check.yml@87-as-a-devops-i-would-like-to-add-terraform-lint-job-to-our-ci-workflow with: - config-file: '.tflint.hcl' + config-file-path: '.tflint.hcl' From 2fad95169410de2dbbfc8d9e3d42d21c71ccee53 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 13:17:13 -0500 Subject: [PATCH 12/20] Issue #28: format terraform. It was a test of workflow to shows that it works --- terraform/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/main.tf b/terraform/main.tf index 34278d99..b90fcdb5 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -19,7 +19,7 @@ terraform { } provider "azurerm" { -features {} + features {} } resource "azurerm_resource_group" "test" { From 5ac5dfbaa268af75e88bb957a7dc416f2d805cbb Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 13:20:24 -0500 Subject: [PATCH 13/20] Issue #28: remove trailing space --- .github/workflows/infra-ci-workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/infra-ci-workflow.yaml b/.github/workflows/infra-ci-workflow.yaml index b47946d7..156dffa9 100644 --- a/.github/workflows/infra-ci-workflow.yaml +++ b/.github/workflows/infra-ci-workflow.yaml @@ -24,7 +24,7 @@ jobs: secrets: inherit terraform-check: - uses: + uses: ai-cfia/github-workflows/.github/workflows/workflow-terraform-check.yml@87-as-a-devops-i-would-like-to-add-terraform-lint-job-to-our-ci-workflow with: config-file-path: '.tflint.hcl' From 69f21d9722a76acff34f589df5814d88b6091aec Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 5 Feb 2024 15:50:39 -0500 Subject: [PATCH 14/20] Issue #28: remove Terraform code since it was just used as an example to prove working pipeline --- terraform/main.tf | 28 ---------------------------- terraform/variables.tf | 5 ----- 2 files changed, 33 deletions(-) delete mode 100644 terraform/main.tf delete mode 100644 terraform/variables.tf diff --git a/terraform/main.tf b/terraform/main.tf deleted file mode 100644 index b90fcdb5..00000000 --- a/terraform/main.tf +++ /dev/null @@ -1,28 +0,0 @@ -terraform { - - required_version = ">= 1.7.2" - - required_providers { - azurerm = { - source = "hashicorp/azurerm" - version = "~> 3.25.0" - } - - } - - backend "azurerm" { - resource_group_name = "rg-ai-cfia-terraform-state" - storage_account_name = "tfcfiastate" - container_name = "infra-terraform-state" - key = "tf/terraform.tfstate" - } -} - -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "testResourceGroup-tf-ai-cfia" - location = var.region -} diff --git a/terraform/variables.tf b/terraform/variables.tf deleted file mode 100644 index 64e208a0..00000000 --- a/terraform/variables.tf +++ /dev/null @@ -1,5 +0,0 @@ -variable "region" { - description = "The Azure Regions in which the resources are located." - type = string - default = "canadaeast" -} From 9521c0ac9774dacd04b2fa5e9f66e4b5a3f92dab Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 6 Feb 2024 12:03:47 -0500 Subject: [PATCH 15/20] Issue #28: set azure info as variables --- apply-terraform.yml | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index cf056aa1..1191dda2 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -7,6 +7,9 @@ trigger: pool: vmImage: 'ubuntu-latest' +variables: + - group: terraform-backend-settings + jobs: - job: TerraformInitPlan displayName: 'Terraform Init and Plan' @@ -17,11 +20,11 @@ jobs: provider: 'azurerm' command: 'init' workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - backendServiceArm: 'CFSC-AiLabChatbot-Sub-SP' - backendAzureRmResourceGroupName: 'rg-ai-cfia-terraform-state' - backendAzureRmStorageAccountName: 'tfcfiastate' - backendAzureRmContainerName: 'infra-terraform-state' - backendAzureRmKey: 'tf/terraform.tfstate' + backendServiceArm: '$(serviceConnectionName)' + backendAzureRmResourceGroupName: '$(resourceGroupName)' + backendAzureRmStorageAccountName: '$(storageAccountName)' + backendAzureRmContainerName: '$(containerName)' + backendAzureRmKey: '$(stateKey)' - task: TerraformTaskV1@0 displayName: Terra Plan @@ -29,20 +32,23 @@ jobs: provider: 'azurerm' command: 'plan' workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + environmentServiceNameAzureRM: '$(serviceConnectionName)' - - job: TerraformApply + - deployment: TerraformApply displayName: 'Terraform Apply' pool: vmImage: 'ubuntu-latest' dependsOn: TerraformInitPlan condition: succeeded() - environment: 'ProductionApproval' - steps: - - task: TerraformTaskV1@0 - displayName: Terra Apply - inputs: - provider: 'azurerm' - command: 'apply' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: 'CFSC-AiLabChatbot-Sub-SP' + environment: nameOfYourEnvironment + strategy: + runOnce: + deploy: + steps: + - task: TerraformTaskV1@0 + displayName: Terra Apply + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: '$(serviceConnectionName)' From 5a34470ba043c02e66170cd999eb06badaac8d12 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 6 Feb 2024 12:05:36 -0500 Subject: [PATCH 16/20] Issue #28: environment name typo --- apply-terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 1191dda2..1cdfafde 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -40,7 +40,7 @@ jobs: vmImage: 'ubuntu-latest' dependsOn: TerraformInitPlan condition: succeeded() - environment: nameOfYourEnvironment + environment: ProductionApproval strategy: runOnce: deploy: From 3587c28d3f51d1db6b3e93c9ac00524a3826e15b Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 6 Feb 2024 12:37:51 -0500 Subject: [PATCH 17/20] Issue #28: Add stage so that approval is only prompted for apply --- apply-terraform.yml | 87 +++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 1cdfafde..31887ac8 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -10,45 +10,54 @@ pool: variables: - group: terraform-backend-settings -jobs: - - job: TerraformInitPlan - displayName: 'Terraform Init and Plan' - steps: - - task: TerraformTaskV2@2 - displayName: Terra Init - inputs: - provider: 'azurerm' - command: 'init' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - backendServiceArm: '$(serviceConnectionName)' - backendAzureRmResourceGroupName: '$(resourceGroupName)' - backendAzureRmStorageAccountName: '$(storageAccountName)' - backendAzureRmContainerName: '$(containerName)' - backendAzureRmKey: '$(stateKey)' +stages: + - stage: InitAndPlan + displayName: 'Initialize and Plan' + jobs: + - job: TerraformInitPlan + displayName: 'Terraform Init and Plan' + steps: + - task: TerraformTaskV2@2 + displayName: Terra Init + inputs: + provider: 'azurerm' + command: 'init' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + backendServiceArm: '$(serviceConnectionName)' + backendAzureRmResourceGroupName: '$(resourceGroupName)' + backendAzureRmStorageAccountName: '$(storageAccountName)' + backendAzureRmContainerName: '$(containerName)' + backendAzureRmKey: '$(stateKey)' - - task: TerraformTaskV1@0 - displayName: Terra Plan - inputs: - provider: 'azurerm' - command: 'plan' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: '$(serviceConnectionName)' + - task: TerraformTaskV1@0 + displayName: Terra Plan + inputs: + provider: 'azurerm' + command: 'plan' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: '$(serviceConnectionName)' - - deployment: TerraformApply - displayName: 'Terraform Apply' - pool: - vmImage: 'ubuntu-latest' - dependsOn: TerraformInitPlan + - stage: Apply + displayName: 'Apply Terraform Plan' + dependsOn: InitAndPlan condition: succeeded() - environment: ProductionApproval - strategy: - runOnce: - deploy: - steps: - - task: TerraformTaskV1@0 - displayName: Terra Apply - inputs: - provider: 'azurerm' - command: 'apply' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: '$(serviceConnectionName)' + jobs: + - deployment: TerraformApply + displayName: 'Terraform Apply' + pool: + vmImage: 'ubuntu-latest' + environment: + name: 'ProductionApproval' + resourceType: 'virtualMachine' + strategy: + runOnce: + deploy: + steps: + - task: TerraformTaskV1@0 + displayName: 'Terra Apply' + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: + '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: '$(serviceConnectionName)' From 1eb468a8260e37f9c3db71816f0b0902d32c71ef Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 6 Feb 2024 13:12:24 -0500 Subject: [PATCH 18/20] Issue #28: Fix yaml lint errors --- apply-terraform.yml | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 31887ac8..5d68adeb 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -46,7 +46,7 @@ stages: displayName: 'Terraform Apply' pool: vmImage: 'ubuntu-latest' - environment: + environment: name: 'ProductionApproval' resourceType: 'virtualMachine' strategy: @@ -58,6 +58,29 @@ stages: inputs: provider: 'azurerm' command: 'apply' - workingDirectory: + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' environmentServiceNameAzureRM: '$(serviceConnectionName)' + - stage: Apply + displayName: 'Apply Terraform Plan' + dependsOn: InitAndPlan + condition: succeeded() + - deployment: TerraformApply + displayName: 'Terraform Apply' + pool: + vmImage: 'ubuntu-latest' + dependsOn: TerraformInitPlan + condition: succeeded() + environment: ProductionApproval + strategy: + runOnce: + deploy: + steps: + + - task: TerraformTaskV1@0 + displayName: Terra Apply + inputs: + provider: 'azurerm' + command: 'apply' + workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' + environmentServiceNameAzureRM: '$(serviceConnectionName)' From f06006acf033dacc1c6321de94ea0e1a938a1275 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 6 Feb 2024 13:20:53 -0500 Subject: [PATCH 19/20] Issue #28: remove duplicate stage --- apply-terraform.yml | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/apply-terraform.yml b/apply-terraform.yml index 5d68adeb..1431d1cb 100644 --- a/apply-terraform.yml +++ b/apply-terraform.yml @@ -46,9 +46,7 @@ stages: displayName: 'Terraform Apply' pool: vmImage: 'ubuntu-latest' - environment: - name: 'ProductionApproval' - resourceType: 'virtualMachine' + environment: 'ProductionApproval' strategy: runOnce: deploy: @@ -61,26 +59,3 @@ stages: workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' environmentServiceNameAzureRM: '$(serviceConnectionName)' - - stage: Apply - displayName: 'Apply Terraform Plan' - dependsOn: InitAndPlan - condition: succeeded() - - deployment: TerraformApply - displayName: 'Terraform Apply' - pool: - vmImage: 'ubuntu-latest' - dependsOn: TerraformInitPlan - condition: succeeded() - environment: ProductionApproval - strategy: - runOnce: - deploy: - steps: - - - task: TerraformTaskV1@0 - displayName: Terra Apply - inputs: - provider: 'azurerm' - command: 'apply' - workingDirectory: '$(System.DefaultWorkingDirectory)/terraform' - environmentServiceNameAzureRM: '$(serviceConnectionName)' From bb2dfbfe866de56f4af2ff345d96472ec7e747d1 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 7 Feb 2024 08:46:53 -0500 Subject: [PATCH 20/20] Issue #28: EOF line and change reference to reusable workflow that was merged --- .github/workflows/infra-ci-workflow.yaml | 2 +- .tflint.hcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/infra-ci-workflow.yaml b/.github/workflows/infra-ci-workflow.yaml index 156dffa9..3f8a6949 100644 --- a/.github/workflows/infra-ci-workflow.yaml +++ b/.github/workflows/infra-ci-workflow.yaml @@ -25,6 +25,6 @@ jobs: terraform-check: uses: - ai-cfia/github-workflows/.github/workflows/workflow-terraform-check.yml@87-as-a-devops-i-would-like-to-add-terraform-lint-job-to-our-ci-workflow + ai-cfia/github-workflows/.github/workflows/workflow-terraform-check.yml@main with: config-file-path: '.tflint.hcl' diff --git a/.tflint.hcl b/.tflint.hcl index 2b645ce4..668d0b11 100644 --- a/.tflint.hcl +++ b/.tflint.hcl @@ -19,4 +19,4 @@ plugin "google" { enabled = true version = "0.26.0" source = "github.com/terraform-linters/tflint-ruleset-google" -} \ No newline at end of file +}