Skip to content

Commit

Permalink
Add comments, fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Aug 29, 2020
1 parent 498b01b commit 0c0510a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions tfexec/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var defaultApplyOptions = applyConfig{
refresh: true,
}

// ApplyOption represents options used in the Apply method.
type ApplyOption interface {
configureApply(*applyConfig)
}
Expand Down
1 change: 1 addition & 0 deletions tfexec/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var defaultDestroyOptions = destroyConfig{
refresh: true,
}

// DestroyOption represents options used in the Destroy method.
type DestroyOption interface {
configureDestroy(*destroyConfig)
}
Expand Down
1 change: 1 addition & 0 deletions tfexec/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var defaultImportOptions = importConfig{
lockTimeout: "0s",
}

// ImportOption represents options used in the Import method.
type ImportOption interface {
configureImport(*importConfig)
}
Expand Down
1 change: 1 addition & 0 deletions tfexec/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var defaultInitOptions = initConfig{
verifyPlugins: true,
}

// InitOption represents options used in the Init method.
type InitOption interface {
configureInit(*initConfig)
}
Expand Down
25 changes: 24 additions & 1 deletion tfexec/options.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package tfexec

// AllowMissingConfigOption represents the -allow-missing-config flag.
type AllowMissingConfigOption struct {
allowMissingConfig bool
}

// AllowMissingConfig represents the -allow-missing-config flag.
func AllowMissingConfig(allowMissingConfig bool) *AllowMissingConfigOption {
return &AllowMissingConfigOption{allowMissingConfig}
}

// BackendOption represents the -backend flag.
type BackendOption struct {
backend bool
}

// Backend represents the -backend flag.
func Backend(backend bool) *BackendOption {
return &BackendOption{backend}
}

// BackendConfigOption represents the -backend-config flag.
type BackendConfigOption struct {
path string
}

// BackendConfig represents the -backend-config flag.
func BackendConfig(backendConfig string) *BackendConfigOption {
return &BackendConfigOption{backendConfig}
}

// BackupOption represents the -backup flag.
type BackupOption struct {
path string
}

// Backup represents the -backup flag.
func Backup(path string) *BackupOption {
return &BackupOption{path}
}
Expand All @@ -37,10 +45,12 @@ func DisableBackup() *BackupOption {
return &BackupOption{"-"}
}

// ConfigOption represents the -config flag.
type ConfigOption struct {
path string
}

// Config represents the -config flag.
func Config(path string) *ConfigOption {
return &ConfigOption{path}
}
Expand All @@ -61,11 +71,13 @@ func DirOrPlan(path string) *DirOrPlanOption {
return &DirOrPlanOption{path}
}

// named to prevent conflict with DestroyOption interface
type DestroyFlagOption struct {
// named to prevent conflict with DestroyOption interface

destroy bool
}

// Destroy represents the -destroy flag.
func Destroy(destroy bool) *DestroyFlagOption {
return &DestroyFlagOption{destroy}
}
Expand Down Expand Up @@ -102,19 +114,24 @@ func GetPlugins(getPlugins bool) *GetPluginsOption {
return &GetPluginsOption{getPlugins}
}

// LockOption represents the -lock flag.
type LockOption struct {
lock bool
}

// Lock represents the -lock flag.
func Lock(lock bool) *LockOption {
return &LockOption{lock}
}

// LockTimeoutOption represents the -lock-timeout flag.
type LockTimeoutOption struct {
timeout string
}

// LockTimeout represents the -lock-timeout flag.
func LockTimeout(lockTimeout string) *LockTimeoutOption {
// TODO: should this just use a duration instead?
return &LockTimeoutOption{lockTimeout}
}

Expand Down Expand Up @@ -162,6 +179,12 @@ type StateOption struct {
path string
}

// State represents the -state flag.
//
// Deprecated: The -state CLI flag is a legacy flag and should not be used.
// If you need a different state file for every run, you can instead use the
// local backend.
// See https://github.com/hashicorp/terraform/issues/25920#issuecomment-676560799
func State(path string) *StateOption {
return &StateOption{path}
}
Expand Down
6 changes: 1 addition & 5 deletions tfexec/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import (
)

var (
tf0_12_0 *version.Version
tf0_12_0 = version.Must(version.NewVersion("0.12.0"))
)

func init() {
tf0_12_0, _ = version.NewVersion("0.12.0")
}

// Version returns structured output from the terraform version command including both the Terraform CLI version
// and any initialized provider versions. This will read cached values when present unless the skipCache parameter
// is set to true.
Expand Down
21 changes: 9 additions & 12 deletions tfinstall/tfinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"golang.org/x/crypto/openpgp"
)

const baseUrl = "https://releases.hashicorp.com/terraform"
const baseURL = "https://releases.hashicorp.com/terraform"

type ExecPathFinder interface {
ExecPath() (string, error)
Expand Down Expand Up @@ -183,19 +183,17 @@ func downloadWithVerification(tfVersion string, installDir string) (string, erro
sumsFilename := "terraform_" + tfVersion + "_SHA256SUMS"
sumsSigFilename := sumsFilename + ".sig"

sumsUrl := fmt.Sprintf("%s/%s/%s",
baseUrl, tfVersion, sumsFilename)
sumsSigUrl := fmt.Sprintf("%s/%s/%s",
baseUrl, tfVersion, sumsSigFilename)
sumsURL := fmt.Sprintf("%s/%s/%s", baseURL, tfVersion, sumsFilename)
sumsSigURL := fmt.Sprintf("%s/%s/%s", baseURL, tfVersion, sumsSigFilename)

client.Src = sumsUrl
client.Src = sumsURL
client.Dst = sumsTmpDir
err = client.Get()
if err != nil {
return "", fmt.Errorf("error fetching checksums: %s", err)
}

client.Src = sumsSigUrl
client.Src = sumsSigURL
err = client.Get()
if err != nil {
return "", fmt.Errorf("error fetching checksums signature: %s", err)
Expand All @@ -210,7 +208,7 @@ func downloadWithVerification(tfVersion string, installDir string) (string, erro
}

// secondly, download Terraform itself, verifying the checksum
url := tfUrl(tfVersion, osName, archName)
url := tfURL(tfVersion, osName, archName)
client.Src = url
client.Dst = tfDir
client.Mode = getter.ClientModeDir
Expand All @@ -222,13 +220,12 @@ func downloadWithVerification(tfVersion string, installDir string) (string, erro
return filepath.Join(tfDir, "terraform"), nil
}

func tfUrl(tfVersion, osName, archName string) string {
func tfURL(tfVersion, osName, archName string) string {
sumsFilename := "terraform_" + tfVersion + "_SHA256SUMS"
sumsUrl := fmt.Sprintf("%s/%s/%s",
baseUrl, tfVersion, sumsFilename)
sumsURL := fmt.Sprintf("%s/%s/%s", baseURL, tfVersion, sumsFilename)
return fmt.Sprintf(
"%s/%s/terraform_%s_%s_%s.zip?checksum=file:%s",
baseUrl, tfVersion, tfVersion, osName, archName, sumsUrl,
baseURL, tfVersion, tfVersion, osName, archName, sumsURL,
)
}

Expand Down

0 comments on commit 0c0510a

Please sign in to comment.