Giter Site home page Giter Site logo

Comments (2)

j4t1nd3r avatar j4t1nd3r commented on June 10, 2024

I did get it to work by:

  • using a different variable and assigning it on a per task basis to TF_WORKSPACE.
  • use a TF workspace select -or-create task to create a workspace
trigger:
  branches:
    include:
      - main

pool:
  vmImage: "windows-latest"

jobs:
  - job: TF_WORKSPACE_def
    displayName: "TF_WORKSPACE def"
    steps:
      - task: TerraformInstaller@1
        displayName: "Terraform_install 1.5.7"
        inputs:
          terraformVersion: 1.5.7

      - task: TerraformTaskV4@4
        displayName: "Terraform_init"
        inputs:
          provider: "azurerm"
          command: "init"
          workingDirectory: tf
          backendServiceArm: "REMOVED-platform-nonprod (REMOVED)"
          backendAzureRmResourceGroupName: "REMOVED-nonprod-base-infra-rg"
          backendAzureRmStorageAccountName: REMOVED
          backendAzureRmContainerName: tfstate-jat
          backendAzureRmKey: "jr-sandbox-tf-wp"

      - task: TerraformTaskV4@4
        displayName: "Terraform_plan"
        inputs:
          workingDirectory: tf
          command: plan
          environmentServiceNameAzureRM: "REMOVED-platform-nonprod (REMOVED)"

  - job: TF_WORKSPACE_dev
    displayName: "TF_WORKSPACE dev"
    dependsOn: TF_WORKSPACE_def
    variables:
      scope: dev
    steps:
      - task: TerraformInstaller@1
        displayName: "Terraform_install 1.5.7"
        inputs:
          terraformVersion: 1.5.7

      - task: TerraformTaskV4@4
        displayName: "Terraform_init"
        inputs:
          provider: "azurerm"
          command: "init"
          workingDirectory: tf
          backendServiceArm: "REMOVED-platform-nonprod (REMOVED)"
          backendAzureRmResourceGroupName: "REMOVED-nonprod-base-infra-rg"
          backendAzureRmStorageAccountName: REMOVED
          backendAzureRmContainerName: tfstate-jat
          backendAzureRmKey: "jr-sandbox-tf-wp"

      - task: TerraformTaskV4@4
        displayName: "Terraform_Workspace new|select"
        inputs:
          command: custom
          customCommand: workspace
          commandOptions: select -or-create $(scope)
          workingDirectory: tf
          environmentServiceNameAzureRM: "REMOVED-platform-nonprod (REMOVED)"

      - task: TerraformTaskV4@4
        displayName: "Terraform_plan"
        inputs:
          workingDirectory: tf
          command: plan
          environmentServiceNameAzureRM: "REMOVED-platform-nonprod (REMOVED)"
        env:
          TF_WORKSPACE: $(scope)

  - job: TF_WORKSPACE_test
    displayName: "TF_WORKSPACE test"
    dependsOn: TF_WORKSPACE_dev
    variables:
      scope: test
    steps:
      - task: TerraformInstaller@1
        displayName: "Terraform_install 1.5.7"
        inputs:
          terraformVersion: 1.5.7

      - task: TerraformTaskV4@4
        displayName: "Terraform_init"
        inputs:
          provider: "azurerm"
          command: "init"
          workingDirectory: tf
          backendServiceArm: "REMOVED-platform-nonprod (REMOVED)"
          backendAzureRmResourceGroupName: "REMOVED-nonprod-base-infra-rg"
          backendAzureRmStorageAccountName: REMOVED
          backendAzureRmContainerName: tfstate-jat
          backendAzureRmKey: "jr-sandbox-tf-wp"

      - task: TerraformTaskV4@4
        displayName: "Terraform_Workspace new|select"
        inputs:
          command: custom
          customCommand: workspace
          commandOptions: select -or-create $(scope)
          workingDirectory: tf
          environmentServiceNameAzureRM: "REMOVED-platform-nonprod (REMOVED)"

      - task: TerraformTaskV4@4
        displayName: "Terraform_plan"
        inputs:
          workingDirectory: tf
          command: plan
          environmentServiceNameAzureRM: "REMOVED-platform-nonprod (REMOVED)"
        env:
          TF_WORKSPACE: $(scope)

However I would still like to know what is with the inconsistency of TF_WORKSPACE of creating the first workspace and not the second one when it is set as mentioned in my original post.

from azure-pipelines-terraform.

mericstam avatar mericstam commented on June 10, 2024

Hi sorry for late reply. Looks like you solved the issue. I will take a look on the inconsistent behavior.

from azure-pipelines-terraform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.