1- //Copyright © 2025, Oracle and/or its affiliates. All rights reserved.
1+ //Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
22
33package odb
44
55import (
66 "context"
77 "errors"
8- "github.com/hashicorp/terraform-provider-aws/internal/enum"
9- tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
108 "strings"
119 "time"
1210
13- "github.com/aws/aws-sdk-go-v2/aws"
11+ "github.com/aws/aws-sdk-go-v2/aws/arn "
1412 "github.com/aws/aws-sdk-go-v2/service/odb"
1513 odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
1614 "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
17-
1815 "github.com/hashicorp/terraform-plugin-framework/path"
1916 "github.com/hashicorp/terraform-plugin-framework/resource"
2017 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
2118 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2219 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
23-
24- "github.com/aws/aws-sdk-go-v2/aws/arn"
2520 "github.com/hashicorp/terraform-plugin-framework/types"
2621 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
27- "github.com/hashicorp/terraform-provider-aws/internal/conns"
2822 "github.com/hashicorp/terraform-provider-aws/internal/create"
23+ "github.com/hashicorp/terraform-provider-aws/internal/enum"
2924 "github.com/hashicorp/terraform-provider-aws/internal/errs"
3025 "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
3126 "github.com/hashicorp/terraform-provider-aws/internal/framework"
3227 "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
3328 fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
34- "github.com/hashicorp/terraform-provider-aws/internal/sweep"
35- sweepfw "github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
29+ tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3630 "github.com/hashicorp/terraform-provider-aws/internal/tfresource"
3731 "github.com/hashicorp/terraform-provider-aws/names"
3832)
@@ -137,23 +131,19 @@ func (r *resourceNetworkPeeringConnection) Schema(ctx context.Context, req resou
137131
138132func (r * resourceNetworkPeeringConnection ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
139133 conn := r .Meta ().ODBClient (ctx )
140-
141134 var plan odbNetworkPeeringConnectionResourceModel
142135 resp .Diagnostics .Append (req .Plan .Get (ctx , & plan )... )
143136 if resp .Diagnostics .HasError () {
144137 return
145138 }
146-
147139 input := odb.CreateOdbPeeringConnectionInput {
148140 OdbNetworkId : plan .OdbNetworkId .ValueStringPointer (),
149141 PeerNetworkId : plan .PeerNetworkId .ValueStringPointer (),
150142 DisplayName : plan .DisplayName .ValueStringPointer (),
151143 Tags : getTagsIn (ctx ),
152144 }
153-
154145 out , err := conn .CreateOdbPeeringConnection (ctx , & input )
155146 if err != nil {
156-
157147 resp .Diagnostics .AddError (
158148 create .ProblemStandardMessage (names .ODB , create .ErrActionCreating , ResNameNetworkPeeringConnection , plan .DisplayName .ValueString (), err ),
159149 err .Error (),
@@ -167,12 +157,10 @@ func (r *resourceNetworkPeeringConnection) Create(ctx context.Context, req resou
167157 )
168158 return
169159 }
170-
171160 resp .Diagnostics .Append (flex .Flatten (ctx , out , & plan )... )
172161 if resp .Diagnostics .HasError () {
173162 return
174163 }
175-
176164 createTimeout := r .CreateTimeout (ctx , plan .Timeouts )
177165 createdPeeredConnection , err := waitNetworkPeeringConnectionCreated (ctx , conn , plan .OdbPeeringConnectionId .ValueString (), createTimeout )
178166 if err != nil {
@@ -187,7 +175,6 @@ func (r *resourceNetworkPeeringConnection) Create(ctx context.Context, req resou
187175 if resp .Diagnostics .HasError () {
188176 return
189177 }
190-
191178 resp .Diagnostics .Append (resp .State .Set (ctx , plan )... )
192179}
193180
@@ -244,14 +231,12 @@ func (r *resourceNetworkPeeringConnection) Read(ctx context.Context, req resourc
244231
245232func (r * resourceNetworkPeeringConnection ) Update (ctx context.Context , req resource.UpdateRequest , resp * resource.UpdateResponse ) {
246233 conn := r .Meta ().ODBClient (ctx )
247-
248234 var plan , state odbNetworkPeeringConnectionResourceModel
249235 resp .Diagnostics .Append (req .Plan .Get (ctx , & plan )... )
250236 resp .Diagnostics .Append (req .State .Get (ctx , & state )... )
251237 if resp .Diagnostics .HasError () {
252238 return
253239 }
254-
255240 updateTimeout := r .UpdateTimeout (ctx , plan .Timeouts )
256241 updatedOdbNetPeeringConn , err := waitNetworkPeeringConnectionUpdated (ctx , conn , plan .OdbPeeringConnectionId .ValueString (), updateTimeout )
257242 if err != nil {
@@ -269,7 +254,6 @@ func (r *resourceNetworkPeeringConnection) Update(ctx context.Context, req resou
269254 )
270255 return
271256 }
272-
273257 peerVpcARN , err := arn .Parse (* updatedOdbNetPeeringConn .PeerNetworkArn )
274258 if err != nil {
275259 resp .Diagnostics .AddError (
@@ -300,14 +284,11 @@ func (r *resourceNetworkPeeringConnection) Delete(ctx context.Context, req resou
300284 input := odb.DeleteOdbPeeringConnectionInput {
301285 OdbPeeringConnectionId : state .OdbPeeringConnectionId .ValueStringPointer (),
302286 }
303-
304287 _ , err := conn .DeleteOdbPeeringConnection (ctx , & input )
305-
306288 if err != nil {
307289 if errs.IsA [* odbtypes.ResourceNotFoundException ](err ) {
308290 return
309291 }
310-
311292 resp .Diagnostics .AddError (
312293 create .ProblemStandardMessage (names .ODB , create .ErrActionDeleting , ResNameNetworkPeeringConnection , state .OdbPeeringConnectionId .ValueString (), err ),
313294 err .Error (),
@@ -378,7 +359,6 @@ func waitNetworkPeeringConnectionDeleted(ctx context.Context, conn *odb.Client,
378359 if out , ok := outputRaw .(* odbtypes.OdbPeeringConnection ); ok {
379360 return out , err
380361 }
381-
382362 return nil , err
383363}
384364
@@ -388,11 +368,9 @@ func statusNetworkPeeringConnection(ctx context.Context, conn *odb.Client, id st
388368 if tfresource .NotFound (err ) {
389369 return nil , "" , nil
390370 }
391-
392371 if err != nil {
393372 return nil , "" , err
394373 }
395-
396374 return out , string (out .Status ), nil
397375 }
398376}
@@ -439,25 +417,3 @@ type odbNetworkPeeringConnectionResourceModel struct {
439417 Tags tftags.Map `tfsdk:"tags"`
440418 TagsAll tftags.Map `tfsdk:"tags_all"`
441419}
442-
443- func sweepNetworkPeeringConnections (ctx context.Context , client * conns.AWSClient ) ([]sweep.Sweepable , error ) {
444- input := odb.ListOdbPeeringConnectionsInput {}
445- conn := client .ODBClient (ctx )
446- var sweepResources []sweep.Sweepable
447-
448- pages := odb .NewListOdbPeeringConnectionsPaginator (conn , & input )
449- for pages .HasMorePages () {
450- page , err := pages .NextPage (ctx )
451- if err != nil {
452- return nil , err
453- }
454-
455- for _ , v := range page .OdbPeeringConnections {
456- sweepResources = append (sweepResources , sweepfw .NewSweepResource (newResourceNetworkPeeringConnection , client ,
457- sweepfw .NewAttribute (names .AttrID , aws .ToString (v .OdbPeeringConnectionId ))),
458- )
459- }
460- }
461-
462- return sweepResources , nil
463- }
0 commit comments