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

resource/aws_appautoscaling_policy: Match correct policy when multiple policies with same name #3012

Merged
merged 3 commits into from
Jan 17, 2018
Merged
Changes from 2 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
18 changes: 7 additions & 11 deletions aws/resource_aws_appautoscaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,26 +567,22 @@ func getAwsAppautoscalingPolicy(d *schema.ResourceData, meta interface{}) (*appl
conn := meta.(*AWSClient).appautoscalingconn

params := applicationautoscaling.DescribeScalingPoliciesInput{
PolicyNames: []*string{aws.String(d.Get("name").(string))},
ServiceNamespace: aws.String(d.Get("service_namespace").(string)),
PolicyNames: []*string{aws.String(d.Get("name").(string))},
ResourceId: aws.String(d.Get("resource_id").(string)),
ScalableDimension: aws.String(d.Get("scalable_dimension").(string)),
ServiceNamespace: aws.String(d.Get("service_namespace").(string)),
}

log.Printf("[DEBUG] Application AutoScaling Policy Describe Params: %#v", params)
resp, err := conn.DescribeScalingPolicies(&params)
if err != nil {
return nil, fmt.Errorf("Error retrieving scaling policies: %s", err)
}

// find scaling policy
name := d.Get("name").(string)
dimension := d.Get("scalable_dimension").(string)
for idx, sp := range resp.ScalingPolicies {
if *sp.PolicyName == name && *sp.ScalableDimension == dimension {
return resp.ScalingPolicies[idx], nil
}
if len(resp.ScalingPolicies) == 0 {
return nil, nil
}

return nil, nil
return resp.ScalingPolicies[0], nil
}

func expandStepScalingPolicyConfiguration(cfg []interface{}) *applicationautoscaling.StepScalingPolicyConfiguration {
Expand Down