I am trying to upgrade the terraform kubernetes provider to the latest version 2.7.1. The following is an excerpt from the current terraform configuration:
terraform {
required_version = ">= 0.14.9"
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.60.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0" # Trying to change this...
}
helm = {
source = "hashicorp/helm"
version = "2.3.0"
}
...
}
}
Following these instructions I tried:
to change the version to >= 2.5.0;
to change the version to 2.7.1 (or even 2.5.1, just for the test);
and run terraform init -upgrade. Unfortunately, attempt (1) has no effect, and (2) gives an error:
Upgrading modules...
[...]
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/kubernetes versions matching "2.5.0, >= 2.5.1"...
- Finding hashicorp/helm versions matching ">= 2.3.0, 2.3.0"...
[...]
- Using previously-installed hashicorp/helm v2.3.0
[...]
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/kubernetes: no available releases match the given constraints 2.5.0, >= 2.5.1
I tried to init a new project (in an empty directory) with the above, and it correctly installs version 2.7.1, therefore I presume the problem is with the pre-existing terraform state. How can I upgrade the provider?
Related
When I ran init:
Initializing modules...
Initializing the backend...
Initializing provider plugins...
Finding cloudflare/cloudflare versions matching "~> 3.0"...
Finding latest version of hashicorp/cloudflare...
Installing cloudflare/cloudflare v3.31.0...
Installed cloudflare/cloudflare v3.31.0 (signed by a HashiCorp partner, key ID DE413CEC881C3283)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/cloudflare: provider registry registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/cloudflare
Did you intend to use cloudflare/cloudflare? If so, you must specify that source address in each module which requires that provider. To see which modules are currently
depending on hashicorp/cloudflare, run the following command:
terraform providers
Module:
cat dns.tf
module "dns" {
source = "./dns"
}
Definition:
cat cloudflare.tf
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 3.0"
}
}
}
provider "cloudflare" {
email = "CLOUDFLARE_EMAIL"
api_key = "CLOUDFLARE_API_KEY"
}
We've been using older versions of both Terraform and the azurerm provider and I'm trying to update the code for newer (for us) versions of each, in this case:
Terraform: v0.13.7
azurerm: v2.25
As part of the recoding, I'm switching to using the Terraform provider block:
terraform {
required_version = "~> 0.13"
required_providers {
azurerm = {
version = "= 2.25.0"
source = "hashicorp/azurerm"
}
}
}
provider azurerm {
skip_provider_registration = true
features {}
}
Terraform is downloading v2.25 of the provider but also the most version v2.67:
$ terraform init
Initializing the backend...
Initializing provider plugins...
- terraform.io/builtin/terraform is built in to Terraform
- Finding hashicorp/azurerm versions matching "2.25.0"...
- Finding latest version of -/azurerm...
- Installing hashicorp/azurerm v2.25.0...
- Installed hashicorp/azurerm v2.25.0 (signed by HashiCorp)
- Installing -/azurerm v2.67.0...
- Installed -/azurerm v2.67.0 (signed by HashiCorp)
So far this doesn't seem to be an issue, but I cannot understand why it's downloading multiple versions. Could it be because, in another code file which defines the backend (we use Azure storage for Terraform state), it's seeing that "azurerm" reference and treating it as a "new" one?
terraform {
backend azurerm {
container_name = "terraforminfra-v2"
key = "state/postgres.tfstate"
}
}
OK, I figured it out ... the "old" reference to the provider was still in the Terraform state, which I think is what was triggering the download of the most current version.
I'm using tfenv to switch terraform versions.Lately I'm getting this error and i'm not sure how to solve this.
Can someone pls let me know what is happening here, why its not able to detect min-required version?
Error:
tfenv install min-required && tfenv use min-required && terraform init -backend=false ./stage; terraform validate -var="api_key=xxxx" ./stage
Error: Could not determine required_version based on your terraform sources.
Make sure at least one of your *tf files includes a required version section like
terraform {
required_version = ">= 0.0.0"
}
see https://www.terraform.io/docs/configuration/terraform.html for details
tfenv-min-required failed
grep: brackets ([ ]) not balanced
No versions matching 'min-required' found in remote
Makefile:
DUTY_VAR=-var=api_key=xxxx test: tfenv install min-required && tfenv use min-required && terraform init -backend=false ./stage; terraform validate ${DUTY_VAR} ./stage
Terraform folder/file structure:
|-terraform (directory)
|-modules ( directory)
| - main.tf
| - variables.tf
| - versions.tf
|
|-stage(root-module)(directory)
| - backend.tf
| - main.tf
| - .terraform-version
| - providers.tf
version.tf
terraform {
required_version = "0.11.13"
}
backend.tf
terraform {
required_version = "0.11.13"
backend "s3" {
bucket = "nonprod"
key = "tfstate/terraform.tfstate"
dynamodb_table = "terraform-state-lock"
region = "us-east-1"
encrypt = true
role_arn = "arn:aws:iam::zzzzzzz:role/yyy"
}
}
There are two parts in this answer as explained below,
Part 1
As specified in the error, please try to specify the terraform version in required_version setting as below,
required_version = ">= 0.11.13"
Please note the >=
Part 2
As per the Terraform documentation, modules should constrain only their minimum allowed versions of Terraform and providers, such as >= 0.12.0
Please refer the Terraform Version Constraint Documentation
So instead of Terraform version 0.11.13, try with version 0.12.0
I have a pipeline in Jenkins that allows me to change my AWS infrastructure with Terraform. The build failed yesterday because and I noticed the provider.aws changed from:
provider.aws: version = "~> 3.15"
to
provider.aws: version = "~> 3.20".
I understand that this includes breaking changes.
Does anyone know how I can manually change that number manually back to 3.15?
In Terraform 0.11 it was done with version attribute when the provider was declared, e.g.:
provider "aws" {
version = "3.15"
}
These days e.g. Terraform 0.13 it is done in the required_providers section, e.g.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.15"
}
}
}
Not sure, but I think in Terraform 0.12 both could be used.
Terraform 0.13 just came out (https://www.hashicorp.com/blog/announcing-hashicorp-terraform-0-13/) and it changes how to work with 3rd party providers (https://www.terraform.io/upgrade-guides/0-13.html#explicit-provider-source-locations).
I'm encountering an error when running terraform init:
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/ibm...
Error: Failed to install provider
Error while installing hashicorp/ibm: provider registry registry.terraform.io
does not have a provider named registry.terraform.io/hashicorp/ibm
This used to work before with Terraform 0.12.29 and the IBM provider 1.10.0.
Here are the instructions for Linux and the current versions of Terraform and the IBM provider:
Install Terraform
Download Terraform 0.13
wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
Unzip the provider
unzip terraform_0.13.0_linux_amd64.zip
Move it to a folder in your path, such as:
mv terraform /usr/local/bin/
Ensure the version is 0.13
terraform version
Install the IBM provider
Create the folder where the plugin will be put:
mkdir -p ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
Get the provider:
wget https://github.com/IBM-Cloud/terraform-provider-ibm/releases/download/v1.10.0/terraform-provider-ibm_1.10.0_linux_amd64.zip
Unzip the provider:
unzip terraform-provider-ibm_1.10.0_linux_amd64.zip
Move the provider to the folder previously created:
mv terraform-provider-ibm_v1.10.0 ~/.terraform.d/plugins/localdomain/provider/ibm/1.10.0/linux_amd64
Test with a simple Terraform file
Create main.tf
terraform {
required_providers {
ibm = {
source = "localdomain/provider/ibm"
version = "1.10.0"
}
}
}
variable ibmcloud_api_key {
}
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}
resource ibm_resource_group new_group {
name = "created-by-terraform"
}
Create terraform.tfvars and fill in your IBM Cloud API key:
ibmcloud_api_key="REPLACE_WITH_YOUR_KEY"
Initialize Terraform
terraform init
will result in:
Initializing the backend...
Initializing provider plugins...
- Finding localdomain/provider/ibm versions matching "1.10.0"...
- Installing localdomain/provider/ibm v1.10.0...
- Installed localdomain/provider/ibm v1.10.0 (unauthenticated)
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.
And apply
terraform apply
will result in:
...
Enter a value: yes
ibm_resource_group.new_group: Creating...
ibm_resource_group.new_group: Creation complete after 2s [id=2142c8122344458d59b8729708464a]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Happy terraforming!
The IBM Provider is now published to the repository so you can use the new terraform 13 provider syntax such as:
terraform {
required_version = ">= 0.13"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.11.2"
}
}
}
terraform {
required_version = ">= 0.13.3"
required_providers {
ibm = {
source = "ibm-cloud/ibm"
version = "1.12.0"
}
}
}
This will give you the latest version.