diff --git a/internal/backend/remote-state/s3/backend.go b/internal/backend/remote-state/s3/backend.go index 7d649b2bb0..997045fd0c 100644 --- a/internal/backend/remote-state/s3/backend.go +++ b/internal/backend/remote-state/s3/backend.go @@ -11,6 +11,7 @@ import ( "regexp" "sort" "strings" + "sync" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -18,8 +19,11 @@ import ( "github.com/aws/aws-sdk-go-v2/service/dynamodb" "github.com/aws/aws-sdk-go-v2/service/s3" awsbase "github.com/hashicorp/aws-sdk-go-base/v2" + baselogging "github.com/hashicorp/aws-sdk-go-base/v2/logging" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform/internal/backend" "github.com/hashicorp/terraform/internal/configs/configschema" + "github.com/hashicorp/terraform/internal/logging" "github.com/hashicorp/terraform/internal/tfdiags" "github.com/hashicorp/terraform/version" "github.com/zclconf/go-cty/cty" @@ -694,11 +698,16 @@ func (b *Backend) Configure(obj cty.Value) tfdiags.Diagnostics { } } + log := logger() + + ctx, baselog := baselogging.NewHcLogger(ctx, log) + cfg := &awsbase.Config{ AccessKey: stringAttr(obj, "access_key"), APNInfo: stdUserAgentProducts(), CallerDocumentationURL: "https://www.terraform.io/docs/language/settings/backends/s3.html", CallerName: "S3 Backend", + Logger: baselog, MaxRetries: intAttrDefault(obj, "max_retries", 5), Profile: stringAttr(obj, "profile"), Region: stringAttr(obj, "region"), @@ -1634,3 +1643,8 @@ func deprecatedEnvVarDiag(envvar, replacement string) tfdiags.Diagnostic { fmt.Sprintf(`The environment variable "%s" is deprecated. Use environment variable "%s" instead.`, envvar, replacement), ) } + +var logger = sync.OnceValue(func() hclog.Logger { + l := logging.HCLogger() + return l.Named("backend-s3") +})