Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Fix unreturned sdkdiag.AppendErrorf function calls #38854

Merged
merged 10 commits into from
Aug 15, 2024
24 changes: 24 additions & 0 deletions .changelog/38854.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
```release-note:bug
resource/aws_rolesanywhere_trust_anchor: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_rolesanywhere_profile: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_s3_bucket_lifecycle_configuration: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_ecs_cluster_capacity_providers: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_fms_policy: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_appstream_stack: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
resource/aws_controltower_landing_zone: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
```release-note:bug
data-source/aws_acm_certificate: Fix unreturned `sdkdiags.AppendErrorf` function calls
```
25 changes: 25 additions & 0 deletions .ci/.semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,28 @@ rules:
patterns:
- pattern-regex: "(Create|Read|Update|Delete)Context:"
severity: ERROR

- id: unreturned-sdkdiag-AppendErrorf
languages: [go]
message: Calls to `sdkdiag.AppendErrorf()` should be returned or set to the `diags` variable
paths:
include:
- internal/
patterns:
- pattern: |
if err != nil {
sdkdiag.AppendErrorf($DIAGS, ...)
}
- pattern-not: |
if err != nil {
return sdkdiag.AppendErrorf($DIAGS, ...)
}
- pattern-not: |
if err != nil {
return ..., sdkdiag.AppendErrorf($DIAGS, ...)
}
- pattern-not: |
if err != nil {
$DIAGS = sdkdiag.AppendErrorf($DIAGS, ...)
}
severity: ERROR
2 changes: 1 addition & 1 deletion internal/service/acm/certificate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func dataSourceCertificateRead(ctx context.Context, d *schema.ResourceData, meta
},
)
if tfresource.NotFound(err) {
sdkdiag.AppendErrorf(diags, "XXX no ACM Certificate matching domain (%s)", domain)
return sdkdiag.AppendErrorf(diags, "XXX no ACM Certificate matching domain (%s)", domain)
} else if err != nil {
return sdkdiag.AppendErrorf(diags, "reading ACM Certificates: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/appstream/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func resourceStackUpdate(ctx context.Context, d *schema.ResourceData, meta inter
_, err := conn.UpdateStack(ctx, input)

if err != nil {
sdkdiag.AppendErrorf(diags, "updating Appstream Stack (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "updating Appstream Stack (%s): %s", d.Id(), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/controltower/landing_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func resourceLandingZoneDelete(ctx context.Context, d *schema.ResourceData, meta
}

if _, err := waitLandingZoneOperationSucceeded(ctx, conn, aws.ToString(output.OperationIdentifier), d.Timeout(schema.TimeoutDelete)); err != nil {
sdkdiag.AppendErrorf(diags, "waiting for ControlTower Landing Zone (%s) delete: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for ControlTower Landing Zone (%s) delete: %s", d.Id(), err)
}

return diags
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ecs/cluster_capacity_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func resourceClusterCapacityProvidersRead(ctx context.Context, d *schema.Resourc
cluster, err := findClusterByNameOrARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
sdkdiag.AppendErrorf(diags, "[WARN] ECS Cluster Capacity Providers (%s) not found, removing from state", d.Id())
log.Printf("[WARN] ECS Cluster Capacity Providers (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/fms/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("delete_unused_fm_managed_resources", policy.DeleteUnusedFMManagedResources)
d.Set(names.AttrDescription, policy.PolicyDescription)
if err := d.Set("exclude_map", flattenPolicyMap(policy.ExcludeMap)); err != nil {
sdkdiag.AppendErrorf(diags, "setting exclude_map: %s", err)
diags = sdkdiag.AppendErrorf(diags, "setting exclude_map: %s", err)
}
d.Set("exclude_resource_tags", policy.ExcludeResourceTags)
if err := d.Set("include_map", flattenPolicyMap(policy.IncludeMap)); err != nil {
sdkdiag.AppendErrorf(diags, "setting include_map: %s", err)
diags = sdkdiag.AppendErrorf(diags, "setting include_map: %s", err)
}
d.Set(names.AttrName, policy.PolicyName)
d.Set("policy_update_token", policy.PolicyUpdateToken)
d.Set("remediation_enabled", policy.RemediationEnabled)
if err := d.Set(names.AttrResourceTags, flattenResourceTags(policy.ResourceTags)); err != nil {
sdkdiag.AppendErrorf(diags, "setting resource_tags: %s", err)
diags = sdkdiag.AppendErrorf(diags, "setting resource_tags: %s", err)
}
d.Set(names.AttrResourceType, policy.ResourceType)
d.Set("resource_type_list", policy.ResourceTypeList)
Expand All @@ -290,7 +290,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf
"policy_option": flattenPolicyOption(policy.SecurityServicePolicyData.PolicyOption),
}}
if err := d.Set("security_service_policy_data", securityServicePolicy); err != nil {
sdkdiag.AppendErrorf(diags, "setting security_service_policy_data: %s", err)
diags = sdkdiag.AppendErrorf(diags, "setting security_service_policy_data: %s", err)
}

return diags
Expand Down
4 changes: 2 additions & 2 deletions internal/service/rolesanywhere/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ func resourceProfileUpdate(ctx context.Context, d *schema.ResourceData, meta int
if n == true {
err := enableProfile(ctx, d.Id(), meta)
if err != nil {
sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Profile (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Profile (%s): %s", d.Id(), err)
}
} else {
err := disableProfile(ctx, d.Id(), meta)
if err != nil {
sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Profile (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Profile (%s): %s", d.Id(), err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/rolesanywhere/trust_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ func resourceTrustAnchorUpdate(ctx context.Context, d *schema.ResourceData, meta
_, n := d.GetChange(names.AttrEnabled)
if n == true {
if err := enableTrustAnchor(ctx, d.Id(), meta); err != nil {
sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err)
}
} else {
if err := disableTrustAnchor(ctx, d.Id(), meta); err != nil {
sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/s3/bucket_lifecycle_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R
_, err = waitLifecycleRulesEquals(ctx, conn, bucket, expectedBucketOwner, rules, d.Timeout(schema.TimeoutCreate))

if err != nil {
sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) create: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) create: %s", d.Id(), err)
}

return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...)
Expand Down Expand Up @@ -388,7 +388,7 @@ func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.R
_, err = waitLifecycleRulesEquals(ctx, conn, bucket, expectedBucketOwner, rules, d.Timeout(schema.TimeoutUpdate))

if err != nil {
sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) update: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) update: %s", d.Id(), err)
}

return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...)
Expand Down
Loading