From d2e38fda635c116ddafb8cd63bf2fdf2c243d64f Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 27 Jul 2018 09:17:02 -0400 Subject: [PATCH 1/2] elbv2: Prevent panics from unsafe dereferences --- aws/data_source_aws_lb.go | 5 +- aws/data_source_aws_lb_target_group.go | 5 +- aws/resource_aws_alb_target_group_test.go | 5 +- aws/resource_aws_lb.go | 43 ++++----- aws/resource_aws_lb_listener.go | 43 ++++----- aws/resource_aws_lb_listener_certificate.go | 7 +- ...source_aws_lb_listener_certificate_test.go | 7 +- aws/resource_aws_lb_listener_rule.go | 48 +++++----- aws/resource_aws_lb_listener_rule_test.go | 5 +- aws/resource_aws_lb_listener_test.go | 3 +- aws/resource_aws_lb_target_group.go | 96 +++++++++---------- ...resource_aws_lb_target_group_attachment.go | 19 ++-- ...rce_aws_lb_target_group_attachment_test.go | 5 +- aws/resource_aws_lb_target_group_test.go | 5 +- aws/resource_aws_lb_test.go | 18 ++-- 15 files changed, 141 insertions(+), 173 deletions(-) diff --git a/aws/data_source_aws_lb.go b/aws/data_source_aws_lb.go index 0d46b4e2b00..6a7395a59f7 100644 --- a/aws/data_source_aws_lb.go +++ b/aws/data_source_aws_lb.go @@ -6,7 +6,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/schema" ) @@ -140,12 +139,12 @@ func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Reading Load Balancer: %s", describeLbOpts) describeResp, err := elbconn.DescribeLoadBalancers(describeLbOpts) if err != nil { - return errwrap.Wrapf("Error retrieving LB: {{err}}", err) + return fmt.Errorf("Error retrieving LB: %s", err) } if len(describeResp.LoadBalancers) != 1 { return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(describeResp.LoadBalancers)) } - d.SetId(*describeResp.LoadBalancers[0].LoadBalancerArn) + d.SetId(aws.StringValue(describeResp.LoadBalancers[0].LoadBalancerArn)) return flattenAwsLbResource(d, meta, describeResp.LoadBalancers[0]) } diff --git a/aws/data_source_aws_lb_target_group.go b/aws/data_source_aws_lb_target_group.go index ceefffb348c..5f7f20f728b 100644 --- a/aws/data_source_aws_lb_target_group.go +++ b/aws/data_source_aws_lb_target_group.go @@ -6,7 +6,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/schema" ) @@ -147,7 +146,7 @@ func dataSourceAwsLbTargetGroupRead(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] Reading Load Balancer Target Group: %s", describeTgOpts) describeResp, err := elbconn.DescribeTargetGroups(describeTgOpts) if err != nil { - return errwrap.Wrapf("Error retrieving LB Target Group: {{err}}", err) + return fmt.Errorf("Error retrieving LB Target Group: %s", err) } if len(describeResp.TargetGroups) != 1 { return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(describeResp.TargetGroups)) @@ -155,6 +154,6 @@ func dataSourceAwsLbTargetGroupRead(d *schema.ResourceData, meta interface{}) er targetGroup := describeResp.TargetGroups[0] - d.SetId(*targetGroup.TargetGroupArn) + d.SetId(aws.StringValue(targetGroup.TargetGroupArn)) return flattenAwsLbTargetGroupResource(d, meta, targetGroup) } diff --git a/aws/resource_aws_alb_target_group_test.go b/aws/resource_aws_alb_target_group_test.go index 44744f651a5..99a073c41f0 100644 --- a/aws/resource_aws_alb_target_group_test.go +++ b/aws/resource_aws_alb_target_group_test.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -495,10 +494,10 @@ func testAccCheckAWSALBTargetGroupDestroy(s *terraform.State) error { } // Verify the error - if isTargetGroupNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") { return nil } else { - return errwrap.Wrapf("Unexpected error checking ALB destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking ALB destroyed: %s", err) } } diff --git a/aws/resource_aws_lb.go b/aws/resource_aws_lb.go index f9a6fd29d36..5add0801f2d 100644 --- a/aws/resource_aws_lb.go +++ b/aws/resource_aws_lb.go @@ -11,7 +11,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -264,7 +263,7 @@ func resourceAwsLbCreate(d *schema.ResourceData, meta interface{}) error { resp, err := elbconn.CreateLoadBalancer(elbOpts) if err != nil { - return errwrap.Wrapf("Error creating Application Load Balancer: {{err}}", err) + return fmt.Errorf("Error creating Application Load Balancer: %s", err) } if len(resp.LoadBalancers) != 1 { @@ -272,7 +271,7 @@ func resourceAwsLbCreate(d *schema.ResourceData, meta interface{}) error { } lb := resp.LoadBalancers[0] - d.SetId(*lb.LoadBalancerArn) + d.SetId(aws.StringValue(lb.LoadBalancerArn)) log.Printf("[INFO] LB ID: %s", d.Id()) stateConf := &resource.StateChangeConf{ @@ -287,13 +286,13 @@ func resourceAwsLbCreate(d *schema.ResourceData, meta interface{}) error { } if len(describeResp.LoadBalancers) != 1 { - return nil, "", fmt.Errorf("No load balancers returned for %s", *lb.LoadBalancerArn) + return nil, "", fmt.Errorf("No load balancers returned for %s", aws.StringValue(lb.LoadBalancerArn)) } dLb := describeResp.LoadBalancers[0] - log.Printf("[INFO] LB state: %s", *dLb.State.Code) + log.Printf("[INFO] LB state: %s", aws.StringValue(dLb.State.Code)) - return describeResp, *dLb.State.Code, nil + return describeResp, aws.StringValue(dLb.State.Code), nil }, Timeout: d.Timeout(schema.TimeoutCreate), MinTimeout: 10 * time.Second, @@ -324,7 +323,7 @@ func resourceAwsLbRead(d *schema.ResourceData, meta interface{}) error { return nil } - return errwrap.Wrapf("Error retrieving ALB: {{err}}", err) + return fmt.Errorf("Error retrieving ALB: %s", err) } if len(describeResp.LoadBalancers) != 1 { return fmt.Errorf("Unable to find ALB: %#v", describeResp.LoadBalancers) @@ -338,7 +337,7 @@ func resourceAwsLbUpdate(d *schema.ResourceData, meta interface{}) error { if !d.IsNewResource() { if err := setElbV2Tags(elbconn, d); err != nil { - return errwrap.Wrapf("Error Modifying Tags on ALB: {{err}}", err) + return fmt.Errorf("Error Modifying Tags on ALB: %s", err) } } @@ -474,9 +473,9 @@ func resourceAwsLbUpdate(d *schema.ResourceData, meta interface{}) error { } dLb := describeResp.LoadBalancers[0] - log.Printf("[INFO] LB state: %s", *dLb.State.Code) + log.Printf("[INFO] LB state: %s", aws.StringValue(dLb.State.Code)) - return describeResp, *dLb.State.Code, nil + return describeResp, aws.StringValue(dLb.State.Code), nil }, Timeout: d.Timeout(schema.TimeoutUpdate), MinTimeout: 10 * time.Second, @@ -623,7 +622,7 @@ func getLbNameFromArn(arn string) (string, error) { func flattenSubnetsFromAvailabilityZones(availabilityZones []*elbv2.AvailabilityZone) []string { var result []string for _, az := range availabilityZones { - result = append(result, *az.SubnetId) + result = append(result, aws.StringValue(az.SubnetId)) } return result } @@ -633,10 +632,10 @@ func flattenSubnetMappingsFromAvailabilityZones(availabilityZones []*elbv2.Avail for _, availabilityZone := range availabilityZones { for _, loadBalancerAddress := range availabilityZone.LoadBalancerAddresses { m := make(map[string]interface{}, 0) - m["subnet_id"] = *availabilityZone.SubnetId + m["subnet_id"] = aws.StringValue(availabilityZone.SubnetId) if loadBalancerAddress.AllocationId != nil { - m["allocation_id"] = *loadBalancerAddress.AllocationId + m["allocation_id"] = aws.StringValue(loadBalancerAddress.AllocationId) } l = append(l, m) @@ -666,7 +665,7 @@ func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.Lo d.Set("arn", lb.LoadBalancerArn) d.Set("arn_suffix", lbSuffixFromARN(lb.LoadBalancerArn)) d.Set("name", lb.LoadBalancerName) - d.Set("internal", (lb.Scheme != nil && *lb.Scheme == "internal")) + d.Set("internal", (lb.Scheme != nil && aws.StringValue(lb.Scheme) == "internal")) d.Set("security_groups", flattenStringList(lb.SecurityGroups)) d.Set("vpc_id", lb.VpcId) d.Set("zone_id", lb.CanonicalHostedZoneId) @@ -686,7 +685,7 @@ func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.Lo ResourceArns: []*string{lb.LoadBalancerArn}, }) if err != nil { - return errwrap.Wrapf("Error retrieving LB Tags: {{err}}", err) + return fmt.Errorf("Error retrieving LB Tags: %s", err) } var et []*elbv2.Tag @@ -702,12 +701,12 @@ func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.Lo LoadBalancerArn: aws.String(d.Id()), }) if err != nil { - return errwrap.Wrapf("Error retrieving LB Attributes: {{err}}", err) + return fmt.Errorf("Error retrieving LB Attributes: %s", err) } accessLogMap := map[string]interface{}{} for _, attr := range attributesResp.Attributes { - switch *attr.Key { + switch aws.StringValue(attr.Key) { case "access_logs.s3.enabled": accessLogMap["enabled"] = aws.StringValue(attr.Value) == "true" case "access_logs.s3.bucket": @@ -715,22 +714,22 @@ func flattenAwsLbResource(d *schema.ResourceData, meta interface{}, lb *elbv2.Lo case "access_logs.s3.prefix": accessLogMap["prefix"] = aws.StringValue(attr.Value) case "idle_timeout.timeout_seconds": - timeout, err := strconv.Atoi(*attr.Value) + timeout, err := strconv.Atoi(aws.StringValue(attr.Value)) if err != nil { - return errwrap.Wrapf("Error parsing ALB timeout: {{err}}", err) + return fmt.Errorf("Error parsing ALB timeout: %s", err) } log.Printf("[DEBUG] Setting ALB Timeout Seconds: %d", timeout) d.Set("idle_timeout", timeout) case "deletion_protection.enabled": - protectionEnabled := (*attr.Value) == "true" + protectionEnabled := aws.StringValue(attr.Value) == "true" log.Printf("[DEBUG] Setting LB Deletion Protection Enabled: %t", protectionEnabled) d.Set("enable_deletion_protection", protectionEnabled) case "routing.http2.enabled": - http2Enabled := (*attr.Value) == "true" + http2Enabled := aws.StringValue(attr.Value) == "true" log.Printf("[DEBUG] Setting ALB HTTP/2 Enabled: %t", http2Enabled) d.Set("enable_http2", http2Enabled) case "load_balancing.cross_zone.enabled": - crossZoneLbEnabled := (*attr.Value) == "true" + crossZoneLbEnabled := aws.StringValue(attr.Value) == "true" log.Printf("[DEBUG] Setting NLB Cross Zone Load Balancing Enabled: %t", crossZoneLbEnabled) d.Set("enable_cross_zone_load_balancing", crossZoneLbEnabled) } diff --git a/aws/resource_aws_lb_listener.go b/aws/resource_aws_lb_listener.go index 918d05250b0..221a180ad3f 100644 --- a/aws/resource_aws_lb_listener.go +++ b/aws/resource_aws_lb_listener.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" @@ -50,7 +49,11 @@ func resourceAwsLbListener() *schema.Resource { StateFunc: func(v interface{}) string { return strings.ToUpper(v.(string)) }, - ValidateFunc: validateLbListenerProtocol(), + ValidateFunc: validation.StringInSlice([]string{ + elbv2.ProtocolEnumHttp, + elbv2.ProtocolEnumHttps, + elbv2.ProtocolEnumTcp, + }, true), }, "ssl_policy": { @@ -74,9 +77,11 @@ func resourceAwsLbListener() *schema.Resource { Required: true, }, "type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validateLbListenerActionType(), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + elbv2.ActionTypeEnumForward, + }, true), }, }, }, @@ -136,7 +141,7 @@ func resourceAwsLbListenerCreate(d *schema.ResourceData, meta interface{}) error }) if err != nil { - return errwrap.Wrapf("Error creating LB Listener: {{err}}", err) + return fmt.Errorf("Error creating LB Listener: %s", err) } if len(resp.Listeners) == 0 { @@ -160,7 +165,7 @@ func resourceAwsLbListenerRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return errwrap.Wrapf("Error retrieving Listener: {{err}}", err) + return fmt.Errorf("Error retrieving Listener: %s", err) } if len(resp.Listeners) != 1 { @@ -175,7 +180,7 @@ func resourceAwsLbListenerRead(d *schema.ResourceData, meta interface{}) error { d.Set("protocol", listener.Protocol) d.Set("ssl_policy", listener.SslPolicy) - if listener.Certificates != nil && len(listener.Certificates) == 1 { + if listener.Certificates != nil && len(listener.Certificates) == 1 && listener.Certificates[0] != nil { d.Set("certificate_arn", listener.Certificates[0].CertificateArn) } @@ -183,8 +188,8 @@ func resourceAwsLbListenerRead(d *schema.ResourceData, meta interface{}) error { if listener.DefaultActions != nil && len(listener.DefaultActions) > 0 { for _, defaultAction := range listener.DefaultActions { action := map[string]interface{}{ - "target_group_arn": *defaultAction.TargetGroupArn, - "type": *defaultAction.Type, + "target_group_arn": aws.StringValue(defaultAction.TargetGroupArn), + "type": aws.StringValue(defaultAction.Type), } defaultActions = append(defaultActions, action) } @@ -238,7 +243,7 @@ func resourceAwsLbListenerUpdate(d *schema.ResourceData, meta interface{}) error return nil }) if err != nil { - return errwrap.Wrapf("Error modifying LB Listener: {{err}}", err) + return fmt.Errorf("Error modifying LB Listener: %s", err) } return resourceAwsLbListenerRead(d, meta) @@ -251,22 +256,8 @@ func resourceAwsLbListenerDelete(d *schema.ResourceData, meta interface{}) error ListenerArn: aws.String(d.Id()), }) if err != nil { - return errwrap.Wrapf("Error deleting Listener: {{err}}", err) + return fmt.Errorf("Error deleting Listener: %s", err) } return nil } - -func validateLbListenerActionType() schema.SchemaValidateFunc { - return validation.StringInSlice([]string{ - elbv2.ActionTypeEnumForward, - }, true) -} - -func validateLbListenerProtocol() schema.SchemaValidateFunc { - return validation.StringInSlice([]string{ - "http", - "https", - "tcp", - }, true) -} diff --git a/aws/resource_aws_lb_listener_certificate.go b/aws/resource_aws_lb_listener_certificate.go index 39f32ad53ed..9b92eae6b0e 100644 --- a/aws/resource_aws_lb_listener_certificate.go +++ b/aws/resource_aws_lb_listener_certificate.go @@ -6,10 +6,9 @@ import ( "log" "time" - "github.com/hashicorp/terraform/helper/resource" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -141,11 +140,11 @@ func findAwsLbListenerCertificate(certificateArn, listenerArn string, skipDefaul } for _, cert := range resp.Certificates { - if skipDefault && *cert.IsDefault { + if skipDefault && aws.BoolValue(cert.IsDefault) { continue } - if *cert.CertificateArn == certificateArn { + if aws.StringValue(cert.CertificateArn) == certificateArn { return cert, nil } } diff --git a/aws/resource_aws_lb_listener_certificate_test.go b/aws/resource_aws_lb_listener_certificate_test.go index d4809472fd3..35b8a4d4771 100644 --- a/aws/resource_aws_lb_listener_certificate_test.go +++ b/aws/resource_aws_lb_listener_certificate_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" @@ -111,7 +110,7 @@ func testAccCheckAwsLbListenerCertificateDestroy(s *terraform.State) error { resp, err := conn.DescribeListenerCertificates(input) if err != nil { - if wserr, ok := err.(awserr.Error); ok && wserr.Code() == "ListenerNotFound" { + if isAWSErr(err, elbv2.ErrCodeListenerNotFoundException, "") { return nil } return err @@ -119,11 +118,11 @@ func testAccCheckAwsLbListenerCertificateDestroy(s *terraform.State) error { for _, cert := range resp.Certificates { // We only care about additional certificates. - if *cert.IsDefault { + if aws.BoolValue(cert.IsDefault) { continue } - if *cert.CertificateArn == rs.Primary.Attributes["certificate_arn"] { + if aws.StringValue(cert.CertificateArn) == rs.Primary.Attributes["certificate_arn"] { return errors.New("LB listener certificate not destroyed") } } diff --git a/aws/resource_aws_lb_listener_rule.go b/aws/resource_aws_lb_listener_rule.go index c32465a64e7..9ae34b825a7 100644 --- a/aws/resource_aws_lb_listener_rule.go +++ b/aws/resource_aws_lb_listener_rule.go @@ -10,11 +10,10 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) func resourceAwsLbbListenerRule() *schema.Resource { @@ -54,9 +53,11 @@ func resourceAwsLbbListenerRule() *schema.Resource { Required: true, }, "type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validateLbListenerActionType(), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + elbv2.ActionTypeEnumForward, + }, true), }, }, }, @@ -150,7 +151,7 @@ func resourceAwsLbListenerRuleCreate(d *schema.ResourceData, meta interface{}) e return errors.New("Error creating LB Listener Rule: no rules returned in response") } - d.SetId(*resp.Rules[0].RuleArn) + d.SetId(aws.StringValue(resp.Rules[0].RuleArn)) return resourceAwsLbListenerRuleRead(d, meta) } @@ -162,12 +163,12 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err RuleArns: []*string{aws.String(d.Id())}, }) if err != nil { - if isRuleNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeRuleNotFoundException, "") { log.Printf("[WARN] DescribeRules - removing %s from state", d.Id()) d.SetId("") return nil } - return errwrap.Wrapf(fmt.Sprintf("Error retrieving Rules for listener %s: {{err}}", d.Id()), err) + return fmt.Errorf("Error retrieving Rules for listener %q: %s", d.Id(), err) } if len(resp.Rules) != 1 { @@ -179,14 +180,14 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err d.Set("arn", rule.RuleArn) // The listener arn isn't in the response but can be derived from the rule arn - d.Set("listener_arn", lbListenerARNFromRuleARN(*rule.RuleArn)) + d.Set("listener_arn", lbListenerARNFromRuleARN(aws.StringValue(rule.RuleArn))) // Rules are evaluated in priority order, from the lowest value to the highest value. The default rule has the lowest priority. - if *rule.Priority == "default" { + if aws.StringValue(rule.Priority) == "default" { d.Set("priority", 99999) } else { - if priority, err := strconv.Atoi(*rule.Priority); err != nil { - return fmt.Errorf("Cannot convert rule priority %q to int: {{err}}", err) + if priority, err := strconv.Atoi(aws.StringValue(rule.Priority)); err != nil { + return fmt.Errorf("Cannot convert rule priority %q to int: %s", err) } else { d.Set("priority", priority) } @@ -195,8 +196,8 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err actions := make([]interface{}, len(rule.Actions)) for i, action := range rule.Actions { actionMap := make(map[string]interface{}) - actionMap["target_group_arn"] = *action.TargetGroupArn - actionMap["type"] = *action.Type + actionMap["target_group_arn"] = aws.StringValue(action.TargetGroupArn) + actionMap["type"] = aws.StringValue(action.Type) actions[i] = actionMap } d.Set("action", actions) @@ -204,10 +205,10 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err conditions := make([]interface{}, len(rule.Conditions)) for i, condition := range rule.Conditions { conditionMap := make(map[string]interface{}) - conditionMap["field"] = *condition.Field + conditionMap["field"] = aws.StringValue(condition.Field) conditionValues := make([]string, len(condition.Values)) for k, value := range condition.Values { - conditionValues[k] = *value + conditionValues[k] = aws.StringValue(value) } conditionMap["values"] = conditionValues conditions[i] = conditionMap @@ -280,7 +281,7 @@ func resourceAwsLbListenerRuleUpdate(d *schema.ResourceData, meta interface{}) e if requestUpdate { resp, err := elbconn.ModifyRule(params) if err != nil { - return errwrap.Wrapf("Error modifying LB Listener Rule: {{err}}", err) + return fmt.Errorf("Error modifying LB Listener Rule: %s", err) } if len(resp.Rules) == 0 { @@ -299,8 +300,8 @@ func resourceAwsLbListenerRuleDelete(d *schema.ResourceData, meta interface{}) e _, err := elbconn.DeleteRule(&elbv2.DeleteRuleInput{ RuleArn: aws.String(d.Id()), }) - if err != nil && !isRuleNotFound(err) { - return errwrap.Wrapf("Error deleting LB Listener Rule: {{err}}", err) + if err != nil && !isAWSErr(err, elbv2.ErrCodeRuleNotFoundException, "") { + return fmt.Errorf("Error deleting LB Listener Rule: %s", err) } return nil } @@ -329,11 +330,6 @@ func lbListenerARNFromRuleARN(ruleArn string) string { return "" } -func isRuleNotFound(err error) bool { - elberr, ok := err.(awserr.Error) - return ok && elberr.Code() == "RuleNotFound" -} - func highestListenerRulePriority(conn *elbv2.ELBV2, arn string) (priority int64, err error) { var priorities []int var nextMarker *string @@ -348,8 +344,8 @@ func highestListenerRulePriority(conn *elbv2.ELBV2, arn string) (priority int64, return } for _, rule := range out.Rules { - if *rule.Priority != "default" { - p, _ := strconv.Atoi(*rule.Priority) + if aws.StringValue(rule.Priority) != "default" { + p, _ := strconv.Atoi(aws.StringValue(rule.Priority)) priorities = append(priorities, p) } } diff --git a/aws/resource_aws_lb_listener_rule_test.go b/aws/resource_aws_lb_listener_rule_test.go index 4f4471d448e..c4a46fb7e47 100644 --- a/aws/resource_aws_lb_listener_rule_test.go +++ b/aws/resource_aws_lb_listener_rule_test.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -326,10 +325,10 @@ func testAccCheckAWSLBListenerRuleDestroy(s *terraform.State) error { } // Verify the error - if isRuleNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeRuleNotFoundException, "") { return nil } else { - return errwrap.Wrapf("Unexpected error checking LB Listener Rule destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking LB Listener Rule destroyed: %s", err) } } diff --git a/aws/resource_aws_lb_listener_test.go b/aws/resource_aws_lb_listener_test.go index 6c385733181..e39c1a8a3d0 100644 --- a/aws/resource_aws_lb_listener_test.go +++ b/aws/resource_aws_lb_listener_test.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -153,7 +152,7 @@ func testAccCheckAWSLBListenerDestroy(s *terraform.State) error { if isAWSErr(err, elbv2.ErrCodeListenerNotFoundException, "") { return nil } else { - return errwrap.Wrapf("Unexpected error checking LB Listener destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking LB Listener destroyed: %s", err) } } diff --git a/aws/resource_aws_lb_target_group.go b/aws/resource_aws_lb_target_group.go index a31d9ced68b..47798903d67 100644 --- a/aws/resource_aws_lb_target_group.go +++ b/aws/resource_aws_lb_target_group.go @@ -9,9 +9,7 @@ import ( "strings" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" @@ -65,10 +63,14 @@ func resourceAwsLbTargetGroup() *schema.Resource { }, "protocol": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateLbListenerProtocol(), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + elbv2.ProtocolEnumHttp, + elbv2.ProtocolEnumHttps, + elbv2.ProtocolEnumTcp, + }, true), }, "vpc_id": { @@ -167,7 +169,11 @@ func resourceAwsLbTargetGroup() *schema.Resource { StateFunc: func(v interface{}) string { return strings.ToUpper(v.(string)) }, - ValidateFunc: validateLbListenerProtocol(), + ValidateFunc: validation.StringInSlice([]string{ + elbv2.ProtocolEnumHttp, + elbv2.ProtocolEnumHttps, + elbv2.ProtocolEnumTcp, + }, true), }, "timeout": { @@ -255,15 +261,14 @@ func resourceAwsLbTargetGroupCreate(d *schema.ResourceData, meta interface{}) er resp, err := elbconn.CreateTargetGroup(params) if err != nil { - return errwrap.Wrapf("Error creating LB Target Group: {{err}}", err) + return fmt.Errorf("Error creating LB Target Group: %s", err) } if len(resp.TargetGroups) == 0 { return errors.New("Error creating LB Target Group: no groups returned in response") } - targetGroupArn := resp.TargetGroups[0].TargetGroupArn - d.SetId(*targetGroupArn) + d.SetId(aws.StringValue(resp.TargetGroups[0].TargetGroupArn)) return resourceAwsLbTargetGroupUpdate(d, meta) } @@ -275,12 +280,12 @@ func resourceAwsLbTargetGroupRead(d *schema.ResourceData, meta interface{}) erro TargetGroupArns: []*string{aws.String(d.Id())}, }) if err != nil { - if isTargetGroupNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") { log.Printf("[DEBUG] DescribeTargetGroups - removing %s from state", d.Id()) d.SetId("") return nil } - return errwrap.Wrapf("Error retrieving Target Group: {{err}}", err) + return fmt.Errorf("Error retrieving Target Group: %s", err) } if len(resp.TargetGroups) != 1 { @@ -294,7 +299,7 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er elbconn := meta.(*AWSClient).elbv2conn if err := setElbV2Tags(elbconn, d); err != nil { - return errwrap.Wrapf("Error Modifying Tags on LB Target Group: {{err}}", err) + return fmt.Errorf("Error Modifying Tags on LB Target Group: %s", err) } if d.HasChange("health_check") { @@ -333,7 +338,7 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er if params != nil { _, err := elbconn.ModifyTargetGroup(params) if err != nil { - return errwrap.Wrapf("Error modifying Target Group: {{err}}", err) + return fmt.Errorf("Error modifying Target Group: %s", err) } } } @@ -399,7 +404,7 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er _, err := elbconn.ModifyTargetGroupAttributes(params) if err != nil { - return errwrap.Wrapf("Error modifying Target Group Attributes: {{err}}", err) + return fmt.Errorf("Error modifying Target Group Attributes: %s", err) } } @@ -413,17 +418,12 @@ func resourceAwsLbTargetGroupDelete(d *schema.ResourceData, meta interface{}) er TargetGroupArn: aws.String(d.Id()), }) if err != nil { - return errwrap.Wrapf("Error deleting Target Group: {{err}}", err) + return fmt.Errorf("Error deleting Target Group: %s", err) } return nil } -func isTargetGroupNotFound(err error) bool { - elberr, ok := err.(awserr.Error) - return ok && elberr.Code() == "TargetGroupNotFound" -} - func validateAwsLbTargetGroupHealthCheckPath(v interface{}, k string) (ws []string, errors []error) { value := v.(string) if len(value) > 1024 { @@ -496,37 +496,37 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t d.Set("target_type", targetGroup.TargetType) healthCheck := make(map[string]interface{}) - healthCheck["interval"] = *targetGroup.HealthCheckIntervalSeconds - healthCheck["port"] = *targetGroup.HealthCheckPort - healthCheck["protocol"] = *targetGroup.HealthCheckProtocol - healthCheck["timeout"] = *targetGroup.HealthCheckTimeoutSeconds - healthCheck["healthy_threshold"] = *targetGroup.HealthyThresholdCount - healthCheck["unhealthy_threshold"] = *targetGroup.UnhealthyThresholdCount + healthCheck["interval"] = int(aws.Int64Value(targetGroup.HealthCheckIntervalSeconds)) + healthCheck["port"] = aws.StringValue(targetGroup.HealthCheckPort) + healthCheck["protocol"] = aws.StringValue(targetGroup.HealthCheckProtocol) + healthCheck["timeout"] = int(aws.Int64Value(targetGroup.HealthCheckTimeoutSeconds)) + healthCheck["healthy_threshold"] = int(aws.Int64Value(targetGroup.HealthyThresholdCount)) + healthCheck["unhealthy_threshold"] = int(aws.Int64Value(targetGroup.UnhealthyThresholdCount)) if targetGroup.HealthCheckPath != nil { - healthCheck["path"] = *targetGroup.HealthCheckPath + healthCheck["path"] = aws.StringValue(targetGroup.HealthCheckPath) } if targetGroup.Matcher != nil && targetGroup.Matcher.HttpCode != nil { - healthCheck["matcher"] = *targetGroup.Matcher.HttpCode + healthCheck["matcher"] = aws.StringValue(targetGroup.Matcher.HttpCode) } if err := d.Set("health_check", []interface{}{healthCheck}); err != nil { - log.Printf("[WARN] Error setting health check: %s", err) + return fmt.Errorf("error setting health_check: %s", err) } attrResp, err := elbconn.DescribeTargetGroupAttributes(&elbv2.DescribeTargetGroupAttributesInput{ TargetGroupArn: aws.String(d.Id()), }) if err != nil { - return errwrap.Wrapf("Error retrieving Target Group Attributes: {{err}}", err) + return fmt.Errorf("Error retrieving Target Group Attributes: %s", err) } for _, attr := range attrResp.Attributes { - switch *attr.Key { + switch aws.StringValue(attr.Key) { case "proxy_protocol_v2.enabled": - enabled, err := strconv.ParseBool(*attr.Value) + enabled, err := strconv.ParseBool(aws.StringValue(attr.Value)) if err != nil { - return fmt.Errorf("Error converting proxy_protocol_v2.enabled to bool: %s", *attr.Value) + return fmt.Errorf("Error converting proxy_protocol_v2.enabled to bool: %s", aws.StringValue(attr.Value)) } d.Set("proxy_protocol_v2", enabled) case "slow_start.duration_seconds": @@ -547,13 +547,13 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t // This is a workaround to support module design where the module needs to // support HTTP and TCP target groups. switch { - case *targetGroup.Protocol != "TCP": + case aws.StringValue(targetGroup.Protocol) != "TCP": if err = flattenAwsLbTargetGroupStickiness(d, attrResp.Attributes); err != nil { return err } - case *targetGroup.Protocol == "TCP" && len(d.Get("stickiness").([]interface{})) < 1: + case aws.StringValue(targetGroup.Protocol) == "TCP" && len(d.Get("stickiness").([]interface{})) < 1: if err = d.Set("stickiness", []interface{}{}); err != nil { - return err + return fmt.Errorf("error setting stickiness: %s", err) } } @@ -561,12 +561,12 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t ResourceArns: []*string{aws.String(d.Id())}, }) if err != nil { - return errwrap.Wrapf("Error retrieving Target Group Tags: {{err}}", err) + return fmt.Errorf("Error retrieving Target Group Tags: %s", err) } for _, t := range tagsResp.TagDescriptions { - if *t.ResourceArn == d.Id() { + if aws.StringValue(t.ResourceArn) == d.Id() { if err := d.Set("tags", tagsToMapELBv2(t.Tags)); err != nil { - return err + return fmt.Errorf("error setting tags: %s", err) } } } @@ -577,25 +577,25 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t func flattenAwsLbTargetGroupStickiness(d *schema.ResourceData, attributes []*elbv2.TargetGroupAttribute) error { stickinessMap := map[string]interface{}{} for _, attr := range attributes { - switch *attr.Key { + switch aws.StringValue(attr.Key) { case "stickiness.enabled": - enabled, err := strconv.ParseBool(*attr.Value) + enabled, err := strconv.ParseBool(aws.StringValue(attr.Value)) if err != nil { - return fmt.Errorf("Error converting stickiness.enabled to bool: %s", *attr.Value) + return fmt.Errorf("Error converting stickiness.enabled to bool: %s", aws.StringValue(attr.Value)) } stickinessMap["enabled"] = enabled case "stickiness.type": - stickinessMap["type"] = *attr.Value + stickinessMap["type"] = aws.StringValue(attr.Value) case "stickiness.lb_cookie.duration_seconds": - duration, err := strconv.Atoi(*attr.Value) + duration, err := strconv.Atoi(aws.StringValue(attr.Value)) if err != nil { - return fmt.Errorf("Error converting stickiness.lb_cookie.duration_seconds to int: %s", *attr.Value) + return fmt.Errorf("Error converting stickiness.lb_cookie.duration_seconds to int: %s", aws.StringValue(attr.Value)) } stickinessMap["cookie_duration"] = duration case "deregistration_delay.timeout_seconds": - timeout, err := strconv.Atoi(*attr.Value) + timeout, err := strconv.Atoi(aws.StringValue(attr.Value)) if err != nil { - return fmt.Errorf("Error converting deregistration_delay.timeout_seconds to int: %s", *attr.Value) + return fmt.Errorf("Error converting deregistration_delay.timeout_seconds to int: %s", aws.StringValue(attr.Value)) } d.Set("deregistration_delay", timeout) } diff --git a/aws/resource_aws_lb_target_group_attachment.go b/aws/resource_aws_lb_target_group_attachment.go index 525a7efdd25..d845a1d4020 100644 --- a/aws/resource_aws_lb_target_group_attachment.go +++ b/aws/resource_aws_lb_target_group_attachment.go @@ -5,9 +5,7 @@ import ( "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -71,7 +69,7 @@ func resourceAwsLbAttachmentCreate(d *schema.ResourceData, meta interface{}) err _, err := elbconn.RegisterTargets(params) if err != nil { - return errwrap.Wrapf("Error registering targets with target group: {{err}}", err) + return fmt.Errorf("Error registering targets with target group: %s", err) } d.SetId(resource.PrefixedUniqueId(fmt.Sprintf("%s-", d.Get("target_group_arn")))) @@ -100,8 +98,8 @@ func resourceAwsLbAttachmentDelete(d *schema.ResourceData, meta interface{}) err } _, err := elbconn.DeregisterTargets(params) - if err != nil && !isTargetGroupNotFound(err) { - return errwrap.Wrapf("Error deregistering Targets: {{err}}", err) + if err != nil && !isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") { + return fmt.Errorf("Error deregistering Targets: %s", err) } return nil @@ -129,17 +127,17 @@ func resourceAwsLbAttachmentRead(d *schema.ResourceData, meta interface{}) error Targets: []*elbv2.TargetDescription{target}, }) if err != nil { - if isTargetGroupNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") { log.Printf("[WARN] Target group does not exist, removing target attachment %s", d.Id()) d.SetId("") return nil } - if isInvalidTarget(err) { + if isAWSErr(err, elbv2.ErrCodeInvalidTargetException, "") { log.Printf("[WARN] Target does not exist, removing target attachment %s", d.Id()) d.SetId("") return nil } - return errwrap.Wrapf("Error reading Target Health: {{err}}", err) + return fmt.Errorf("Error reading Target Health: %s", err) } if len(resp.TargetHealthDescriptions) != 1 { @@ -150,8 +148,3 @@ func resourceAwsLbAttachmentRead(d *schema.ResourceData, meta interface{}) error return nil } - -func isInvalidTarget(err error) bool { - elberr, ok := err.(awserr.Error) - return ok && elberr.Code() == "InvalidTarget" -} diff --git a/aws/resource_aws_lb_target_group_attachment_test.go b/aws/resource_aws_lb_target_group_attachment_test.go index b6b0dc76b73..44fb76c86f1 100644 --- a/aws/resource_aws_lb_target_group_attachment_test.go +++ b/aws/resource_aws_lb_target_group_attachment_test.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -161,10 +160,10 @@ func testAccCheckAWSLBTargetGroupAttachmentDestroy(s *terraform.State) error { } // Verify the error - if isTargetGroupNotFound(err) || isInvalidTarget(err) { + if isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") || isAWSErr(err, elbv2.ErrCodeInvalidTargetException, "") { return nil } else { - return errwrap.Wrapf("Unexpected error checking LB destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking LB destroyed: %s", err) } } diff --git a/aws/resource_aws_lb_target_group_test.go b/aws/resource_aws_lb_target_group_test.go index 691b80078f3..19c8f05df3d 100644 --- a/aws/resource_aws_lb_target_group_test.go +++ b/aws/resource_aws_lb_target_group_test.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -949,10 +948,10 @@ func testAccCheckAWSLBTargetGroupDestroy(s *terraform.State) error { } // Verify the error - if isTargetGroupNotFound(err) { + if isAWSErr(err, elbv2.ErrCodeTargetGroupNotFoundException, "") { return nil } else { - return errwrap.Wrapf("Unexpected error checking ALB destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking ALB destroyed: %s", err) } } diff --git a/aws/resource_aws_lb_test.go b/aws/resource_aws_lb_test.go index a91c2eb6377..b93352d2e2e 100644 --- a/aws/resource_aws_lb_test.go +++ b/aws/resource_aws_lb_test.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -708,7 +707,7 @@ func TestAccAWSLB_networkLoadbalancer_subnet_change(t *testing.T) { func testAccCheckAWSlbARNs(pre, post *elbv2.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - if *pre.LoadBalancerArn != *post.LoadBalancerArn { + if aws.StringValue(pre.LoadBalancerArn) != aws.StringValue(post.LoadBalancerArn) { return errors.New("LB has been recreated. ARNs are different") } @@ -738,7 +737,7 @@ func testAccCheckAWSLBExists(n string, res *elbv2.LoadBalancer) resource.TestChe } if len(describe.LoadBalancers) != 1 || - *describe.LoadBalancers[0].LoadBalancerArn != rs.Primary.ID { + aws.StringValue(describe.LoadBalancers[0].LoadBalancerArn) != rs.Primary.ID { return errors.New("LB not found") } @@ -763,16 +762,15 @@ func testAccCheckAWSLBAttribute(n, key, value string) resource.TestCheckFunc { LoadBalancerArn: aws.String(rs.Primary.ID), }) if err != nil { - return errwrap.Wrapf("Error retrieving LB Attributes: {{err}}", err) + return fmt.Errorf("Error retrieving LB Attributes: %s", err) } for _, attr := range attributesResp.Attributes { - if *attr.Key == key { - if *attr.Value == value { + if aws.StringValue(attr.Key) == key { + if aws.StringValue(attr.Value) == value { return nil - } else { - return fmt.Errorf("LB attribute %s expected: %q actual: %q", key, value, *attr.Value) } + return fmt.Errorf("LB attribute %s expected: %q actual: %q", key, value, aws.StringValue(attr.Value)) } } return fmt.Errorf("LB attribute %s does not exist on LB: %s", key, rs.Primary.ID) @@ -793,7 +791,7 @@ func testAccCheckAWSLBDestroy(s *terraform.State) error { if err == nil { if len(describe.LoadBalancers) != 0 && - *describe.LoadBalancers[0].LoadBalancerArn == rs.Primary.ID { + aws.StringValue(describe.LoadBalancers[0].LoadBalancerArn) == rs.Primary.ID { return fmt.Errorf("LB %q still exists", rs.Primary.ID) } } @@ -802,7 +800,7 @@ func testAccCheckAWSLBDestroy(s *terraform.State) error { if isLoadBalancerNotFound(err) { return nil } else { - return errwrap.Wrapf("Unexpected error checking LB destroyed: {{err}}", err) + return fmt.Errorf("Unexpected error checking LB destroyed: %s", err) } } From cd39d3bfe26e08b0f23a8c1db6d7bc1179f40dfc Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 27 Jul 2018 10:31:21 -0400 Subject: [PATCH 2/2] resource/aws_lb_listener_rule: Ensure priority conversion error includes priority Fixes: aws/resource_aws_lb_listener_rule.go:190: missing argument for Errorf("%s"): format reads arg 2, have only 1 args --- aws/resource_aws_lb_listener_rule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_lb_listener_rule.go b/aws/resource_aws_lb_listener_rule.go index 9ae34b825a7..e3352ba880f 100644 --- a/aws/resource_aws_lb_listener_rule.go +++ b/aws/resource_aws_lb_listener_rule.go @@ -187,7 +187,7 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err d.Set("priority", 99999) } else { if priority, err := strconv.Atoi(aws.StringValue(rule.Priority)); err != nil { - return fmt.Errorf("Cannot convert rule priority %q to int: %s", err) + return fmt.Errorf("Cannot convert rule priority %q to int: %s", aws.StringValue(rule.Priority), err) } else { d.Set("priority", priority) }