-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34300 from hashicorp/b-rollback-ini-parsing-error
Rolls back AWS SDK modules with shared config parsing bug
- Loading branch information
Showing
6 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:bug | ||
provider: Fixes parsing error in AWS shared config files with extra whitespace | ||
``` | ||
|
||
```release-note:bug | ||
provider: Fixes poor performance when parsing AWS shared config files | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package sdkdiag | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
) | ||
|
||
// Comparer is a Comparer function for use with cmp.Diff to compare two diag.Diagnostic values | ||
func Comparer(l, r diag.Diagnostic) bool { | ||
if l.Severity != r.Severity { | ||
return false | ||
} | ||
if l.Summary != r.Summary { | ||
return false | ||
} | ||
if l.Detail != r.Detail { | ||
return false | ||
} | ||
|
||
lp := l.AttributePath | ||
rp := r.AttributePath | ||
if len(lp) != len(rp) { | ||
return false | ||
} | ||
return lp.Equals(rp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
terraformsdk "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/errs" | ||
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" | ||
) | ||
|
||
// TestSharedConfigFileParsing prevents regression in shared config file parsing | ||
// * https://github.com/aws/aws-sdk-go-v2/issues/2349: indented keys | ||
func TestSharedConfigFileParsing(t *testing.T) { //nolint:paralleltest | ||
testcases := map[string]struct { | ||
Config map[string]any | ||
SharedConfigurationFile string | ||
Check func(t *testing.T, meta *conns.AWSClient) | ||
}{ | ||
"leading whitespace": { | ||
// Do not "fix" indentation! | ||
SharedConfigurationFile: ` | ||
[default] | ||
region = us-west-2 | ||
`, //lintignore:AWSAT003 | ||
Check: func(t *testing.T, meta *conns.AWSClient) { | ||
//lintignore:AWSAT003 | ||
if a, e := meta.Region, "us-west-2"; a != e { | ||
t.Errorf("expected region %q, got %q", e, a) | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range testcases { //nolint:paralleltest | ||
tc := tc | ||
|
||
t.Run(name, func(t *testing.T) { | ||
ctx := context.TODO() | ||
|
||
oldenv := servicemocks.InitSessionTestEnv() | ||
defer servicemocks.PopEnv(oldenv) | ||
|
||
config := map[string]any{ | ||
"access_key": servicemocks.MockStaticAccessKey, | ||
"secret_key": servicemocks.MockStaticSecretKey, | ||
"skip_credentials_validation": true, | ||
"skip_requesting_account_id": true, | ||
} | ||
|
||
if tc.SharedConfigurationFile != "" { | ||
file, err := os.CreateTemp("", "aws-sdk-go-base-shared-configuration-file") | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error creating temporary shared configuration file: %s", err) | ||
} | ||
|
||
defer os.Remove(file.Name()) | ||
|
||
err = os.WriteFile(file.Name(), []byte(tc.SharedConfigurationFile), 0600) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error writing shared configuration file: %s", err) | ||
} | ||
|
||
config["shared_config_files"] = []any{file.Name()} | ||
} | ||
|
||
rc := terraformsdk.NewResourceConfigRaw(config) | ||
|
||
p, err := New(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var diags diag.Diagnostics | ||
diags = append(diags, p.Validate(rc)...) | ||
if diags.HasError() { | ||
t.Fatalf("validating: %s", sdkdiag.DiagnosticsString(diags)) | ||
} | ||
|
||
diags = append(diags, p.Configure(ctx, rc)...) | ||
|
||
// The provider always returns a warning if there is no account ID | ||
var expected diag.Diagnostics | ||
expected = append(expected, | ||
errs.NewWarningDiagnostic( | ||
"AWS account ID not found for provider", | ||
"See https://www.terraform.io/docs/providers/aws/index.html#skip_requesting_account_id for implications.", | ||
), | ||
) | ||
|
||
if diff := cmp.Diff(diags, expected, cmp.Comparer(sdkdiag.Comparer)); diff != "" { | ||
t.Errorf("unexpected diagnostics difference: %s", diff) | ||
} | ||
|
||
meta := p.Meta().(*conns.AWSClient) | ||
|
||
tc.Check(t, meta) | ||
}) | ||
} | ||
} |