Skip to content

Terraform state commands ignores required_version #28025

@kubaj

Description

@kubaj

I found a nasty issue, where terraform ignores required_version field in the configuration. I switch between two environments with different versions of the terraform and I rely on the required_version field to take care of things.

I was trying to move a resource within the state to the module but unfortunately I used the different tf binary (with newer version) than I wanted to. Running the following command was successful, even though it shouldn't be:

terraform state mv [src] [dst]

Result of this is updated state.

Terraform Version

Terraform v0.14.7

Terraform Configuration Files

terraform {
  required_version = "~> 0.12.20"

  backend "gcs" {
    ...
  }
}

Debug Output

Crash Output

Expected Behavior

Running the terraform state commands verifies the version constrain defined in the required_version field and if the constrain is not fulfilled, terraform prints out the same error message as in the other commands:

This configuration does not support Terraform version 0.14.7. To proceed,
either choose another supported Terraform version or update this version
constraint. Version constraints are normally set for good reason, so updating
the constraint may lead to other errors or unexpected behavior.

Actual Behavior

Command is successful when version constraint is not fulfilled and the state is upgraded to the newer version.

Steps to Reproduce

Mentioned above.

Additional Context

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconfirmeda Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions