From 49d7c879accfc74926cb8e7992cf0522f5f844ea Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 1 Apr 2022 15:40:09 -0700 Subject: [PATCH] Fix problems caught by staticcheck v0.3.0 This will allow us to upgrade to this version in a later commit without causing the our build checks to fail. --- internal/cloud/e2e/helper_test.go | 2 +- internal/command/logout.go | 20 ++++++++------------ internal/lang/marks/marks.go | 12 +++++------- internal/terraform/evaluate.go | 3 ++- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/internal/cloud/e2e/helper_test.go b/internal/cloud/e2e/helper_test.go index d17604619f..084edf8f2d 100644 --- a/internal/cloud/e2e/helper_test.go +++ b/internal/cloud/e2e/helper_test.go @@ -251,6 +251,6 @@ findTfVersion: } if !hasVersion { - t.Skip(fmt.Sprintf("Skipping test because TFC/E does not have current Terraform version to test with (%s)", version)) + t.Skipf("Skipping test because TFC/E does not have current Terraform version to test with (%s)", version) } } diff --git a/internal/command/logout.go b/internal/command/logout.go index 8d3df7a319..904ccc5b06 100644 --- a/internal/command/logout.go +++ b/internal/command/logout.go @@ -78,18 +78,14 @@ func (c *LogoutCommand) Run(args []string) int { return 1 } - // credsCtx might not be set if we're using a mock credentials source - // in a test, but it should always be set in normal use. - if credsCtx != nil { - switch credsCtx.Location { - case cliconfig.CredentialsNotAvailable: - c.Ui.Output(fmt.Sprintf("No credentials for %s are stored.\n", dispHostname)) - return 0 - case cliconfig.CredentialsViaHelper: - c.Ui.Output(fmt.Sprintf("Removing the stored credentials for %s from the configured\n%q credentials helper.\n", dispHostname, credsCtx.HelperType)) - case cliconfig.CredentialsInPrimaryFile: - c.Ui.Output(fmt.Sprintf("Removing the stored credentials for %s from the following file:\n %s\n", dispHostname, credsCtx.LocalFilename)) - } + switch credsCtx.Location { + case cliconfig.CredentialsNotAvailable: + c.Ui.Output(fmt.Sprintf("No credentials for %s are stored.\n", dispHostname)) + return 0 + case cliconfig.CredentialsViaHelper: + c.Ui.Output(fmt.Sprintf("Removing the stored credentials for %s from the configured\n%q credentials helper.\n", dispHostname, credsCtx.HelperType)) + case cliconfig.CredentialsInPrimaryFile: + c.Ui.Output(fmt.Sprintf("Removing the stored credentials for %s from the following file:\n %s\n", dispHostname, credsCtx.LocalFilename)) } err = creds.ForgetForHost(hostname) diff --git a/internal/lang/marks/marks.go b/internal/lang/marks/marks.go index 0a174d9156..78bb527329 100644 --- a/internal/lang/marks/marks.go +++ b/internal/lang/marks/marks.go @@ -1,18 +1,16 @@ package marks import ( - "strings" - "github.com/zclconf/go-cty/cty" ) // valueMarks allow creating strictly typed values for use as cty.Value marks. -// The variable name for new values should be the title-cased format of the -// value to better match the GoString output for debugging. +// Each distinct mark value must be a constant in this package whose value +// is a valueMark whose underlying string matches the name of the variable. type valueMark string func (m valueMark) GoString() string { - return "marks." + strings.Title(string(m)) + return "marks." + string(m) } // Has returns true if and only if the cty.Value has the given mark. @@ -36,9 +34,9 @@ func Contains(val cty.Value, mark valueMark) bool { // Sensitive indicates that this value is marked as sensitive in the context of // Terraform. -var Sensitive = valueMark("sensitive") +const Sensitive = valueMark("Sensitive") // TypeType is used to indicate that the value contains a representation of // another value's type. This is part of the implementation of the console-only // `type` function. -var TypeType = valueMark("typeType") +const TypeType = valueMark("TypeType") diff --git a/internal/terraform/evaluate.go b/internal/terraform/evaluate.go index 243335df26..f8df6a2dc0 100644 --- a/internal/terraform/evaluate.go +++ b/internal/terraform/evaluate.go @@ -792,7 +792,8 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc instances[key] = val } - ret := cty.DynamicVal + // ret should be populated with a valid value in all cases below + var ret cty.Value switch { case config.Count != nil: