Closed robmoss2k closed 5 months ago
Hello, thanks for creating an issue.
The version in the required_version
constraint should take priority over the version found in the state file. It looks like this isn't working properly. Can you share the contents of versions.tf
?
Number 1 in the version discovery list relates to Terraform Cloud/Enterprise workspaces, where the remote workspace version always takes priority.
This log shows the version coming from a local terraform.tfstate
, the lowest priority version source. Are you using the s3
backend, or the local backend? Does a terraform.tfstate
file exist in the repo?
I think number 1 is inspecting my S3 remote state? Here is versions.tf
:
provider "aws" {
region = var.region
profile = "robmoss"
default_tags {
tags = {
Owner = var.owner
purpose = var.purpose
Name = "${var.owner}: ${var.purpose}"
map-migrated = "d-server-001j25bgmzlvy7"
}
}
}
provider "tls" {}
provider "http" {}
There is no terraform.tfstate
file in the repo.
I updated the original issue to contain debug-enabled logs.
Hold on a minute. I've uploaded the log from the wrong run. Updating again - sorry!
Edited: updated with the stuff from the correct repo. From the logs, my assumption was wrong and my PR is useless.
OK, here it is. I have this:
required_version = ">= v1.8.0"
According to the documentation, I should have this:
required_version = ">= 1.8.0"
However, terraform
doesn't throw an error when you include the v
, so terraform
is behaving in a way that dflook/terraform-version
doesn't expect.
That's a good find, I didn't know Terraform allowed that.
I didn't know Terraform wasn't supposed to allow anything else!
Version 1.42.1 has been released that allows a v
in the version number
major updates requiere the -upgrade flag anyway, so we need a way to pass it down to terraform init
Problem description
In the documentation, it specifies the following first two points for
terraform-version
:required_version
constraint in the Terraform configuration. If the constraint is range, the latest matching version is used.We aren't allowed to execute terraform locally, as there are loads of validation steps to prevent people from breaking things that run in the GitHub Actions. Therefore, if my last terraform apply was on version
1.7.5
and I've validated I can switch to1.8.0
, the only way I can do that is to change my required_version to==1.8.0
. Butterraform-version
ignores this when installing terraform, installing version1.7.5
, and then it barfs because terraform1.7.5
won't apply whenrequired_version
is set to==1.8.0
.Suggested fix:
required_version
overrides the version in the state file if it's newer.Terraform version
1.8.0
Backend
s3
Workflow YAML
Workflow log
Has debug logging been enabled?
ACTIONS_STEP_DEBUG
secret was set totrue
when capturing the workflow log above.