Skip to content

Commit 6d6f676

Browse files
committed
Adds logging
1 parent f02aeda commit 6d6f676

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

internal/service/ec2/vpc_.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
listschema "github.com/hashicorp/terraform-plugin-framework/list/schema"
2121
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2222
"github.com/hashicorp/terraform-plugin-framework/types"
23+
"github.com/hashicorp/terraform-plugin-log/tflog"
2324
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2425
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2526
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -31,12 +32,15 @@ import (
3132
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
3233
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
3334
"github.com/hashicorp/terraform-provider-aws/internal/provider/sdkv2/importer"
35+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
3436
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
3537
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3638
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
3739
inttypes "github.com/hashicorp/terraform-provider-aws/internal/types"
3840
"github.com/hashicorp/terraform-provider-aws/internal/verify"
3941
"github.com/hashicorp/terraform-provider-aws/names"
42+
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
43+
"go.opentelemetry.io/otel/attribute"
4044
)
4145

4246
const (
@@ -832,6 +836,13 @@ func (l *vpcListResource) List(ctx context.Context, request list.ListRequest, st
832836
awsClient := l.Meta()
833837
conn := awsClient.EC2Client(ctx)
834838

839+
attributes := []attribute.KeyValue{
840+
otelaws.RegionAttr(awsClient.Region(ctx)),
841+
}
842+
for _, attribute := range attributes {
843+
ctx = tflog.SetField(ctx, string(attribute.Key), attribute.Value.AsInterface())
844+
}
845+
835846
var query vpcListResourceModel
836847
if request.Config.Raw.IsKnown() && !request.Config.Raw.IsNull() {
837848
if diags := request.Config.Get(ctx, &query); diags.HasError() {
@@ -851,6 +862,8 @@ func (l *vpcListResource) List(ctx context.Context, request list.ListRequest, st
851862
Values: []string{"false"},
852863
})
853864

865+
tflog.Info(ctx, "Listing resources")
866+
854867
stream.Results = func(yield func(list.ListResult) bool) {
855868
pages := ec2.NewDescribeVpcsPaginator(conn, &input)
856869
for pages.HasMorePages() {
@@ -862,12 +875,16 @@ func (l *vpcListResource) List(ctx context.Context, request list.ListRequest, st
862875
}
863876

864877
for _, vpc := range page.Vpcs {
878+
ctx := tflog.SetField(ctx, "tf_aws.resource_attribute.id", aws.ToString(vpc.VpcId))
879+
865880
result := request.NewListResult(ctx)
866881

867882
tags := keyValueTags(ctx, vpc.Tags)
868883

869884
rd := l.ResourceData()
870885
rd.SetId(aws.ToString(vpc.VpcId))
886+
887+
tflog.Info(ctx, "Reading resource")
871888
err := resourceVPCFlatten(ctx, awsClient, &vpc, rd)
872889
if retry.NotFound(err) {
873890
tflog.Warn(ctx, "Resource disappeared during listing, skipping")

0 commit comments

Comments
 (0)