Azure DevOps error "inconsistent with the current configuration:"

Babychen Daisy, Dona 20 Reputation points
2023-08-26T05:11:19.8066667+00:00
2023-08-25T13:24:43.8832043Z │ Error: Inconsistent dependency lock file
2023-08-25T13:24:43.8845301Z │ 
2023-08-25T13:24:43.8846010Z │ The following dependency selections recorded in the lock file are
2023-08-25T13:24:43.8846408Z │ inconsistent with the current configuration:
2023-08-25T13:24:43.8846857Z │   - provider registry.terraform.io/hashicorp/azuread: required by this configuration but no version is selected
2023-08-25T13:24:43.8847312Z │   - provider registry.terraform.io/hashicorp/azurerm: required by this configuration but no version is selected
2023-08-25T13:24:43.8847619Z │ 
2023-08-25T13:24:43.8847957Z │ To make the initial dependency selections that will initialize the
2023-08-25T13:24:43.8857688Z │ dependency lock file, run:
2023-08-25T13:24:43.8858062Z │   terraform init


I am using Azure pipeline with DevOps and terraform. I am getting the above ereror. Please help.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,634 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 25,946 Reputation points
    2023-08-27T14:58:14.25+00:00

    I think your issue is related to the related to Terraform's dependency lock file. Starting with Terraform v0.14, a new feature was introduced: the dependency lock file (.terraform.lock.hcl). This file helps ensure consistent provider versions across all team members and CI/CD environments. When there's a mismatch between the Terraform configuration and this lock file, you might get errors like the one you've encountered.

    If you have any existing .terraform directory or .terraform.lock.hcl file in your repository or workspace, delete them. These can contain state and lock file data from previous Terraform runs.

       rm -rf .terraform .terraform.lock.hcl
    
    

    As the error suggests, you should run terraform init. This command will fetch the required providers and initialize the lock file.

       terraform init
    

    The .terraform.lock.hcl file, you should commit this to your repository.

       git add .terraform.lock.hcl
       git commit -m "Add/Update Terraform lock file"
       git push
    

    It's a good practice to specify versions for your providers. In your Terraform configurations, make sure you have something similar to:

    terraform {
         required_providers {
           azuread = {
             source  = "hashicorp/azuread"
             version = "~> 2.0"
           }
           azurerm = {
             source  = "hashicorp/azurerm"
             version = "~> 2.50"
           }
         }
       }
    

    Azure DevOps pipelines might cache data. If you still face the issue after following the above steps, try to reset or clear the pipeline cache. This ensures that old data doesn't interfere with your new configurations.

    0 comments No comments

  2. BYUN, JOONBUM 0 Reputation points
    2023-11-28T01:25:13.5966667+00:00

    Thanks a lot for your posting.

    It would be helpful if more details of below steps in Azure DevOps environment were provided;

    • How to find the .terraform folder and terraform.lock.hcl file
    • Which folder in the repository the terraform.lock.hcl file should be commited.
    • How to clear the DevOps pipeline cache data

    Thanks a lot.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.