Terraform: updating providers

Terraform is built of several providers. Providers are a logical abstraction of an upstream API. They are responsible for understanding API interactions and exposing resources.

On the website of hashicorp, you can find all providers. Just click this link to check for more. On this page, you will notice the well-known public cloud providers, as well as some other vendors.

just a partial screenshot of the Hashicorp provider registry.

What to do with updated providers?

As everything in IT, updates will be released. Looking at new functionality at the cloud providers, API calls will eventually change. So new providers are necessary for successful automation to this cloud.

In a previous post on this site, I created a main.tf file with a reference to a specific version of the Google provider… This was done with the following lines in the main.tf

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "4.51.0"
    }
  }
}

When looking at the Google provider on the terraform registry, we can see that a new version of this provider is released. The latest version is (at the moment) 4.56.0.

We can make use of this new provider by changing the version in the main.tf file. However, the first time you make any changes in your tf files and issue a ‘terraform plan’ command, an error message is shown in the console.

ubuntu@terraform:~/terraform-gcp$ terraform plan
╷
│ Error: Inconsistent dependency lock file
│ 
│ The following dependency selections recorded in the lock file are inconsistent with the current configuration:
│   - provider registry.terraform.io/hashicorp/google: locked version selection 4.51.0 doesn't match the updated version constraints "4.56.0"
│ 
│ To update the locked dependency selections to match a changed configuration, run:
│   terraform init -upgrade
╵
ubuntu@terraform:~/terraform-gcp$ 

So,changing a version in your configuration files will not automatically download the new version. You have to issue the command ‘terraform init -upgrade’. After this command, the ‘terraform plan’ command is running smoothly.

ubuntu@terraform:~/terraform-gcp$ terraform init -upgrade

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/google versions matching "4.56.0"...
- Installing hashicorp/google v4.56.0...
- Installed hashicorp/google v4.56.0 (signed by HashiCorp)

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
ubuntu@terraform:~/terraform-gcp$ terraform plan
google_compute_network.vpc_network: Refreshing state... [id=projects/terraform-gcp-380221/global/networks/terraform-network]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # google_compute_network.test_network will be created
  + resource "google_compute_network" "test_network" {
      + auto_create_subnetworks         = true
      + delete_default_routes_on_create = false
      + gateway_ipv4                    = (known after apply)
      + id                              = (known after apply)
      + internal_ipv6_range             = (known after apply)
      + mtu                             = (known after apply)
      + name                            = "terraform-test-network"
      + project                         = (known after apply)
      + routing_mode                    = (known after apply)
      + self_link                       = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.
ubuntu@terraform:~/terraform-gcp$ 

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.