我有一个azure devops管道来使用terraform构建资源。我正在使用Azure Devops的Terraform扩展。管道工作正常,能够使用terraform init构建资源,计划和应用stpes,但当我从代码中删除资源时,命令不会破坏资源。不知何故,它似乎甚至没有识别出有一个资源要删除。为什么会这样?我在自托管代理中运行管道。我将计划输出到x.tfplan并应用x. tfplan。我删除了它,以防计划被缓存,但问题仍然存在。下面是cicd文件的剥离版本。我可以确认-checkout: self
步骤确保了最新版本的代码被检出(我还通过检查命令行中目录的内容进行了确认)。
name: $(Build.BuildId).$(date:yyyyMMdd)
parameters:
- name: environment
displayName: "environment"
type: string
default: dev
values:
- dev
- test
trigger:
- main
pr: none
variables:
- group: "VG-SHARED"
- group: "VG-${{parameters.environment}}"
pool:
# vmImage: "windows-2019"
name: "SWC Self Hosted Windows 01"
stages:
- stage: "Deploy_Databricks_Resources"
displayName: "Deploy Databricks resources in ${{ parameters.environment }}"
jobs:
- deployment: "Deploy_Databricks_Resources"
displayName: "Deploy Databricks resources in ${{ parameters.environment }}"
environment: ${{ parameters.environment }}
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: TerraformInstaller@1
displayName: "tf install"
inputs:
terraformVersion: "1.4.0"
- task: TerraformTaskV4@4
displayName: "tf init"
inputs:
provider: "azurerm"
command: "init"
# commandOptions: '-reconfigure'
workingDirectory: '$(System.DefaultWorkingDirectory)\${{ parameters.environment }}'
backendServiceArm: "XX"
backendAzureRmResourceGroupName: "XX"
backendAzureRmStorageAccountName: "XXX" #"$(storageName)"
backendAzureRmContainerName: "tfstate"
backendAzureRmKey: "${{ parameters.environment }}-terraform.tfstate"
- task: TerraformTaskV4@4
displayName: "tf plan"
inputs:
provider: "azurerm"
command: "plan"
workingDirectory: '$(System.DefaultWorkingDirectory)\${{ parameters.environment }}'
commandOptions: "-var-file terraform.tfvars"
environmentServiceNameAzureRM: '$(azdoResourceConnection)'
- task: TerraformTaskV4@4
displayName: "tf apply"
inputs:
provider: "azurerm"
command: "apply"
workingDirectory: '$(System.DefaultWorkingDirectory)\${{ parameters.environment }}'
commandOptions: ""
environmentServiceNameAzureRM: '$(azdoResourceConnection)'
1条答案
按热度按时间xzlaal3s1#
如果您可以访问工作目录并可以运行这些命令
如果显示0个资源,则在运行terraform apply stage后将删除状态文件。