diff --git a/.changelog/38512.txt b/.changelog/38512.txt new file mode 100644 index 00000000000..e4a0ef394c5 --- /dev/null +++ b/.changelog/38512.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_timestreamwrite_table: Fix `runtime error: invalid memory address or nil pointer dereference` panic when reading a non-existent table +``` \ No newline at end of file diff --git a/.ci/semgrep/errors/error-checks.yml b/.ci/semgrep/errors/error-checks.yml index cc7967d7251..23a92d44e90 100644 --- a/.ci/semgrep/errors/error-checks.yml +++ b/.ci/semgrep/errors/error-checks.yml @@ -57,3 +57,34 @@ rules: - pattern-not-inside: | tfresource.RetryWhen(...) severity: ERROR + + - id: isnewresource-notfound-without-err-checks + languages: [go] + message: When checking for !d.IsNewResource() && tfresource.NotFound() errors, typically other error conditions should be checked. + patterns: + - pattern: | + if !d.IsNewResource() && tfresource.NotFound($ERR) { ... } + - pattern-not-inside: | + if !d.IsNewResource() && tfresource.NotFound($ERR) { ... } + if $ERR != nil { ... } + # e.g. internal/service/dms/s3_endpoint.go + - pattern-not-inside: | + if !d.IsNewResource() && tfresource.NotFound($ERR) { ... } + if $ERR == nil && ... { + ... + err = ... + ... + } + if $ERR != nil { ... } + # e.g. internal/service/quicksight/analysis.go + - pattern-not-inside: | + if !d.IsNewResource() && tfresource.NotFound($ERR) { ... } + if !d.IsNewResource() && ... { ... } + if $ERR != nil { ... } + # e.g. internal/service/sagemaker/app.go + - pattern-not-inside: | + if err != nil { + if !d.IsNewResource() && tfresource.NotFound($ERR) { ... } + return ... + } + severity: ERROR diff --git a/internal/service/chime/voice_connector_logging.go b/internal/service/chime/voice_connector_logging.go index 252f36c3ef6..6dbfef750cc 100644 --- a/internal/service/chime/voice_connector_logging.go +++ b/internal/service/chime/voice_connector_logging.go @@ -92,6 +92,10 @@ func resourceVoiceConnectorLoggingRead(ctx context.Context, d *schema.ResourceDa return diags } + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading Chime Voice Connector logging configuration (%s): %s", d.Id(), err) + } + d.Set("enable_media_metric_logs", resp.EnableMediaMetricLogs) d.Set("enable_sip_logs", resp.EnableSIPLogs) d.Set("voice_connector_id", d.Id()) diff --git a/internal/service/chimesdkvoice/sip_media_application.go b/internal/service/chimesdkvoice/sip_media_application.go index 4dd6fcf3b48..0db3ff0507b 100644 --- a/internal/service/chimesdkvoice/sip_media_application.go +++ b/internal/service/chimesdkvoice/sip_media_application.go @@ -106,6 +106,10 @@ func resourceSipMediaApplicationRead(ctx context.Context, d *schema.ResourceData return diags } + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading Chime Sip Media Application (%s): %s", d.Id(), err) + } + d.Set(names.AttrARN, resp.SipMediaApplicationArn) d.Set("aws_region", resp.AwsRegion) d.Set(names.AttrName, resp.Name) diff --git a/internal/service/chimesdkvoice/sip_rule.go b/internal/service/chimesdkvoice/sip_rule.go index 3a7a7909a22..f830f0a44d1 100644 --- a/internal/service/chimesdkvoice/sip_rule.go +++ b/internal/service/chimesdkvoice/sip_rule.go @@ -122,6 +122,10 @@ func resourceSipRuleRead(ctx context.Context, d *schema.ResourceData, meta inter return diags } + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading ChimeSKVoice Sip Rule (%s): %s", d.Id(), err) + } + d.Set(names.AttrName, resp.Name) d.Set("disabled", resp.Disabled) d.Set("trigger_type", resp.TriggerType) diff --git a/internal/service/timestreamwrite/table.go b/internal/service/timestreamwrite/table.go index 0fe06144780..fed164e0c6a 100644 --- a/internal/service/timestreamwrite/table.go +++ b/internal/service/timestreamwrite/table.go @@ -233,6 +233,10 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa return diags } + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading Timestream Table (%s): %s", d.Id(), err) + } + d.Set(names.AttrARN, table.Arn) d.Set(names.AttrDatabaseName, table.DatabaseName) if err := d.Set("magnetic_store_write_properties", flattenMagneticStoreWriteProperties(table.MagneticStoreWriteProperties)); err != nil {