Skip to content

Commit

Permalink
service/cloudwatchlogs: Fixes for tfproviderlint R002 (#11921)
Browse files Browse the repository at this point in the history
Reference: #9952

Remove pointer value dereferences, which can cause potential panics and are extraneous as `Set()` automatically handles pointer types including when `nil`.

Previously:

```
aws/resource_aws_cloudwatch_log_destination_policy.go:77:26: R002: ResourceData.Set() pointer value dereference is extraneous
aws/resource_aws_cloudwatch_log_resource_policy.go:77:27: R002: ResourceData.Set() pointer value dereference is extraneous
```

Output from acceptance testing:

```
--- PASS: TestAccAWSCloudwatchLogDestinationPolicy_basic (86.97s)

--- PASS: TestAccAWSCloudWatchLogResourcePolicy_basic (31.10s)
```
  • Loading branch information
bflad authored Feb 26, 2020
1 parent fd6457f commit 03b75be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
14 changes: 5 additions & 9 deletions aws/resource_aws_cloudwatch_log_destination_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package aws

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceAwsCloudWatchLogDestinationPolicy() *schema.Resource {
Expand Down Expand Up @@ -67,17 +67,13 @@ func resourceAwsCloudWatchLogDestinationPolicyRead(d *schema.ResourceData, meta
return err
}

if !exists {
if !exists || destination.AccessPolicy == nil {
log.Printf("[WARN] CloudWatch Log Destination Policy (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

if destination.AccessPolicy != nil {
d.SetId(destination_name)
d.Set("access_policy", *destination.AccessPolicy)
} else {
d.SetId("")
}
d.Set("access_policy", destination.AccessPolicy)

return nil
}
Expand Down
3 changes: 1 addition & 2 deletions aws/resource_aws_cloudwatch_log_resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func resourceAwsCloudWatchLogResourcePolicyRead(d *schema.ResourceData, meta int
return nil
}

d.SetId(policyName)
d.Set("policy_document", *resourcePolicy.PolicyDocument)
d.Set("policy_document", resourcePolicy.PolicyDocument)

return nil
}
Expand Down

0 comments on commit 03b75be

Please sign in to comment.