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
This commit is contained in:
Jake Champlin 2017-01-27 14:55:34 -05:00
parent 0cd69d2101
commit 8b66d137d1
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
1 changed files with 8 additions and 3 deletions

View File

@ -144,10 +144,15 @@ func resourceAwsAlbListenerRuleRead(d *schema.ResourceData, meta interface{}) er
rule := resp.Rules[0] rule := resp.Rules[0]
d.Set("arn", rule.RuleArn) d.Set("arn", rule.RuleArn)
if priority, err := strconv.Atoi(*rule.Priority); err != nil { // Rules are evaluated in priority order, from the lowest value to the highest value. The default rule has the lowest priority.
return errwrap.Wrapf("Cannot convert rule priority %q to int: {{err}}", err) if *rule.Priority == "default" {
d.Set("priority", 99999)
} else { } 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)) actions := make([]interface{}, len(rule.Actions))