How Do I Upgrade Terraform Providers?
- Docker
- Terraform
- An AWS EC2 Ubuntu Instance
Install Terraform
The official instructions for installing Terraform are here. I used Ubuntu-based EC2 for this "How do I", instructions for which are here.
Install Docker
The official instructions for installing Docker are here.
Step 1: Make a simple Configuration File.
terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "5.23.0"
}
}
}
Save the file as main.tf
Step 2: Execute terraform init.
terraform init
The initialization will commence, and show the following output on the screen
![](https://hestia.ghost.io/content/images/2024/05/image-19.png)
As part of initialization, a .terraform.lock.hcl file is also generated. This file stores a hash for each distinct Provider-Version pairing.
![](https://hestia.ghost.io/content/images/2024/05/image-20.png)
Step 3: Change the Provider version.
In main.tf, make a change (as shown below):
terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "5.27.0"
}
}
}
Change version from 5.23.0 to 5.27.0.
Step 4: Execute terraform init again.
A different Provider version warrants a new initialization of the terraform environment. However, this time, you should get an error instead of the happy green success message.
![](https://hestia.ghost.io/content/images/2024/05/image-21.png)
The .hcl file has the hash for 5.23.0 and is therefore confused when it finds 5.27.0 in the Configuration file.
Step 5: Execute terraform init with -upgrade flag.
terraform init -upgrade
![](https://hestia.ghost.io/content/images/2024/05/image-22.png)
I write to remember, and if, in the process, I can help someone learn about Containers, Orchestration (Docker Compose, Kubernetes), GitOps, DevSecOps, VR/AR, Architecture, and Data Management, that is just icing on the cake.