Upgrade to Go 1.17
This includes the addition of the new "//go:build" comment form in addition
to the legacy "// +build" notation, as produced by gofmt to ensure
consistent behavior between Go versions. The new directives are all
equivalent to what was present before, so there's no change in behavior.
Go 1.17 continues to use the Unicode 13 tables as in Go 1.16, so this
upgrade does not require also upgrading our Unicode-related dependencies.
This upgrade includes the following breaking changes which will also
appear as breaking changes for Terraform users, but that are consistent
with the Terraform v1.0 compatibility promises.
- On MacOS, Terraform now requires macOS 10.13 High Sierra or later.
This upgrade also includes the following breaking changes which will
appear as breaking changes for Terraform users that are inconsistent with
our compatibility promises, but have justified exceptions as follows:
- cidrsubnet, cidrhost, and cidrnetmask will now reject IPv4 CIDR
addresses whose decimal components have leading zeros, where previously
they would just silently ignore those leading zeros.
This is a security-motivated exception to our compatibility promises,
because some external systems interpret zero-prefixed octets as octal
numbers rather than decimal, and thus the previous lenient parsing could
lead to a different interpretation of the address between systems, and
thus potentially allow bypassing policy when configuring firewall rules
etc.
This upgrade also includes the following breaking changes which could
_potentially_ appear as breaking changes for Terraform users, but that do
not in practice for the reasons given:
- The Go net/url package no longer allows query strings with pairs
separated by semicolons instead of ampersands. This primarily affects
HTTP servers written in Go, and Terraform includes a special temporary
HTTP server as part of its implementation of OAuth for "terraform login",
but that server only needs to accept URLs created by Terraform itself
and Terraform does not generate any URLs that would be rejected.
2021-08-17 02:19:17 +02:00
|
|
|
//go:build !windows
|
2015-12-30 23:37:24 +01:00
|
|
|
// +build !windows
|
2014-08-14 18:45:58 +02:00
|
|
|
|
2019-07-31 01:54:48 +02:00
|
|
|
package cliconfig
|
2014-08-14 18:45:58 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
2018-03-21 14:55:56 +01:00
|
|
|
"os/user"
|
2014-08-14 18:45:58 +02:00
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func configFile() (string, error) {
|
2014-09-27 21:36:13 +02:00
|
|
|
dir, err := homeDir()
|
2014-08-14 18:45:58 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(dir, ".terraformrc"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func configDir() (string, error) {
|
2014-09-27 21:36:13 +02:00
|
|
|
dir, err := homeDir()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(dir, ".terraform.d"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func homeDir() (string, error) {
|
2014-08-14 18:45:58 +02:00
|
|
|
// First prefer the HOME environmental variable
|
|
|
|
if home := os.Getenv("HOME"); home != "" {
|
2017-06-12 21:04:40 +02:00
|
|
|
// FIXME: homeDir gets called from globalPluginDirs during init, before
|
2021-01-26 20:39:11 +01:00
|
|
|
// the logging is set up. We should move meta initializtion outside of
|
2017-06-12 21:04:40 +02:00
|
|
|
// init, but in the meantime we just need to silence this output.
|
|
|
|
//log.Printf("[DEBUG] Detected home directory from env var: %s", home)
|
|
|
|
|
2014-08-14 18:45:58 +02:00
|
|
|
return home, nil
|
|
|
|
}
|
|
|
|
|
2018-03-21 14:55:56 +01:00
|
|
|
// If that fails, try build-in module
|
|
|
|
user, err := user.Current()
|
|
|
|
if err != nil {
|
2014-08-14 18:45:58 +02:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2018-03-21 14:55:56 +01:00
|
|
|
if user.HomeDir == "" {
|
2014-08-14 18:45:58 +02:00
|
|
|
return "", errors.New("blank output")
|
|
|
|
}
|
|
|
|
|
2018-03-21 14:55:56 +01:00
|
|
|
return user.HomeDir, nil
|
2014-08-14 18:45:58 +02:00
|
|
|
}
|