From 8b66d137d1c17564c391c2dc6a6d1ce3e7b0d7ae Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Fri, 27 Jan 2017 14:55:34 -0500 Subject: [PATCH] provider/aws: Import aws_alb_listener_rule fix Allows the user to import a default aws_alb_listener_rule. When creating the resource with TF, the AWS API requires that `priority` be an integer. However, the `DescribeRules` API call returns a string for `priority`. This would work in every case except for the `default` listener rule, which sets the `priority` value to the string "default". This fixes the previous error: ``` Error importing: 1 error(s) occurred: * aws_alb_listener_rule.test: Cannot convert rule priority %q to int: strconv.ParseInt: parsing "default": invalid syntax ``` Fixes: #11464 --- .../providers/aws/resource_aws_alb_listener_rule.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_alb_listener_rule.go b/builtin/providers/aws/resource_aws_alb_listener_rule.go index f1dc944b5..1d5ba163f 100644 --- a/builtin/providers/aws/resource_aws_alb_listener_rule.go +++ b/builtin/providers/aws/resource_aws_alb_listener_rule.go @@ -144,10 +144,15 @@ func resourceAwsAlbListenerRuleRead(d *schema.ResourceData, meta interface{}) er rule := resp.Rules[0] d.Set("arn", rule.RuleArn) - if priority, err := strconv.Atoi(*rule.Priority); err != nil { - return errwrap.Wrapf("Cannot convert rule priority %q to int: {{err}}", err) + // 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" { + d.Set("priority", 99999) } else { - d.Set("priority", priority) + if priority, err := strconv.Atoi(*rule.Priority); err != nil { + return errwrap.Wrapf("Cannot convert rule priority %q to int: {{err}}", err) + } else { + d.Set("priority", priority) + } } actions := make([]interface{}, len(rule.Actions))