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

provider: Remove extraneous AWS Go SDK value wrapping in d.Set() #16554

Closed
bflad opened this issue Dec 2, 2020 · 2 comments · Fixed by #16650
Closed

provider: Remove extraneous AWS Go SDK value wrapping in d.Set() #16554

bflad opened this issue Dec 2, 2020 · 2 comments · Fixed by #16650
Assignees
Labels
linter Pertains to changes to or issues with the various linters. provider Pertains to the provider itself, rather than any interaction with AWS. technical-debt Addresses areas of the codebase that need refactoring or redesign.
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Dec 2, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

The (*schema.ResourceData).Set() receiver method automatically handles pointer types and nil values, so wrapping the values with the AWS Go SDK pointer conversion functions, e.g. aws.StringValue() is extraneous.

Note: This should not include slice/map functions calls such as aws.StringValueSlice() since those conversions are not automatic.

Example semgrep Rule

rules:
  - id: helper-schema-ResourceData-Set-extraneous-value-pointer-conversion
    languages: [go]
    message: AWS Go SDK pointer conversion function for `d.Set()` value is extraneous
    paths:
      include:
        - aws/
    patterns:
      - pattern-either:
        - pattern: d.Set($ATTRIBUTE, aws.BoolValue($APIOBJECT))
        - pattern: d.Set($ATTRIBUTE, aws.Int64Value($APIOBJECT))
        - pattern: d.Set($ATTRIBUTE, int(aws.Int64Value($APIOBJECT)))
        - pattern: d.Set($ATTRIBUTE, aws.StringValue($APIOBJECT))
    severity: WARNING

Example Reports

aws/resource_aws_wafv2_rule_group.go
severity:warning rule:helper-schema-ResourceData-Set-extraneous-value-wrapping: AWS Go SDK value wrapping in `d.Set()` is extraneous
188:	d.Set("name", aws.StringValue(resp.RuleGroup.Name))
189:	d.Set("capacity", aws.Int64Value(resp.RuleGroup.Capacity))
190:	d.Set("description", aws.StringValue(resp.RuleGroup.Description))
191:	d.Set("arn", aws.StringValue(resp.RuleGroup.ARN))
192:	d.Set("lock_token", aws.StringValue(resp.LockToken))

aws/resource_aws_wafv2_web_acl.go
severity:warning rule:helper-schema-ResourceData-Set-extraneous-value-wrapping: AWS Go SDK value wrapping in `d.Set()` is extraneous
215:	d.Set("name", aws.StringValue(resp.WebACL.Name))
216:	d.Set("capacity", aws.Int64Value(resp.WebACL.Capacity))
217:	d.Set("description", aws.StringValue(resp.WebACL.Description))
218:	d.Set("arn", aws.StringValue(resp.WebACL.ARN))
219:	d.Set("lock_token", aws.StringValue(resp.LockToken))

aws/resource_aws_worklink_fleet.go
severity:warning rule:helper-schema-ResourceData-Set-extraneous-value-wrapping: AWS Go SDK value wrapping in `d.Set()` is extraneous
176:	d.Set("name", aws.StringValue(resp.FleetName))
177:	d.Set("display_name", aws.StringValue(resp.DisplayName))
178:	d.Set("optimize_for_end_user_location", aws.BoolValue(resp.OptimizeForEndUserLocation))
179:	d.Set("company_code", aws.StringValue(resp.CompanyCode))

Affected Resources

TBD

Definition of Done

  • Rule added to .semgrep.yml with no reports on main branch and CI passes
@bflad bflad added technical-debt Addresses areas of the codebase that need refactoring or redesign. provider Pertains to the provider itself, rather than any interaction with AWS. linter Pertains to changes to or issues with the various linters. labels Dec 2, 2020
@anGie44 anGie44 self-assigned this Dec 7, 2020
@anGie44 anGie44 added this to the v3.36.0 milestone Apr 2, 2021
@ghost
Copy link

ghost commented Apr 9, 2021

This has been released in version 3.36.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented May 3, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linter Pertains to changes to or issues with the various linters. provider Pertains to the provider itself, rather than any interaction with AWS. technical-debt Addresses areas of the codebase that need refactoring or redesign.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants