@@ -439,12 +439,15 @@ const (
439
439
```go
440
440
// internal/service/{service}/{thing}.go
441
441
442
- function ExampleThingCreate(d *schema.ResourceData, meta interface{}) error {
442
+ function ExampleThingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
443
+ var diags diag.Diagnostics
443
444
// ...
444
- return ExampleThingRead(d, meta)
445
+ return append(diags, ExampleThingRead(ctx, d, meta)... )
445
446
}
446
447
447
- function ExampleThingRead(d *schema.ResourceData, meta interface{}) error {
448
+ function ExampleThingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
449
+ var diags diag.Diagnostics
450
+
448
451
conn := meta.(*AWSClient).ExampleConn()
449
452
450
453
input := &example.OperationInput{/* ... */}
@@ -476,16 +479,16 @@ const (
476
479
if !d.IsNewResource() && tfawserr.ErrorCodeEquals(err, example.ErrCodeNoSuchEntityException) {
477
480
log.Printf("[WARN] Example Thing (%s) not found, removing from state", d.Id())
478
481
d.SetId("")
479
- return nil
482
+ return diags
480
483
}
481
484
482
485
if err != nil {
483
- return fmt.Errorf( "reading Example Thing (%s): %w", d.Id(), err)
486
+ return sdkdiag.AppendErrorf(diags, "reading Example Thing (%s): %w", d.Id(), err)
484
487
}
485
488
486
489
// Prevent panics.
487
490
if output == nil {
488
- return fmt.Errorf( "reading Example Thing (%s): empty response", d.Id())
491
+ return sdkdiag.AppendErrorf(diags, "reading Example Thing (%s): empty response", d.Id())
489
492
}
490
493
491
494
// ... refresh Terraform state as normal ...
@@ -770,13 +773,15 @@ func waitThingDeleted(ctx context.Context, conn *example.Example, id string, tim
770
773
=== "Terraform Plugin SDK V2"
771
774
```go
772
775
func resourceThingCreate(ctx context.Context, d * schema.ResourceData, meta interface{}) diag.Diagnostics {
776
+ var diags diag.Diagnostics
777
+
773
778
// ... AWS Go SDK logic to create resource ...
774
779
775
780
if _, err := waitThingCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) {
776
781
return append(diags, create.DiagError(names.Example, create.ErrActionWaitingForCreation, ResNameThing, d.Id(), err)...)
777
782
}
778
783
779
- return ExampleThingRead(d, meta)
784
+ return append(diags, ExampleThingRead(ctx, d, meta)... )
780
785
}
781
786
782
787
func resourceThingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
0 commit comments