minamijoyo / tfupdate

Update version constraints in your Terraform configurations
MIT License
539 stars 23 forks source link

I want to change the required_version in the version.tf file to > instead of equal sign(=). #64

Closed nanaones closed 2 years ago

nanaones commented 2 years ago

First of all, thank you for making such a wonderful tool.

When updating using tfupdate, all required_versions are set to "=" first. It's problematic to use as it bypasses backward compatibility in some situations.

Is there a way to force the user to select the equal sign part? Are there any updates planned for this part?

nanaones commented 2 years ago

now result :

terraform {
  required_version = "1.1.2"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.70.0"
    }
  }
}

terraform official document, example

want to be :

terraform {
  required_version = ">= 1.1.2"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.70.0"
    }
  }
}
minamijoyo commented 2 years ago

Hi @nanaones, A value of version flag accepts any string literal. You can pass a version constraint as it is:

before

terraform {
  required_version = "1.1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.70.0"
    }
  }
}
$ tfupdate terraform -v ">= 1.1.2" main.tf

after

terraform {
  required_version = ">= 1.1.2"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.70.0"
    }
  }
}

Give it a try!

simonweil commented 2 years ago

Worked for me! Suggest to update the readme

minamijoyo commented 2 years ago

@simonweil Thank you for your suggestion. I mentioned it explicitly in README.