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.