Skip to content

Commit

Permalink
Support updates for aws_ssm_association & aws_ssm_patch_baseline reso…
Browse files Browse the repository at this point in the history
…urces (#1421)

* Update SSM Association Schedule Expression

* Update SSM Association Output Location

* Add support for SSM Association Document Version

* Add acceptance test for AWS SSM Assocation with Parameters

* Add support for SSM Association Parameter Updates

* Add support for ssm_patch_baseline resource updates
  • Loading branch information
stack72 authored and catsby committed Aug 16, 2017
1 parent a141e50 commit 5558396
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 14 deletions.
47 changes: 44 additions & 3 deletions aws/resource_aws_ssm_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func resourceAwsSsmAssociation() *schema.Resource {
return &schema.Resource{
Create: resourceAwsSsmAssociationCreate,
Read: resourceAwsSsmAssociationRead,
Update: resourceAwsSsmAssocationUpdate,
Delete: resourceAwsSsmAssociationDelete,

Schema: map[string]*schema.Schema{
Expand All @@ -26,6 +27,11 @@ func resourceAwsSsmAssociation() *schema.Resource {
ForceNew: true,
Optional: true,
},
"document_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
ForceNew: true,
Expand All @@ -34,19 +40,16 @@ func resourceAwsSsmAssociation() *schema.Resource {
"parameters": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Computed: true,
},
"schedule_expression": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"output_location": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_bucket_name": {
Expand Down Expand Up @@ -97,6 +100,10 @@ func resourceAwsSsmAssociationCreate(d *schema.ResourceData, meta interface{}) e
assosciationInput.InstanceId = aws.String(v.(string))
}

if v, ok := d.GetOk("document_version"); ok {
assosciationInput.DocumentVersion = aws.String(v.(string))
}

if v, ok := d.GetOk("schedule_expression"); ok {
assosciationInput.ScheduleExpression = aws.String(v.(string))
}
Expand Down Expand Up @@ -152,6 +159,7 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err
d.Set("parameters", association.Parameters)
d.Set("association_id", association.AssociationId)
d.Set("schedule_expression", association.ScheduleExpression)
d.Set("document_version", association.DocumentVersion)

if err := d.Set("targets", flattenAwsSsmTargets(association.Targets)); err != nil {
return fmt.Errorf("[DEBUG] Error setting targets error: %#v", err)
Expand All @@ -164,6 +172,39 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err
return nil
}

func resourceAwsSsmAssocationUpdate(d *schema.ResourceData, meta interface{}) error {
ssmconn := meta.(*AWSClient).ssmconn

log.Printf("[DEBUG] SSM association update: %s", d.Id())

associationInput := &ssm.UpdateAssociationInput{
AssociationId: aws.String(d.Get("association_id").(string)),
}

if d.HasChange("schedule_expression") {
associationInput.ScheduleExpression = aws.String(d.Get("schedule_expression").(string))
}

if d.HasChange("document_version") {
associationInput.DocumentVersion = aws.String(d.Get("document_version").(string))
}

if d.HasChange("parameters") {
associationInput.Parameters = expandSSMDocumentParameters(d.Get("parameters").(map[string]interface{}))
}

if d.HasChange("output_location") {
associationInput.OutputLocation = expandSSMAssociationOutputLocation(d.Get("output_location").([]interface{}))
}

_, err := ssmconn.UpdateAssociation(associationInput)
if err != nil {
return errwrap.Wrapf("[ERROR] Error updating SSM association: {{err}}", err)
}

return resourceAwsSsmAssociationRead(d, meta)
}

func resourceAwsSsmAssociationDelete(d *schema.ResourceData, meta interface{}) error {
ssmconn := meta.(*AWSClient).ssmconn

Expand Down
Loading

0 comments on commit 5558396

Please sign in to comment.