Skip to content

Conversation

SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Aug 27, 2025

This PR is stacked on #37508

Once this PR is merged all the S3 tests will be passing.

After diagnostic comparison became more stringent s3 tests were failing because some diagnostics had Source data associated with them, while the expected diagnostics in the test cases did not include that information. The Source data that causes the issue appears to be added here in a backend testing helper:

diags = diags.Append(valDiags.InConfigBody(c, ""))

To address this, I've updated relevant test cases to similarly add config contect to diagnostics in some test cases.

Target Release

N/A

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@SarahFrench SarahFrench added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Aug 27, 2025
@SarahFrench
Copy link
Member Author

When I run the s3 tests locally they all pass 🎉

go test github.com/hashicorp/terraform/internal/backend/remote-state/s3                   
ok      github.com/hashicorp/terraform/internal/backend/remote-state/s3 13.361s

jar-b
jar-b previously approved these changes Aug 27, 2025
Copy link
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Thanks for fixing these!

% TF_ACC=1 go test -count=1 ./...
ok      github.com/hashicorp/terraform/internal/backend/remote-state/s3 213.818s

Base automatically changed from SarahFrench-patch-1 to main August 27, 2025 19:19
@SarahFrench SarahFrench dismissed jar-b’s stale review August 27, 2025 19:19

The base branch was changed.

@SarahFrench
Copy link
Member Author

SarahFrench commented Aug 28, 2025

I got some feedback about making diagnosticBase implement ComparableDiagnostic: diagnostic comparisons are used in Terraform to held deduplicate diagnostics that are shown to users. The diagnosticBase type has no source information so it's possible that two different diagnostics arising from different places could mistakenly be identified as equal, and therefore one will be removed from the deduplicated output shown to users.

Because of the potential risk affecting users seeing diagnostics, I've removed the Equal method from diagnosticBase implement, and I've restored the s3 tests to using their own package-specific comparer.

The only reason we needed to make diagnosticBase implement ComparableDiagnostic is because Sourceless diagnostics are returned from here:

_ /* ctx */, awsConfig, cfgDiags := awsbase.GetAwsConfig(ctx, cfg)
for _, d := range cfgDiags {
diags = diags.Append(tfdiags.Sourceless(
baseSeverityToTerraformSeverity(d.Severity()),
d.Summary(),
d.Detail(),
))
}

If the hashicorp/aws-sdk-go-base/v2 dependency was updated so that the diagnostic could be linked to places in the configuration then the diagnostics could stop being Sourceless and then would be compatible with the shared comparer logic. However that's a big ask, so updating this PR to return the s3-specific comparer to this package is the easiest solution.

@SarahFrench
Copy link
Member Author

I ran the s3 tests locally and they're passing:

% go test github.com/hashicorp/terraform/internal/backend/remote-state/s3
ok      github.com/hashicorp/terraform/internal/backend/remote-state/s3 13.551s

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lightly changed version of the original file removed in #36385

@SarahFrench SarahFrench enabled auto-merge (squash) August 28, 2025 11:40
@SarahFrench SarahFrench merged commit 1c09e58 into main Aug 28, 2025
7 checks passed
@SarahFrench SarahFrench deleted the sarah/fix-diag-comparison-s3-tests branch August 28, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend/s3 no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants