Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTofu Support #315

Closed
cameronattard opened this issue Aug 29, 2023 · 19 comments · Fixed by #435
Closed

OpenTofu Support #315

cameronattard opened this issue Aug 29, 2023 · 19 comments · Fixed by #435
Assignees
Labels
new feature New feature or request

Comments

@cameronattard
Copy link

Is your feature request related to a problem? Please describe.
Per https://opentf.org/announcement, a new fork of Terraform, OpenTF is being created.

Describe the solution you'd like
Allow using tfswitch to install and manage OpenTF versions in addition to Terraform versions.

@cameronattard cameronattard added the enhancement Refactor existing code for better performance and quality label Aug 29, 2023
@nitrocode
Copy link

Wouldn't something like the --mirror flag work for opentf ?

https://github.com/warrensbox/terraform-switcher#use-custom-mirror

@roni-frantchi
Copy link

Wouldn't something like the --mirror flag work for opentf ?

Hey @nitrocode - not quite.
Although we are looking to be fully compatible with legacy Terraform, the binary name, command (terraform vs opentf) are all going to be different.

@kislerdm
Copy link

Hey folks! tofu support would be indeed quite useful. WDYT about separating managers and introducing the tool to manage tofu versions only? So it'd be an implementation of tfswitch interface/CLI commands, but called tofuswitch.

The main motivation: to separate concerns because tofu shall be treated as a standalone software independent of terraform when it comes to distribution. It'd enable for clean migration of CI pipelines etc.

@nitrocode
Copy link

Same issue that affects listing versions in mirrors will also affect opentofu since there isn't a single non-paginated url containing every opentofu release.

Related issue

@nitrocode
Copy link

An option might be to switch from downloading terraform releases from the hashicorp page and download instead directly from github. Then it would be fairly simple to download the files from opentofu instead. The version check would then have to hit the github rest api or have an index url file passed in as an argument.

https://github.com/opentofu/opentofu/releases
https://github.com/hashicorp/terraform/releases

@nitrocode
Copy link

I made a page here that seems to line up similar to the terraform release page

https://nitrocode.github.io/opentofu/

@nitrocode
Copy link

nitrocode commented Jan 4, 2024

We'll probably need a way of overriding the versionPrefix since opentofu's prefix is tofu_

It might also be nice to override the rest of these too.

const (
defaultMirror = "https://releases.hashicorp.com/terraform"
defaultBin = "/usr/local/bin/terraform" //default bin installation dir
defaultLatest = ""
tfvFilename = ".terraform-version"
rcFilename = ".tfswitchrc"
tomlFilename = ".tfswitch.toml"
tgHclFilename = "terragrunt.hcl"
versionPrefix = "terraform_"
)

const (
installFile = "terraform"
versionPrefix = "terraform_"
installPath = ".terraform.versions"
recentFile = "RECENT"
defaultBin = "/usr/local/bin/terraform" //default bin installation dir
tfDarwinArm64StartVersion = "1.0.2"
)

@MatthewJohn
Copy link
Collaborator

MatthewJohn commented Feb 24, 2024

I'm interested in this issue, as we use tfswitch (or terraform-switcher ;) ) in Terrareg.

Once concern I could imagine is that, you're using Hashicorp's HCL library for obtaining the constraint from a terraform {} block:

terraform-switcher/main.go

Lines 430 to 435 in d7dfd1b

func installTFProvidedModule(dir string, custBinPath, mirrorURL *string) {
fmt.Printf("Reading required version from terraform file\n")
module, _ := tfconfig.LoadModule(dir)
tfconstraint := module.RequiredCore[0] //we skip duplicated definitions and use only first one
installFromConstraint(&tfconstraint, custBinPath, mirrorURL)
}

Do we know if OpenTofu are sticking with this format (are they planning on changing the name at some point?) and I assume they have their own fork of the libraries:

"github.com/hashicorp/hcl2/hclparse"

Edit: It looks like OpenTofu are still using hashicorp's hcl library and that library hasn't changed it's license.

@yermulnik
Copy link
Collaborator

Do we know if OpenTofu are sticking with this format (are they planning on changing the name at some point?)

https://opentofu.org/

Can I use OpenTofu as a drop-in replacement for Terraform? Is OpenTofu suitable for production use?

Right now, OpenTofu is a drop-in replacement for Terraform, as it's compatible with Terraform versions 1.5.x and most of 1.6.x. You don’t need to make any changes to your code to ensure compatibility.

Hopefully OpenTofu isn't going to break core features and syntax compatibility in any near future 🤞🏻

@kvendingoldo

This comment was marked as spam.

@yermulnik
Copy link
Collaborator

@kvendingoldo While I have nothing against tenv (I tried it myself and, well, I prefer tfswitch, that I can run w/o any args to get just what I need — to switch to latest TF version allowed by the version constraint), I would like to ask to refrain from posting misleading info like «A lot of users switched to that tool to unify version management in the world of Terraform».

tenv:
image
tfswitch:
image

Please be respectful and mindful.

PS: To the extent possible we'll make our best to look into OpenTofu and Terragrunt support to be implemented in tfswitch (though it is not a high-priority task at the moment I think). PRs are welcome since tfswitch has gain some energy lately.

@nitrocode
Copy link

The tenv doesn't help me unfortunately because it's not the cli that I'd need here.

Atlantis (and other apps) uses the underlying terraform-switcher's go libs so those would need to be updated so we can keep the implementation of how atlantis autoupdates terraform the same as how it could autoupdate opentofu.

@yermulnik
Copy link
Collaborator

Atlantis (and other apps) uses the underlying terraform-switcher's go libs so those would need to be updated so we can keep the implementation of how atlantis autoupdates terraform the same as how it could autoupdate opentofu.

Thanks for the update and details.
Is what you're referring to related to #192 by any chance? I mean how the Atlantis (and other apps) utilizes tfswitch as a library?

While we're a bit short on human power to implement OpenTofu support, we welcome contributions and we'll try our best to review them as fast as our capacity allows.

@kvendingoldo

This comment was marked as spam.

@nitrocode
Copy link

It's unrelated to the issue you mentioned.

See this issue for the lower level details runatlantis/atlantis#4339.

@MatrixCrawler MatrixCrawler added new feature New feature or request and removed enhancement Refactor existing code for better performance and quality labels Apr 26, 2024
@yermulnik yermulnik changed the title OpenTF Support OpenTofu Support Apr 26, 2024
MatthewJohn added a commit that referenced this issue May 27, 2024
MatthewJohn added a commit that referenced this issue May 27, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 28, 2024
…or when passing too many args

Issue #315

Co-authored-by: George L. Yermulnik <[email protected]>
MatthewJohn added a commit that referenced this issue May 28, 2024
This is to represent producT or Tool.
This avoids possible common naming for 'quiet'

Issue #315

Co-authored-by: George L. Yermulnik <[email protected]>
MatthewJohn added a commit that referenced this issue May 28, 2024
MatthewJohn added a commit that referenced this issue May 31, 2024
… to fetch versions before mirror URL default is set

Only update mirror URL, if it's not already been defined by the user

Issue #315
MatthewJohn added a commit that referenced this issue May 31, 2024
@nitrocode
Copy link

Thanks for implementing this @MatthewJohn

@warrensbox will there be a release soon?

@MatthewJohn
Copy link
Collaborator

Thanks for implementing this @MatthewJohn

@warrensbox will there be a release soon?

We're just doing some testing at the moment on the alpha release of this :)

@warrensbox
Copy link
Owner

Opentofu feature was released on https://github.com/warrensbox/terraform-switcher/releases/tag/v1.2.0

Latest bug fixed: v1.2.2 (mostly related to windows)

@yermulnik yermulnik unpinned this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants