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

tests/provider: Fix and enable AWS SDK Go pointer conversion linting (C resources) #18335

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ rules:
- aws/cloudfront_distribution_configuration_structure.go
- aws/data_source_aws_route_table.go
- aws/opsworks_layers.go
- aws/resource_aws_c*
- aws/resource_aws_d*
- aws/resource_aws_e*
- aws/resource_aws_g*
Expand Down Expand Up @@ -94,7 +93,6 @@ rules:
- aws/data_source_aws_route*
- aws/ecs_task_definition_equivalency.go
- aws/opsworks_layers.go
- aws/resource_aws_c*.go
- aws/resource_aws_d*.go
- aws/resource_aws_e*.go
- aws/resource_aws_g*.go
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_cloud9_environment_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ func resourceAwsCloud9EnvironmentEc2Create(d *schema.ResourceData, meta interfac
return 42, "", err
}

status := *out.Status
var sErr error
status := aws.StringValue(out.Status)

if status == cloud9.EnvironmentStatusError && out.Message != nil {
sErr = fmt.Errorf("Reason: %s", *out.Message)
return out, status, fmt.Errorf("Reason: %s", aws.StringValue(out.Message))
}

return out, status, sErr
return out, status, nil
},
}
_, err = stateConf.WaitForState()
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_cloudfront_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func testSweepCloudFrontDistributions(region string) error {
}

for _, distributionSummary := range distributionSummaries {
distributionID := *distributionSummary.Id
distributionID := aws.StringValue(distributionSummary.Id)

if *distributionSummary.Enabled {
if aws.BoolValue(distributionSummary.Enabled) {
log.Printf("[WARN] Skipping deletion of enabled CloudFront Distribution: %s", distributionID)
continue
}
Expand Down
10 changes: 8 additions & 2 deletions aws/resource_aws_cloudfront_origin_request_policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -154,11 +155,16 @@ func resourceAwsCloudFrontOriginRequestPolicyRead(d *schema.ResourceData, meta i
}

if err != nil {
return err
return fmt.Errorf("error reading CloudFront Origin Request Policy (%s): %w", d.Id(), err)
}

if resp == nil || resp.OriginRequestPolicy == nil || resp.OriginRequestPolicy.OriginRequestPolicyConfig == nil {
return fmt.Errorf("error reading CloudFront Origin Request Policy (%s): empty response", d.Id())
}

d.Set("etag", aws.StringValue(resp.ETag))

originRequestPolicy := *resp.OriginRequestPolicy.OriginRequestPolicyConfig
originRequestPolicy := resp.OriginRequestPolicy.OriginRequestPolicyConfig
d.Set("comment", aws.StringValue(originRequestPolicy.Comment))
d.Set("name", aws.StringValue(originRequestPolicy.Name))
d.Set("cookies_config", flattenCloudFrontOriginRequestPolicyCookiesConfig(originRequestPolicy.CookiesConfig))
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func resourceAwsCloudTrailRead(d *schema.ResourceData, meta interface{}) error {
// you're looking for is not found. Instead, it's simply not in the list.
var trail *cloudtrail.Trail
for _, c := range resp.TrailList {
if d.Id() == *c.Name {
if d.Id() == aws.StringValue(c.Name) {
trail = c
}
}
Expand Down Expand Up @@ -566,8 +566,8 @@ func flattenAwsCloudTrailEventSelector(configured []*cloudtrail.EventSelector) [

for _, raw := range configured {
item := make(map[string]interface{})
item["read_write_type"] = *raw.ReadWriteType
item["include_management_events"] = *raw.IncludeManagementEvents
item["read_write_type"] = aws.StringValue(raw.ReadWriteType)
item["include_management_events"] = aws.BoolValue(raw.IncludeManagementEvents)
item["data_resource"] = flattenAwsCloudTrailEventSelectorDataResource(raw.DataResources)

eventSelectors = append(eventSelectors, item)
Expand All @@ -581,7 +581,7 @@ func flattenAwsCloudTrailEventSelectorDataResource(configured []*cloudtrail.Data

for _, raw := range configured {
item := make(map[string]interface{})
item["type"] = *raw.Type
item["type"] = aws.StringValue(raw.Type)
item["values"] = flattenStringList(raw.Values)

dataResources = append(dataResources, item)
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_log_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func lookupCloudWatchLogDestination(conn *cloudwatchlogs.CloudWatchLogs,
}

for _, destination := range resp.Destinations {
if *destination.DestinationName == name {
if aws.StringValue(destination.DestinationName) == name {
return destination, true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_log_metric_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func lookupCloudWatchLogMetricFilter(conn *cloudwatchlogs.CloudWatchLogs,
}

for _, mf := range resp.MetricFilters {
if *mf.FilterName == name {
if aws.StringValue(mf.FilterName) == name {
return mf, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_log_resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func lookupCloudWatchLogResourcePolicy(conn *cloudwatchlogs.CloudWatchLogs,
}

for _, resourcePolicy := range resp.ResourcePolicies {
if *resourcePolicy.PolicyName == name {
if aws.StringValue(resourcePolicy.PolicyName) == name {
return resourcePolicy, true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func lookupCloudWatchLogStream(conn *cloudwatchlogs.CloudWatchLogs,
}

for _, ls := range resp.LogStreams {
if *ls.LogStreamName == name {
if aws.StringValue(ls.LogStreamName) == name {
return ls, true, nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_cloudwatch_metric_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func resourceAwsCloudWatchMetricAlarmRead(d *schema.ResourceData, meta interface
if err := d.Set("alarm_actions", flattenStringSet(resp.AlarmActions)); err != nil {
log.Printf("[WARN] Error setting Alarm Actions: %s", err)
}
arn := *resp.AlarmArn
arn := aws.StringValue(resp.AlarmArn)
d.Set("alarm_description", resp.AlarmDescription)
d.Set("alarm_name", resp.AlarmName)
d.Set("arn", arn)
Expand Down Expand Up @@ -578,7 +578,7 @@ func getAwsCloudWatchMetricAlarm(d *schema.ResourceData, meta interface{}) (*clo
func flattenDimensions(dims []*cloudwatch.Dimension) map[string]interface{} {
flatDims := make(map[string]interface{})
for _, d := range dims {
flatDims[*d.Name] = *d.Value
flatDims[aws.StringValue(d.Name)] = aws.StringValue(d.Value)
}
return flatDims
}
62 changes: 31 additions & 31 deletions aws/resource_aws_codedeploy_deployment_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,14 +1107,14 @@ func ec2TagFiltersToMap(list []*codedeploy.EC2TagFilter) []map[string]interface{
result := make([]map[string]interface{}, 0, len(list))
for _, tf := range list {
l := make(map[string]interface{})
if tf.Key != nil && *tf.Key != "" {
l["key"] = *tf.Key
if v := tf.Key; aws.StringValue(v) != "" {
l["key"] = aws.StringValue(v)
}
if tf.Value != nil && *tf.Value != "" {
l["value"] = *tf.Value
if v := tf.Value; aws.StringValue(v) != "" {
l["value"] = aws.StringValue(v)
}
if tf.Type != nil && *tf.Type != "" {
l["type"] = *tf.Type
if v := tf.Type; aws.StringValue(v) != "" {
l["type"] = aws.StringValue(v)
}
result = append(result, l)
}
Expand All @@ -1126,14 +1126,14 @@ func onPremisesTagFiltersToMap(list []*codedeploy.TagFilter) []map[string]string
result := make([]map[string]string, 0, len(list))
for _, tf := range list {
l := make(map[string]string)
if tf.Key != nil && *tf.Key != "" {
l["key"] = *tf.Key
if v := tf.Key; aws.StringValue(v) != "" {
l["key"] = aws.StringValue(v)
}
if tf.Value != nil && *tf.Value != "" {
l["value"] = *tf.Value
if v := tf.Value; aws.StringValue(v) != "" {
l["value"] = aws.StringValue(v)
}
if tf.Type != nil && *tf.Type != "" {
l["type"] = *tf.Type
if v := tf.Type; aws.StringValue(v) != "" {
l["type"] = aws.StringValue(v)
}
result = append(result, l)
}
Expand Down Expand Up @@ -1168,8 +1168,8 @@ func triggerConfigsToMap(list []*codedeploy.TriggerConfig) []map[string]interfac
for _, tc := range list {
item := make(map[string]interface{})
item["trigger_events"] = flattenStringSet(tc.TriggerEvents)
item["trigger_name"] = *tc.TriggerName
item["trigger_target_arn"] = *tc.TriggerTargetArn
item["trigger_name"] = aws.StringValue(tc.TriggerName)
item["trigger_target_arn"] = aws.StringValue(tc.TriggerTargetArn)
result = append(result, item)
}
return result
Expand All @@ -1184,7 +1184,7 @@ func autoRollbackConfigToMap(config *codedeploy.AutoRollbackConfiguration) []map
// otherwise empty configurations will be created
if config != nil && (*config.Enabled || len(config.Events) > 0) {
item := make(map[string]interface{})
item["enabled"] = *config.Enabled
item["enabled"] = aws.BoolValue(config.Enabled)
item["events"] = flattenStringSet(config.Events)
result = append(result, item)
}
Expand All @@ -1207,8 +1207,8 @@ func alarmConfigToMap(config *codedeploy.AlarmConfiguration) []map[string]interf

item := make(map[string]interface{})
item["alarms"] = flattenStringSet(names)
item["enabled"] = *config.Enabled
item["ignore_poll_alarm_failure"] = *config.IgnorePollAlarmFailure
item["enabled"] = aws.BoolValue(config.Enabled)
item["ignore_poll_alarm_failure"] = aws.BoolValue(config.IgnorePollAlarmFailure)

result = append(result, item)
}
Expand Down Expand Up @@ -1311,11 +1311,11 @@ func flattenDeploymentStyle(style *codedeploy.DeploymentStyle) []map[string]inte
}

item := make(map[string]interface{})
if style.DeploymentOption != nil {
item["deployment_option"] = *style.DeploymentOption
if v := style.DeploymentOption; v != nil {
item["deployment_option"] = aws.StringValue(v)
}
if style.DeploymentType != nil {
item["deployment_type"] = *style.DeploymentType
if v := style.DeploymentType; v != nil {
item["deployment_type"] = aws.StringValue(v)
}

result := make([]map[string]interface{}, 0, 1)
Expand Down Expand Up @@ -1351,11 +1351,11 @@ func flattenBlueGreenDeploymentConfig(config *codedeploy.BlueGreenDeploymentConf
a := make([]map[string]interface{}, 0)
deploymentReadyOption := make(map[string]interface{})

if config.DeploymentReadyOption.ActionOnTimeout != nil {
deploymentReadyOption["action_on_timeout"] = *config.DeploymentReadyOption.ActionOnTimeout
if v := config.DeploymentReadyOption.ActionOnTimeout; v != nil {
deploymentReadyOption["action_on_timeout"] = aws.StringValue(v)
}
if config.DeploymentReadyOption.WaitTimeInMinutes != nil {
deploymentReadyOption["wait_time_in_minutes"] = *config.DeploymentReadyOption.WaitTimeInMinutes
if v := config.DeploymentReadyOption.WaitTimeInMinutes; v != nil {
deploymentReadyOption["wait_time_in_minutes"] = aws.Int64Value(v)
}

m["deployment_ready_option"] = append(a, deploymentReadyOption)
Expand All @@ -1365,8 +1365,8 @@ func flattenBlueGreenDeploymentConfig(config *codedeploy.BlueGreenDeploymentConf
b := make([]map[string]interface{}, 0)
greenFleetProvisioningOption := make(map[string]interface{})

if config.GreenFleetProvisioningOption.Action != nil {
greenFleetProvisioningOption["action"] = *config.GreenFleetProvisioningOption.Action
if v := config.GreenFleetProvisioningOption.Action; v != nil {
greenFleetProvisioningOption["action"] = aws.StringValue(v)
}

m["green_fleet_provisioning_option"] = append(b, greenFleetProvisioningOption)
Expand All @@ -1376,11 +1376,11 @@ func flattenBlueGreenDeploymentConfig(config *codedeploy.BlueGreenDeploymentConf
c := make([]map[string]interface{}, 0)
blueInstanceTerminationOption := make(map[string]interface{})

if config.TerminateBlueInstancesOnDeploymentSuccess.Action != nil {
blueInstanceTerminationOption["action"] = *config.TerminateBlueInstancesOnDeploymentSuccess.Action
if v := config.TerminateBlueInstancesOnDeploymentSuccess.Action; v != nil {
blueInstanceTerminationOption["action"] = aws.StringValue(v)
}
if config.TerminateBlueInstancesOnDeploymentSuccess.TerminationWaitTimeInMinutes != nil {
blueInstanceTerminationOption["termination_wait_time_in_minutes"] = *config.TerminateBlueInstancesOnDeploymentSuccess.TerminationWaitTimeInMinutes
if v := config.TerminateBlueInstancesOnDeploymentSuccess.TerminationWaitTimeInMinutes; v != nil {
blueInstanceTerminationOption["termination_wait_time_in_minutes"] = aws.Int64Value(v)
}

m["terminate_blue_instances_on_deployment_success"] = append(c, blueInstanceTerminationOption)
Expand Down
25 changes: 4 additions & 21 deletions aws/resource_aws_codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func expandAwsCodePipelineActions(a []interface{}) []*codepipeline.ActionDeclara
for _, config := range a {
data := config.(map[string]interface{})

conf := expandAwsCodePipelineStageActionConfiguration(data["configuration"].(map[string]interface{}))
conf := stringMapToPointers(data["configuration"].(map[string]interface{}))

action := codepipeline.ActionDeclaration{
ActionTypeId: &codepipeline.ActionTypeId{
Expand Down Expand Up @@ -406,7 +406,7 @@ func flattenAwsCodePipelineStageActions(si int, actions []*codepipeline.ActionDe
"name": aws.StringValue(action.Name),
}
if action.Configuration != nil {
config := flattenAwsCodePipelineStageActionConfiguration(action.Configuration)
config := aws.StringValueMap(action.Configuration)

actionProvider := aws.StringValue(action.ActionTypeId.Provider)
if actionProvider == CodePipelineProviderGitHub {
Expand Down Expand Up @@ -449,23 +449,6 @@ func flattenAwsCodePipelineStageActions(si int, actions []*codepipeline.ActionDe
return actionsList
}

func expandAwsCodePipelineStageActionConfiguration(config map[string]interface{}) map[string]*string {
m := map[string]*string{}
for k, v := range config {
s := v.(string)
m[k] = &s
}
return m
}

func flattenAwsCodePipelineStageActionConfiguration(config map[string]*string) map[string]string {
m := map[string]string{}
for k, v := range config {
m[k] = *v
}
return m
}

func expandAwsCodePipelineActionsOutputArtifacts(s []interface{}) []*codepipeline.OutputArtifact {
outputArtifacts := []*codepipeline.OutputArtifact{}
for _, artifact := range s {
Expand All @@ -482,7 +465,7 @@ func expandAwsCodePipelineActionsOutputArtifacts(s []interface{}) []*codepipelin
func flattenAwsCodePipelineActionsOutputArtifacts(artifacts []*codepipeline.OutputArtifact) []string {
values := []string{}
for _, artifact := range artifacts {
values = append(values, *artifact.Name)
values = append(values, aws.StringValue(artifact.Name))
}
return values
}
Expand All @@ -503,7 +486,7 @@ func expandAwsCodePipelineActionsInputArtifacts(s []interface{}) []*codepipeline
func flattenAwsCodePipelineActionsInputArtifacts(artifacts []*codepipeline.InputArtifact) []string {
values := []string{}
for _, artifact := range artifacts {
values = append(values, *artifact.Name)
values = append(values, aws.StringValue(artifact.Name))
}
return values
}
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_config_remediation_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ func flattenRemediationConfigurationParameters(parameters map[string]*configserv
for key, value := range parameters {
item := make(map[string]interface{})
item["name"] = key
if value.ResourceValue != nil {
item["resource_value"] = *value.ResourceValue.Value
if v := value.ResourceValue; v != nil {
item["resource_value"] = aws.StringValue(v.Value)
}
if value.StaticValue != nil && len(value.StaticValue.Values) > 0 {
item["static_value"] = *value.StaticValue.Values[0]
if v := value.StaticValue; v != nil && len(v.Values) > 0 {
item["static_value"] = aws.StringValue(v.Values[0])
}

items = append(items, item)
Expand Down