Failed to load “tfplan” as a plan file

I am performing a very simple testing on TF + AzureDevops pipeline. the plan stage is success but the Deploy stage is failing with Failed to load “tfplan” as a plan file

I can see a new plan file is generated in my azure blog storage container and I am using the same name in the plan and deploy stage job.

if I use terraform apply in the same job, then the job is success.

how do I ensure both the TerraformPlan and TerraformApply jobs using the same plan file?

Please help:

trigger:

main
pool:
vmImage: ‘ubuntu-latest’

variables:

group: KV-SQL-SERVER-TEST
stages:

stage: Plan
displayName: ‘Terraform Plan’
jobs:

job: TerraformPlan
displayName: ‘Terraform Plan’
steps:
task: TerraformInstaller@0
inputs:
terraformVersion: ‘latest’
script: |
terraform --version
terraform init -backend-config=“access_key=$(storagetest101-key1)”
terraform plan -out=tfplan
displayName: ‘Terraform Init and Plan’


stage: Deploy
displayName: ‘Terraform Apply’
jobs:

job: TerraformApply
displayName: ‘Terraform Apply’
steps:
task: TerraformInstaller@0
inputs:
terraformVersion: ‘latest’

script: |
terraform --version
terraform init -backend-config=“access_key=$(storagetest101-key1)”
terraform validate
terraform apply -auto-approve -input=false tfplan
displayName: ‘Terraform Init and Apply’

It’s the expected behavior. You are running terraform plan and terraform apply in the different jobs. When you use MS-hosted agents, each job will get a brand-new agent. That’s to say that your terraform plan and terraform apply are running on the different agents, so that terraform apply can’t find the target plan file.

As a workaround, you can publish the plan file into a build artifact in job “TerraformPlan” and download the artifact in job “TerraformApply” to consume the plan file. I have modified your yaml file as shown below.

trigger:
- main
pool:
  vmImage: ‘ubuntu-latest’

variables:
  group: KV-SQL-SERVER-TEST
stages:
- stage: Plan
  displayName: ‘Terraform Plan’
  jobs:
  - job: TerraformPlan
    displayName: ‘Terraform Plan’
    steps:
    - task: TerraformInstaller@0
      inputs:
        terraformVersion: ‘latest’
    - script: |
        terraform --version
        terraform init -backend-config=“access_key=$(storagetest101-key1)”
        terraform plan -out=tfplan
      displayName: ‘Terraform Init and Plan’
    
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(System.DefaultWorkingDirectory)'
        Contents: '*tfplan*'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'planfile'
        publishLocation: 'Container'

- stage: Deploy
  displayName: ‘Terraform Apply’
  jobs:
  - job: TerraformApply
    displayName: ‘Terraform Apply’
    steps:
    - task: DownloadBuildArtifacts@1
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'planfile'
        downloadPath: '$(System.DefaultWorkingDirectory)'
    - task: TerraformInstaller@0
      inputs:
        terraformVersion: ‘latest’

    - script: |
        terraform --version
        terraform init -backend-config=“access_key=$(storagetest101-key1)”
        terraform validate
        terraform apply -auto-approve -input=false planfile/tfplan
      displayName: ‘Terraform Init and Apply’

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật