Skip to content

Commit

Permalink
resource/aws_redshift_security_group: Fixes for tfproviderlint R002 (#…
Browse files Browse the repository at this point in the history
…12029)

Reference: #9952

Remove pointer value dereferences, which can cause potential panics and are extraneous as `Set()` automatically handles pointer types including when `nil`. Also adds missing EC2-Classic PreCheck to acceptance testing.

Previously:

```
aws/resource_aws_redshift_security_group.go:151:16: R002: ResourceData.Set() pointer value dereference is extraneous
aws/resource_aws_redshift_security_group.go:152:23: R002: ResourceData.Set() pointer value dereference is extraneous
```

Output from acceptance testing:

```
--- PASS: TestAccAWSRedshiftSecurityGroup_basic (11.89s)
--- PASS: TestAccAWSRedshiftSecurityGroup_ingressCidr (12.79s)
--- PASS: TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup (13.09s)
--- PASS: TestAccAWSRedshiftSecurityGroup_updateIngressCidr (25.35s)
--- PASS: TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup (28.94s)
```
  • Loading branch information
bflad authored Feb 21, 2020
1 parent 2a9256f commit bf061e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions aws/resource_aws_redshift_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@ func resourceAwsRedshiftSecurityGroupRead(d *schema.ResourceData, meta interface
}

for _, v := range sg.IPRanges {
rule := map[string]interface{}{"cidr": *v.CIDRIP}
rule := map[string]interface{}{"cidr": aws.StringValue(v.CIDRIP)}
rules.Add(rule)
}

for _, g := range sg.EC2SecurityGroups {
rule := map[string]interface{}{
"security_group_name": *g.EC2SecurityGroupName,
"security_group_owner_id": *g.EC2SecurityGroupOwnerId,
"security_group_name": aws.StringValue(g.EC2SecurityGroupName),
"security_group_owner_id": aws.StringValue(g.EC2SecurityGroupOwnerId),
}
rules.Add(rule)
}

d.Set("ingress", rules)
d.Set("name", *sg.ClusterSecurityGroupName)
d.Set("description", *sg.Description)
d.Set("name", sg.ClusterSecurityGroupName)
d.Set("description", sg.Description)

return nil
}
Expand Down
10 changes: 5 additions & 5 deletions aws/resource_aws_redshift_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccAWSRedshiftSecurityGroup_basic(t *testing.T) {
resourceName := "aws_redshift_security_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestAccAWSRedshiftSecurityGroup_ingressCidr(t *testing.T) {
resourceName := "aws_redshift_security_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressCidr(t *testing.T) {
resourceName := "aws_redshift_security_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup(t *testing.T) {
resourceName := "aws_redshift_security_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup(t *testing.T) {
resourceName := "aws_redshift_security_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
Expand Down

0 comments on commit bf061e0

Please sign in to comment.