Providers - Dependency Lock File¶
Step-01: Introduction¶
- Understand the importance of Dependency Lock File which is introduced in Terraform v0.14
Step-02: Review the Terraform Manifests¶
- c1-versions.tf
- Discuss about Terraform, AWS and Random Pet Provider Versions
- c2-s3bucket.tf
- Discuss about Random Pet Resource
- Discuss about S3 Bucket Resource
- .terraform.lock.hcl
- Discuss about Provider Version, Version Constraints and Hashes
Step-03: Initialize and apply the configuration¶
# Initialize Terraform
terraform init
# Validate Terraform Configuration files
terraform validate
# Execute Terraform Plan
terraform plan
# Create Resources using Terraform Apply
terraform apply
.terraform.lock.hcl-ORIGINAL & .terraform.lock.hcl
- Backup .terraform.lock.hcl as .terraform.lock.hcl-FIRST-INIT
Step-04: Upgrade the AWS provider version¶
- For AWS Provider, with version constraint
version = ">= 2.0.0", it is going to upgrade to latest3.x.xversion with commandterraform init -upgrade - Review .terraform.lock.hcl
- Discuss about AWS Versions
- Compare
.terraform.lock.hcl-FIRST-INIT&.terraform.lock.hcl
Step-05: Apply Terraform configuration with latest AWS Provider¶
- Should fail due to S3 related latest changes came in AWS v3.x provider when compared to AWS v2.x provider
Step-06: Comment region in S3 Resource and try Terraform Apply¶
- It should work.
- When we do a major version upgrade to providers, it might break few features.
- So with
.terraform.lock.hcl, we can avoid this type of issues.
Step-07: Clean-Up¶
# Destroy Resources
terraform destroy
# Delete Terraform Files
rm -rf .terraform # We are not removing files named ".terraform.lock.hcl, .terraform.lock.hcl-ORIGINAL" which are needed for this demo for you.
rm -rf terraform.tfstate*
References¶
- Random Pet Provider
- Dependency Lock File
- Terraform New Features in v0.14
- AWS S3 Bucket Region - Read Only in AWS Provider V3.x
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
MARCH2026
Enroll Now on Udemy →
🎉 Offer