diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c00263d5b9..642fb79b7c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,6 +15,10 @@ updates: ignore: # terraform-plugin-go should only be updated via terraform-plugin-framework - dependency-name: "github.com/hashicorp/terraform-plugin-go" + # terraform-plugin-log should only be updated via terraform-plugin-framework + - dependency-name: "github.com/hashicorp/terraform-plugin-log" + # go-hclog should only be updated via terraform-plugin-log + - dependency-name: "github.com/hashicorp/go-hclog" schedule: # Check for updates to Go modules every weekday interval: "daily" diff --git a/go.mod b/go.mod index 876ac0f34b..1fabe9ad3f 100644 --- a/go.mod +++ b/go.mod @@ -12,10 +12,12 @@ require ( github.com/google/go-cmp v0.5.7 github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.15.0 github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.3 + github.com/hashicorp/go-hclog v1.0.0 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/hcl/v2 v2.11.1 github.com/hashicorp/terraform-plugin-framework v0.5.1-0.20220105213120-5f18d804a22b github.com/hashicorp/terraform-plugin-go v0.5.0 + github.com/hashicorp/terraform-plugin-log v0.2.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 github.com/jinzhu/inflection v1.0.0 github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24 diff --git a/internal/acctest/testchecks.go b/internal/acctest/testchecks.go index 75c8e4aa15..46fe126e54 100644 --- a/internal/acctest/testchecks.go +++ b/internal/acctest/testchecks.go @@ -6,6 +6,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/hashicorp/terraform-plugin-log/tfsdklog" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol" @@ -60,7 +62,7 @@ func (td TestData) DeleteResource() resource.TestCheckFunc { return fmt.Errorf("unable to convert %T to CloudControlApiProvider", td.provider) } - ctx := context.TODO() + ctx := getTestContext() return tfcloudcontrol.DeleteResource(ctx, provider.CloudControlApiClient(ctx), provider.RoleARN(ctx), td.CloudFormationResourceType, id, deleteResourceTimeout) } @@ -73,7 +75,7 @@ func (td TestData) checkExists(shouldExist bool) resource.TestCheckFunc { return fmt.Errorf("unable to convert %T to CloudControlApiProvider", td.provider) } - ctx := context.TODO() + ctx := getTestContext() return existsFunc(shouldExist)( ctx, @@ -124,3 +126,7 @@ func existsFunc(shouldExist bool) func(context.Context, *cloudcontrol.Client, st } } } + +func getTestContext() context.Context { + return tfsdklog.NewRootProviderLogger(context.TODO(), tflog.WithLevelFromEnv("TF_LOG"), tflog.WithoutLocation()) +} diff --git a/internal/generic/logging.go b/internal/generic/logging.go new file mode 100644 index 0000000000..da81e95ee7 --- /dev/null +++ b/internal/generic/logging.go @@ -0,0 +1,20 @@ +package generic + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +const ( + LoggingKeyCFNType = "cfn_type" +) + +func traceEntry(ctx context.Context, n string) { + tflog.Trace(ctx, fmt.Sprintf("%s entry", n)) +} + +func traceExit(ctx context.Context, n string) { + tflog.Trace(ctx, fmt.Sprintf("%s exit", n)) +} diff --git a/internal/generic/plural_data_source.go b/internal/generic/plural_data_source.go index 2fa6180ac5..7221027a4d 100644 --- a/internal/generic/plural_data_source.go +++ b/internal/generic/plural_data_source.go @@ -3,14 +3,15 @@ package generic import ( "context" "fmt" - "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" cctypes "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-log/tflog" tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol" ) @@ -65,10 +66,9 @@ func newGenericPluralDataSource(provider tfsdk.Provider, pluralDataSourceType *p } func (pd *pluralDataSource) Read(ctx context.Context, _ tfsdk.ReadDataSourceRequest, response *tfsdk.ReadDataSourceResponse) { - cfTypeName := pd.dataSourceType.cfTypeName - tfTypeName := pd.dataSourceType.tfTypeName + ctx = pd.cfnTypeContext(ctx) - log.Printf("[TRACE] DataSource.Read enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "PluralDataSource.Read") conn := pd.provider.CloudControlApiClient(ctx) @@ -87,9 +87,9 @@ func (pd *pluralDataSource) Read(ctx context.Context, _ tfsdk.ReadDataSourceRequ Raw: val, } - log.Printf("[DEBUG] Response.State.Raw. value: %v", response.State.Raw) + tflog.Debug(ctx, "Response.State.Raw", "value", hclog.Fmt("%v", response.State.Raw)) - log.Printf("[TRACE] DataSource.Read exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "PluralDataSource.Read") } // list returns the ResourceDescriptions of the specified CloudFormation type. @@ -97,6 +97,13 @@ func (pd *pluralDataSource) list(ctx context.Context, conn *cloudcontrol.Client) return tfcloudcontrol.ListResourcesByTypeName(ctx, conn, pd.provider.RoleARN(ctx), pd.dataSourceType.cfTypeName) } +// cfnTypeContext injects the CloudFormation type name into logger contexts. +func (pd *pluralDataSource) cfnTypeContext(ctx context.Context) context.Context { + ctx = tflog.With(ctx, LoggingKeyCFNType, pd.dataSourceType.cfTypeName) + + return ctx +} + // GetCloudControlResourceDescriptionsValue returns the Terraform Value for the specified Cloud Control API ResourceDescriptions. func GetCloudControlResourceDescriptionsValue(id string, descriptions []cctypes.ResourceDescription) tftypes.Value { m := map[string]tftypes.Value{ diff --git a/internal/generic/resource.go b/internal/generic/resource.go index 7c5bd9fb19..2ef4d2c8a1 100644 --- a/internal/generic/resource.go +++ b/internal/generic/resource.go @@ -4,16 +4,17 @@ import ( "context" "encoding/json" "fmt" - "log" "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" cctypes "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" + hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-log/tflog" tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol" "github.com/hashicorp/terraform-provider-awscc/internal/tfresource" "github.com/hashicorp/terraform-provider-awscc/internal/validate" @@ -394,14 +395,13 @@ var ( ) func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceRequest, response *tfsdk.CreateResourceResponse) { - cfTypeName := r.resourceType.cfTypeName - tfTypeName := r.resourceType.tfTypeName + ctx = r.cfnTypeContext(ctx) - log.Printf("[TRACE] Resource.Create enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "Resource.Create") conn := r.provider.CloudControlApiClient(ctx) - log.Printf("[DEBUG] Request.Plan.Raw. value: %v", request.Plan.Raw) + tflog.Debug(ctx, "Request.Plan.Raw", "value", hclog.Fmt("%v", request.Plan.Raw)) translator := toCloudControl{tfToCfNameMap: r.resourceType.tfToCfNameMap} desiredState, err := translator.AsString(ctx, request.Plan.Raw) @@ -412,12 +412,12 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque return } - log.Printf("[DEBUG] CloudControl DesiredState. value: %s", desiredState) + tflog.Debug(ctx, "CloudControl DesiredState", "value", desiredState) input := &cloudcontrol.CreateResourceInput{ ClientToken: aws.String(tfresource.UniqueId()), DesiredState: aws.String(desiredState), - TypeName: aws.String(cfTypeName), + TypeName: aws.String(r.resourceType.cfTypeName), } if roleARN := r.provider.RoleARN(ctx); roleARN != "" { @@ -484,18 +484,17 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque return } - log.Printf("[DEBUG] Response.State.Raw. value: %v", response.State.Raw) + tflog.Debug(ctx, "Response.State.Raw", "value", hclog.Fmt("%v", response.State.Raw)) - log.Printf("[TRACE] Resource.Create exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "Resource.Create") } func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest, response *tfsdk.ReadResourceResponse) { - cfTypeName := r.resourceType.cfTypeName - tfTypeName := r.resourceType.tfTypeName + ctx = r.cfnTypeContext(ctx) - log.Printf("[TRACE] Resource.Read enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "Resource.Read") - log.Printf("[DEBUG] Request.State.Raw. value: %v", request.State.Raw) + tflog.Debug(ctx, "Request.State.Raw", "value", hclog.Fmt("%v", request.State.Raw)) conn := r.provider.CloudControlApiClient(ctx) @@ -567,16 +566,15 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest, } } - log.Printf("[DEBUG] Response.State.Raw. value: %v", response.State.Raw) + tflog.Debug(ctx, "Response.State.Raw", "value", hclog.Fmt("%v", response.State.Raw)) - log.Printf("[TRACE] Resource.Read exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "Resource.Read") } func (r *resource) Update(ctx context.Context, request tfsdk.UpdateResourceRequest, response *tfsdk.UpdateResourceResponse) { - cfTypeName := r.resourceType.cfTypeName - tfTypeName := r.resourceType.tfTypeName + ctx = r.cfnTypeContext(ctx) - log.Printf("[TRACE] Resource.Update enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "Resource.Update") conn := r.provider.CloudControlApiClient(ctx) @@ -617,13 +615,13 @@ func (r *resource) Update(ctx context.Context, request tfsdk.UpdateResourceReque return } - log.Printf("[DEBUG] Cloud Control API PatchDocument: %s", patchDocument) + tflog.Debug(ctx, "Cloud Control API PatchDocument", "value", patchDocument) input := &cloudcontrol.UpdateResourceInput{ ClientToken: aws.String(tfresource.UniqueId()), Identifier: aws.String(id), PatchDocument: aws.String(patchDocument), - TypeName: aws.String(cfTypeName), + TypeName: aws.String(r.resourceType.cfTypeName), } if roleARN := r.provider.RoleARN(ctx); roleARN != "" { @@ -667,14 +665,13 @@ func (r *resource) Update(ctx context.Context, request tfsdk.UpdateResourceReque return } - log.Printf("[TRACE] Resource.Update exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "Resource.Update") } func (r *resource) Delete(ctx context.Context, request tfsdk.DeleteResourceRequest, response *tfsdk.DeleteResourceResponse) { - cfTypeName := r.resourceType.cfTypeName - tfTypeName := r.resourceType.tfTypeName + ctx = r.cfnTypeContext(ctx) - log.Printf("[TRACE] Resource.Delete enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "Resource.Delete") conn := r.provider.CloudControlApiClient(ctx) @@ -686,7 +683,7 @@ func (r *resource) Delete(ctx context.Context, request tfsdk.DeleteResourceReque return } - err = tfcloudcontrol.DeleteResource(ctx, conn, r.provider.RoleARN(ctx), cfTypeName, id, r.resourceType.deleteTimeout) + err = tfcloudcontrol.DeleteResource(ctx, conn, r.provider.RoleARN(ctx), r.resourceType.cfTypeName, id, r.resourceType.deleteTimeout) if err != nil { response.Diagnostics = append(response.Diagnostics, ServiceOperationErrorDiag("Cloud Control API", "DeleteResource", err)) @@ -696,20 +693,19 @@ func (r *resource) Delete(ctx context.Context, request tfsdk.DeleteResourceReque response.State.RemoveResource(ctx) - log.Printf("[TRACE] Resource.Delete exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "Resource.Delete") } func (r *resource) ImportState(ctx context.Context, request tfsdk.ImportResourceStateRequest, response *tfsdk.ImportResourceStateResponse) { - cfTypeName := r.resourceType.cfTypeName - tfTypeName := r.resourceType.tfTypeName + ctx = r.cfnTypeContext(ctx) - log.Printf("[TRACE] Resource.ImportState enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "Resource.ImportState") - log.Printf("[DEBUG] Request.ID: %s", request.ID) + tflog.Debug(ctx, "Request.ID", "value", hclog.Fmt("%v", request.ID)) tfsdk.ResourceImportStatePassthroughID(ctx, idAttributePath, request, response) - log.Printf("[TRACE] Resource.ImportState exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "Resource.ImportState") } // ConfigValidators returns a list of functions which will all be performed during validation. @@ -804,6 +800,13 @@ func (r *resource) populateUnknownValues(ctx context.Context, id string, state * return nil } +// cfnTypeContext injects the CloudFormation type name into logger contexts. +func (r *resource) cfnTypeContext(ctx context.Context) context.Context { + ctx = tflog.With(ctx, LoggingKeyCFNType, r.resourceType.tfTypeName) + + return ctx +} + // patchDocument returns a JSON Patch document describing the difference between `old` and `new`. func patchDocument(old, new string) (string, error) { patch, err := jsonpatch.CreatePatch([]byte(old), []byte(new)) diff --git a/internal/generic/singular_data_source.go b/internal/generic/singular_data_source.go index eca83057f6..c46986e414 100644 --- a/internal/generic/singular_data_source.go +++ b/internal/generic/singular_data_source.go @@ -3,13 +3,14 @@ package generic import ( "context" "fmt" - "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" cctypes "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-log/tflog" tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol" "github.com/hashicorp/terraform-provider-awscc/internal/tfresource" ) @@ -65,10 +66,9 @@ func newGenericSingularDataSource(provider tfsdk.Provider, singularDataSourceTyp } func (sd *singularDataSource) Read(ctx context.Context, request tfsdk.ReadDataSourceRequest, response *tfsdk.ReadDataSourceResponse) { - cfTypeName := sd.dataSourceType.cfTypeName - tfTypeName := sd.dataSourceType.tfTypeName + ctx = sd.cfnTypeContext(ctx) - log.Printf("[TRACE] DataSource.Read enter. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceEntry(ctx, "SingularDataSource.Read") conn := sd.provider.CloudControlApiClient(ctx) @@ -122,9 +122,9 @@ func (sd *singularDataSource) Read(ctx context.Context, request tfsdk.ReadDataSo return } - log.Printf("[DEBUG] Response.State.Raw. value: %v", response.State.Raw) + tflog.Debug(ctx, "Response.State.Raw", "value", hclog.Fmt("%v", response.State.Raw)) - log.Printf("[TRACE] DataSource.Read exit. cfTypeName: %s, tfTypeName: %s", cfTypeName, tfTypeName) + traceExit(ctx, "SingularDataSource.Read") } // describe returns the live state of the specified resource. @@ -154,3 +154,10 @@ func (sd *singularDataSource) setId(ctx context.Context, val string, state *tfsd return nil } + +// cfnTypeContext injects the CloudFormation type name into logger contexts. +func (sd *singularDataSource) cfnTypeContext(ctx context.Context) context.Context { + ctx = tflog.With(ctx, LoggingKeyCFNType, sd.dataSourceType.cfTypeName) + + return ctx +} diff --git a/internal/generic/translate.go b/internal/generic/translate.go index 4ec78fad94..9696b9a9d1 100644 --- a/internal/generic/translate.go +++ b/internal/generic/translate.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" "fmt" - "log" "math/big" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-log/tflog" ) // Translates a Terraform Value to Cloud Control DesiredState. @@ -235,7 +235,7 @@ func (t toTerraform) valueFromRaw(ctx context.Context, schema *tfsdk.Schema, pat if isObject { attributeName, ok := t.cfToTfNameMap[key] if !ok { - log.Printf("[INFO] attribute name mapping not found. key: %s", key) + tflog.Info(ctx, "attribute name mapping not found", "key", key) continue } path = path.WithAttributeName(attributeName) @@ -245,7 +245,7 @@ func (t toTerraform) valueFromRaw(ctx context.Context, schema *tfsdk.Schema, pat val, err := t.valueFromRaw(ctx, schema, path, v) if err != nil { if isObject { - log.Printf("[INFO] not found in Terraform schema. key: %s, path: %s, error: %s", key, path, err.Error()) + tflog.Info(ctx, "not found in Terraform schema", "key", key, "path", path, "error", err.Error()) path = path.WithoutLastStep() continue } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index c64f22507e..b0c492e544 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -3,7 +3,6 @@ package provider import ( "context" "fmt" - "log" "os" "strings" "time" @@ -11,9 +10,11 @@ import ( "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" "github.com/aws/smithy-go/logging" awsbase "github.com/hashicorp/aws-sdk-go-base/v2" + hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-awscc/internal/registry" cctypes "github.com/hashicorp/terraform-provider-awscc/internal/types" "github.com/hashicorp/terraform-provider-awscc/internal/validate" @@ -425,27 +426,31 @@ func newCloudControlClient(ctx context.Context, pd *providerData) (*cloudcontrol } type awsSdkLogger struct{} +type awsSdkContextLogger struct { + ctx context.Context +} func (l awsSdkLogger) Logf(classification logging.Classification, format string, v ...interface{}) { - log.Printf("[%s] [aws-sdk-go-v2] %s", classification, fmt.Sprintf(format, v...)) + switch classification { + case logging.Warn: + hclog.Default().Warn("[aws-sdk-go-v2] %s", fmt.Sprintf(format, v...)) + default: + hclog.Default().Debug("[aws-sdk-go-v2] %s", fmt.Sprintf(format, v...)) + } +} + +func (l awsSdkLogger) WithContext(ctx context.Context) logging.Logger { + return awsSdkContextLogger{ctx: ctx} } -// func (l awsSdkLogger) WithContext(ctx context.Context) logging.Logger { -// return awsSdkContextLogger{ctx: ctx} -// } - -// type awsSdkContextLogger struct { -// ctx context.Context -// } - -// func (l awsSdkContextLogger) Logf(classification logging.Classification, format string, v ...interface{}) { -// switch classification { -// case logging.Warn: -// tflog.Warn(l.ctx, "[aws-sdk-go-v2]", "message", hclog.Fmt(format, v...)) -// default: -// tflog.Debug(l.ctx, "[aws-sdk-go-v2]", "message", hclog.Fmt(format, v...)) -// } -// } +func (l awsSdkContextLogger) Logf(classification logging.Classification, format string, v ...interface{}) { + switch classification { + case logging.Warn: + tflog.Warn(l.ctx, "[aws-sdk-go-v2]", "message", hclog.Fmt(format, v...)) + default: + tflog.Debug(l.ctx, "[aws-sdk-go-v2]", "message", hclog.Fmt(format, v...)) + } +} func userAgentProducts(products []userAgentProduct) []awsbase.UserAgentProduct { results := make([]awsbase.UserAgentProduct, len(products)) diff --git a/internal/service/cloudcontrol/delete.go b/internal/service/cloudcontrol/delete.go index ad9379cb68..99580cdb6d 100644 --- a/internal/service/cloudcontrol/delete.go +++ b/internal/service/cloudcontrol/delete.go @@ -3,16 +3,16 @@ package cloudcontrol import ( "context" "fmt" - "log" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-awscc/internal/tfresource" ) func DeleteResource(ctx context.Context, conn *cloudcontrol.Client, roleARN, typeName, id string, maxWaitTime time.Duration) error { - log.Printf("[DEBUG] DeleteResource. cfTypeName: %s, id: %s", typeName, id) + tflog.Debug(ctx, "DeleteResource", "cfTypeName", typeName, "id", id) input := &cloudcontrol.DeleteResourceInput{ ClientToken: aws.String(tfresource.UniqueId()), diff --git a/internal/service/cloudcontrol/find.go b/internal/service/cloudcontrol/find.go index 5637b13b4f..31b0dc6792 100644 --- a/internal/service/cloudcontrol/find.go +++ b/internal/service/cloudcontrol/find.go @@ -3,17 +3,17 @@ package cloudcontrol import ( "context" "errors" - "log" "strings" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-awscc/internal/tfresource" ) func FindResourceByTypeNameAndID(ctx context.Context, conn *cloudcontrol.Client, roleARN, typeName, id string) (*types.ResourceDescription, error) { - log.Printf("[DEBUG] FindResourceByTypeNameAndID. cfTypeName: %s, id: %s", typeName, id) + tflog.Debug(ctx, "FindResourceByTypeNameAndID", "cfTypeName", typeName, "id", id) input := &cloudcontrol.GetResourceInput{ Identifier: aws.String(id), @@ -43,7 +43,7 @@ func FindResourceByTypeNameAndID(ctx context.Context, conn *cloudcontrol.Client, return nil, &tfresource.NotFoundError{Message: "Empty result"} } - log.Printf("[DEBUG] ResourceDescription.ResourceModel. value: %s", aws.ToString(output.ResourceDescription.Properties)) + tflog.Debug(ctx, "ResourceDescription.ResourceModel", "value", aws.ToString(output.ResourceDescription.Properties)) return output.ResourceDescription, nil } diff --git a/internal/service/cloudcontrol/list.go b/internal/service/cloudcontrol/list.go index cfab0e2802..0e17ef90f0 100644 --- a/internal/service/cloudcontrol/list.go +++ b/internal/service/cloudcontrol/list.go @@ -2,16 +2,16 @@ package cloudcontrol import ( "context" - "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-awscc/internal/tfresource" ) func ListResourcesByTypeName(ctx context.Context, conn *cloudcontrol.Client, roleARN, typeName string) ([]types.ResourceDescription, error) { - log.Printf("[DEBUG] ListResourcesByTypeName. cfTypeName: %s", typeName) + tflog.Debug(ctx, "ListResourcesByTypeName", "cfTypeName", typeName) input := &cloudcontrol.ListResourcesInput{ TypeName: aws.String(typeName),