Skip to content

Commit

Permalink
Merge pull request #15484 from terraform-providers/td-more-GetOk-extr…
Browse files Browse the repository at this point in the history
…aneous-conditionals

provider: Fix and prevent additional occurrences of extraneous conditionals after (helper/schema.ResourceData).GetOk() receiver method
  • Loading branch information
gdavison authored Oct 8, 2020
2 parents 9379abe + 68b07c9 commit 6e3df24
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ rules:
- pattern-either:
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(bool) { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(int) != 0 { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(int) > 0 { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(string) != "" { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && len($VALUE.(string)) > 0 { $BODY }
severity: WARNING
2 changes: 1 addition & 1 deletion aws/data_source_aws_ecr_authorization_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dataSourceAwsEcrAuthorizationToken() *schema.Resource {
func dataSourceAwsEcrAuthorizationTokenRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecrconn
params := &ecr.GetAuthorizationTokenInput{}
if v, ok := d.GetOk("registry_id"); ok && len(v.(string)) > 0 {
if v, ok := d.GetOk("registry_id"); ok {
params.RegistryIds = []*string{aws.String(v.(string))}
}
log.Printf("[DEBUG] Getting ECR authorization token")
Expand Down
13 changes: 4 additions & 9 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
opts.AvailabilityZones = expandStringList(attr.List())
}

// Need to check value > 0 due to:
// InvalidParameterValue: Backtrack is not enabled for the aurora-postgresql engine.
if v, ok := d.GetOk("backtrack_window"); ok && v.(int) > 0 {
if v, ok := d.GetOk("backtrack_window"); ok {
opts.BacktrackWindow = aws.Int64(int64(v.(int)))
}

Expand Down Expand Up @@ -569,9 +567,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
Tags: tags,
}

// Need to check value > 0 due to:
// InvalidParameterValue: Backtrack is not enabled for the aurora-postgresql engine.
if v, ok := d.GetOk("backtrack_window"); ok && v.(int) > 0 {
if v, ok := d.GetOk("backtrack_window"); ok {
createOpts.BacktrackWindow = aws.Int64(int64(v.(int)))
}

Expand Down Expand Up @@ -690,9 +686,8 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
if v, ok := d.GetOk("enable_http_endpoint"); ok {
createOpts.EnableHttpEndpoint = aws.Bool(v.(bool))
}
// Need to check value > 0 due to:
// InvalidParameterValue: Backtrack is not enabled for the aurora-postgresql engine.
if v, ok := d.GetOk("backtrack_window"); ok && v.(int) > 0 {

if v, ok := d.GetOk("backtrack_window"); ok {
createOpts.BacktrackWindow = aws.Int64(int64(v.(int)))
}

Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_wafv2_ip_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func resourceAwsWafv2IPSetUpdate(d *schema.ResourceData, meta interface{}) error
params.Addresses = expandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("description"); ok && len(v.(string)) > 0 {
if v, ok := d.GetOk("description"); ok {
params.Description = aws.String(v.(string))
}

Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_wafv2_web_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func resourceAwsWafv2WebACLUpdate(d *schema.ResourceData, meta interface{}) erro
VisibilityConfig: expandWafv2VisibilityConfig(d.Get("visibility_config").([]interface{})),
}

if v, ok := d.GetOk("description"); ok && len(v.(string)) > 0 {
if v, ok := d.GetOk("description"); ok {
u.Description = aws.String(v.(string))
}

Expand Down

0 comments on commit 6e3df24

Please sign in to comment.