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

v0.21+: Override mirror URL for terraform downloads #2701

Closed
1 task
nitrocode opened this issue Nov 21, 2022 · 5 comments · Fixed by #2843
Closed
1 task

v0.21+: Override mirror URL for terraform downloads #2701

nitrocode opened this issue Nov 21, 2022 · 5 comments · Fixed by #2843
Labels
bug Something isn't working regression Bug introduced in a new version

Comments

@nitrocode
Copy link
Member

nitrocode commented Nov 21, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Describe the user story

From comment #1776 (comment)

I think [mirrorURL] could be a configurable URL because some companies host TF exe in their private repos for setups with no public access and/or to control which TF versions are currently cleared to be used.

Describe the solution you'd like

Override the mirror URL to download terraform from airgapped environments using a flag such as --tf-download-mirror-url

The tf download url is in the user config

type UserConfig struct {

TFDownloadURL string `mapstructure:"tf-download-url"`

DefaultTFDownloadURL = "https://releases.hashicorp.com"

And it just needs to be passed here

var mirrorURL = "https://releases.hashicorp.com/terraform"

Here is how the tf downloading works

if defaultVersionStr != "" {
defaultVersion, err := version.NewVersion(defaultVersionStr)
if err != nil {
return nil, err
}
finalDefaultVersion = defaultVersion
ensureVersionFunc := func() {
// Since ensureVersion might end up downloading terraform,
// we call it asynchronously so as to not delay server startup.
versionsLock.Lock()
_, err := ensureVersion(log, tfDownloader, versions, defaultVersion, binDir, tfDownloadURL)

func ensureVersion(log logging.SimpleLogging, dl Downloader, versions map[string]string, v *version.Version, binDir string, downloadURL string) (string, error) {

Describe the drawbacks of your solution

None

Describe alternatives you've considered

None

@nitrocode
Copy link
Member Author

cc: @fblgit I did some research on how the current tf download url can be plumbed through if you have time to take a look, we'd really appreciate this.

@adam-verigin
Copy link
Contributor

This is blocking us from updating since we run Atlantis in an environment where no internet-bound communication is allowed.

Using the latest release, when I run a plan, Atlantis dies, after logging:

<timestamp> [Error] : Getting url: Get "https://releases.hashicorp.com/terraform/": net/http: TLS handshake timeout

It doesn't log a line number/etc, so it took a while to track down where the error is coming from.

It also strikes me that this shouldn't kill Atlantis. Pulling this listing may intermitently fail (as all internet bound traffic does). It would make more sense to catch this and report it back to whatever VCS Atlantis is interacting with.

Finally, I'd like to request that, along with allowing someone to override the mirror URL, I would like to be able to disable the dynamic version fetching altogether.

@nitrocode
Copy link
Member Author

Agreed. Please feel free to propose a pr. This would be a good fix.

cc @fblgit

@adam-verigin
Copy link
Contributor

Was looking into this a little more.

I noticed --tf-download-url in the Arlantis docs. That shows up as TFDownloadURL in user_config.go, so if that property gets exposed in terraform_client.go, then it's a matter of passing that client to project_command_context_builder.go.

As for the error handling... that looks like a harder fix because terraform-switcher has embedded os.Exit(1) calls in its error handling. So, it might be easiest to replicate the version listing logic locally rather than depending on that library.

@nitrocode
Copy link
Member Author

If you implemented your mirror the same way as hashicorp, then the tf switcher function wouldn't error out, no?

Or do you have a use case that could be better proposed in the upstream library? I think we'd prefer not replicating logic here if the upstream library could do it.

Thanks for diving into this!

@nitrocode nitrocode changed the title Override the mirror URL to download terraform from airgapped environments v0.21+: Override the mirror URL to download terraform from airgapped environments Dec 19, 2022
@nitrocode nitrocode pinned this issue Dec 19, 2022
@nitrocode nitrocode changed the title v0.21+: Override the mirror URL to download terraform from airgapped environments v0.21+: Override mirror URL for terraform downloads Dec 19, 2022
@nitrocode nitrocode added bug Something isn't working regression Bug introduced in a new version and removed feature New functionality/enhancement labels Dec 19, 2022
@nitrocode nitrocode unpinned this issue Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Bug introduced in a new version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants