Skip to content

Commit 5effec7

Browse files
committed
fixed linters and applied feedback of exa-infra
1 parent 453b286 commit 5effec7

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

internal/service/odb/network_peering_connection.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package odb
55
import (
66
"context"
77
"errors"
8+
"github.com/aws/aws-sdk-go-v2/aws"
9+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
810
"strings"
911
"time"
1012

@@ -111,6 +113,7 @@ func (r *resourceNetworkPeeringConnection) Schema(ctx context.Context, req resou
111113
names.AttrCreatedAt: schema.StringAttribute{
112114
Description: "Created time of the odb network peering connection.",
113115
Computed: true,
116+
CustomType: timetypes.RFC3339Type{},
114117
},
115118
"percent_progress": schema.Float32Attribute{
116119
Description: "Progress of the odb network peering connection.",
@@ -163,15 +166,34 @@ func (r *resourceNetworkPeeringConnection) Create(ctx context.Context, req resou
163166
}
164167
createTimeout := r.CreateTimeout(ctx, plan.Timeouts)
165168
createdPeeredConnection, err := waitNetworkPeeringConnectionCreated(ctx, conn, plan.OdbPeeringConnectionId.ValueString(), createTimeout)
169+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root(names.AttrID), aws.ToString(out.OdbPeeringConnectionId))...)
166170
if err != nil {
167171
resp.Diagnostics.AddError(
168172
create.ProblemStandardMessage(names.ODB, create.ErrActionWaitingForCreation, ResNameNetworkPeeringConnection, plan.DisplayName.ValueString(), err),
169173
err.Error(),
170174
)
171175
return
172176
}
173-
plan.CreatedAt = types.StringValue(createdPeeredConnection.CreatedAt.Format(time.RFC3339))
174-
resp.Diagnostics.Append(flex.Flatten(ctx, createdPeeredConnection, &plan, flex.WithIgnoredFieldNamesAppend("CreatedAt"))...)
177+
178+
odbNetworkARNParsed, err := arn.Parse(*createdPeeredConnection.OdbNetworkArn)
179+
if err != nil {
180+
resp.Diagnostics.AddError(
181+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, ResNameNetworkPeeringConnection, plan.DisplayName.ValueString(), err),
182+
err.Error(),
183+
)
184+
return
185+
}
186+
peerVpcARN, err := arn.Parse(*createdPeeredConnection.PeerNetworkArn)
187+
if err != nil {
188+
resp.Diagnostics.AddError(
189+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, ResNameNetworkPeeringConnection, plan.DisplayName.ValueString(), err),
190+
err.Error(),
191+
)
192+
return
193+
}
194+
plan.PeerNetworkId = types.StringValue(strings.Split(peerVpcARN.Resource, "/")[1])
195+
plan.OdbNetworkId = types.StringValue(strings.Split(odbNetworkARNParsed.Resource, "/")[1])
196+
resp.Diagnostics.Append(flex.Flatten(ctx, createdPeeredConnection, &plan)...)
175197
if resp.Diagnostics.HasError() {
176198
return
177199
}
@@ -218,11 +240,9 @@ func (r *resourceNetworkPeeringConnection) Read(ctx context.Context, req resourc
218240
return
219241
}
220242
state.PeerNetworkId = types.StringValue(strings.Split(peerVpcARN.Resource, "/")[1])
221-
state.CreatedAt = types.StringValue(out.CreatedAt.Format(time.RFC3339))
222243
state.OdbNetworkId = types.StringValue(strings.Split(odbNetworkARNParsed.Resource, "/")[1])
223244

224-
resp.Diagnostics.Append(flex.Flatten(ctx, out, &state, flex.WithIgnoredFieldNamesAppend("CreatedAt"),
225-
flex.WithIgnoredFieldNamesAppend("PeerNetworkId"), flex.WithIgnoredFieldNamesAppend("OdbNetworkId"))...)
245+
resp.Diagnostics.Append(flex.Flatten(ctx, out, &state)...)
226246
if resp.Diagnostics.HasError() {
227247
return
228248
}
@@ -263,10 +283,8 @@ func (r *resourceNetworkPeeringConnection) Update(ctx context.Context, req resou
263283
return
264284
}
265285
state.PeerNetworkId = types.StringValue(strings.Split(peerVpcARN.Resource, "/")[1])
266-
state.CreatedAt = types.StringValue(updatedOdbNetPeeringConn.CreatedAt.Format(time.RFC3339))
267286
state.OdbNetworkId = types.StringValue(strings.Split(odbNetworkARNParsed.Resource, "/")[1])
268-
resp.Diagnostics.Append(flex.Flatten(ctx, updatedOdbNetPeeringConn, &plan, flex.WithIgnoredFieldNamesAppend("CreatedAt"), flex.WithIgnoredFieldNamesAppend("CreatedAt"),
269-
flex.WithIgnoredFieldNamesAppend("PeerNetworkId"), flex.WithIgnoredFieldNamesAppend("OdbNetworkId"))...)
287+
resp.Diagnostics.Append(flex.Flatten(ctx, updatedOdbNetPeeringConn, &plan)...)
270288
if resp.Diagnostics.HasError() {
271289
return
272290
}
@@ -401,8 +419,8 @@ func findNetworkPeeringConnectionByID(ctx context.Context, conn *odb.Client, id
401419

402420
type odbNetworkPeeringConnectionResourceModel struct {
403421
framework.WithRegionModel
404-
OdbNetworkId types.String `tfsdk:"odb_network_id"`
405-
PeerNetworkId types.String `tfsdk:"peer_network_id"`
422+
OdbNetworkId types.String `tfsdk:"odb_network_id" autoflex:",noflatten"`
423+
PeerNetworkId types.String `tfsdk:"peer_network_id" autoflex:",noflatten"`
406424
OdbPeeringConnectionId types.String `tfsdk:"id"`
407425
DisplayName types.String `tfsdk:"display_name"`
408426
Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"`
@@ -411,7 +429,7 @@ type odbNetworkPeeringConnectionResourceModel struct {
411429
OdbNetworkArn types.String `tfsdk:"odb_network_arn"`
412430
PeerNetworkArn types.String `tfsdk:"peer_network_arn"`
413431
OdbPeeringConnectionType types.String `tfsdk:"odb_peering_connection_type"`
414-
CreatedAt types.String `tfsdk:"created_at"`
432+
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
415433
PercentProgress types.Float32 `tfsdk:"percent_progress"`
416434
Timeouts timeouts.Value `tfsdk:"timeouts"`
417435
Tags tftags.Map `tfsdk:"tags"`

internal/service/odb/network_peering_connection_data_source.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ package odb
44

55
import (
66
"context"
7-
"time"
8-
97
"github.com/aws/aws-sdk-go-v2/service/odb"
108
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
9+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1110
"github.com/hashicorp/terraform-plugin-framework/datasource"
1211
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1312
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -72,6 +71,7 @@ func (d *dataSourceNetworkPeeringConnection) Schema(ctx context.Context, req dat
7271
names.AttrCreatedAt: schema.StringAttribute{
7372
Description: "Created time of the odb network peering connection.",
7473
Computed: true,
74+
CustomType: timetypes.RFC3339Type{},
7575
},
7676
"percent_progress": schema.Float32Attribute{
7777
Description: "Progress of the odb network peering connection.",
@@ -112,10 +112,7 @@ func (d *dataSourceNetworkPeeringConnection) Read(ctx context.Context, req datas
112112
if tagsRead != nil {
113113
data.Tags = tftags.FlattenStringValueMap(ctx, tagsRead.Map())
114114
}
115-
if out.OdbPeeringConnection.CreatedAt != nil {
116-
data.CreatedAt = types.StringValue(out.OdbPeeringConnection.CreatedAt.Format(time.RFC3339))
117-
}
118-
resp.Diagnostics.Append(flex.Flatten(ctx, out.OdbPeeringConnection, &data, flex.WithIgnoredFieldNamesAppend("CreatedAt"))...)
115+
resp.Diagnostics.Append(flex.Flatten(ctx, out.OdbPeeringConnection, &data)...)
119116
if resp.Diagnostics.HasError() {
120117
return
121118
}
@@ -132,7 +129,7 @@ type odbNetworkPeeringConnectionDataSourceModel struct {
132129
OdbNetworkArn types.String `tfsdk:"odb_network_arn"`
133130
PeerNetworkArn types.String `tfsdk:"peer_network_arn"`
134131
OdbPeeringConnectionType types.String `tfsdk:"odb_peering_connection_type"`
135-
CreatedAt types.String `tfsdk:"created_at"`
132+
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
136133
PercentProgress types.Float32 `tfsdk:"percent_progress"`
137134
Tags tftags.Map `tfsdk:"tags"`
138135
}

0 commit comments

Comments
 (0)