Skip to content

Commit

Permalink
Coveo parameter hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Jul 18, 2018
1 parent 882d416 commit 162d514
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,25 @@ func resourceAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error
d.Set("type", param.Type)
d.Set("value", param.Value)

describeParamsInput := &ssm.DescribeParametersInput{
Filters: []*ssm.ParametersFilter{
&ssm.ParametersFilter{
Key: aws.String("Name"),
Values: []*string{aws.String(d.Get("name").(string))},
},
},
MaxResults: aws.Int64(50),
}
detailedParameters := []*ssm.ParameterMetadata{}
err = ssmconn.DescribeParametersPages(describeParamsInput,
func(page *ssm.DescribeParametersOutput, lastPage bool) bool {
detailedParameters = append(detailedParameters, page.Parameters...)
return !lastPage
})
// COVEO HACK: This is to prevent from using the DescribeParameters call. It is very heavy
// remove when we are less reliant on SSM
err = ssmconn.GetParameterHistoryPages(&ssm.GetParameterHistoryInput{
Name: aws.String(d.Id()),
WithDecryption: aws.Bool(false),
MaxResults: aws.Int64(50),
}, func(page *ssm.GetParameterHistoryOutput, lastPage bool) bool {
if lastPage {
param := page.Parameters[len(page.Parameters)-1]
d.Set("key_id", param.KeyId)
d.Set("description", param.Description)
d.Set("allowed_pattern", param.AllowedPattern)
}
return !lastPage
})
if err != nil {
return fmt.Errorf("error describing SSM parameter: %s", err)
}
if len(detailedParameters) == 0 {
log.Printf("[WARN] SSM Param %q not found, removing from state", d.Id())
d.SetId("")
return nil
return fmt.Errorf("error getting SSM parameter: %s", err)
}

detail := detailedParameters[0]
d.Set("key_id", detail.KeyId)
d.Set("description", detail.Description)
d.Set("allowed_pattern", detail.AllowedPattern)

if tagList, err := ssmconn.ListTagsForResource(&ssm.ListTagsForResourceInput{
ResourceId: aws.String(d.Get("name").(string)),
ResourceType: aws.String("Parameter"),
Expand Down

0 comments on commit 162d514

Please sign in to comment.