Skip to content

Commit

Permalink
provider/aws: Change AWS ssm_maintenance_window Read func
Browse files Browse the repository at this point in the history
Fixes: #14653

I was originally calling the wrong API method and only some of the
values were being persisted to state. By changing the API method, we can
now get all of the values and therefore can detech manual drift

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSSMMaintenanceWindow_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/05/19 16:56:27 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSSMMaintenanceWindow_ -timeout 120m
=== RUN   TestAccAWSSSMMaintenanceWindow_basic
--- PASS: TestAccAWSSSMMaintenanceWindow_basic (41.39s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	41.419s
```
  • Loading branch information
stack72 committed May 19, 2017
1 parent d9fb2cf commit 93a15cc
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions builtin/providers/aws/resource_aws_ssm_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func resourceAwsSsmMaintenanceWindowCreate(d *schema.ResourceData, meta interfac

d.SetId(*resp.WindowId)

//need to set the schedule to state as it isn't actually available via the API
d.Set("schedule", d.Get("schedule").(string))

return resourceAwsSsmMaintenanceWindowRead(d, meta)
}

Expand Down Expand Up @@ -108,44 +111,30 @@ func resourceAwsSsmMaintenanceWindowUpdate(d *schema.ResourceData, meta interfac
return err
}

//need to set the schedule to state as it isn't actually available via the API
d.Set("schedule", d.Get("schedule").(string))

return resourceAwsSsmMaintenanceWindowRead(d, meta)
}

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

params := &ssm.DescribeMaintenanceWindowsInput{
Filters: []*ssm.MaintenanceWindowFilter{
{
Key: aws.String("Name"),
Values: []*string{aws.String(d.Get("name").(string))},
},
},
params := &ssm.GetMaintenanceWindowInput{
WindowId: aws.String(d.Id()),
}

resp, err := ssmconn.DescribeMaintenanceWindows(params)
resp, err := ssmconn.GetMaintenanceWindow(params)
if err != nil {
return err
}

found := false

for _, window := range resp.WindowIdentities {
if *window.WindowId == d.Id() {
found = true

d.Set("name", window.Name)
d.Set("cutoff", window.Cutoff)
d.Set("duration", window.Duration)
d.Set("enabled", window.Enabled)
}
}

if !found {
log.Printf("[INFO] Cannot find the SSM Maintenance Window %q. Removing from state", d.Get("name").(string))
d.SetId("")
return nil
}
d.Set("name", resp.Name)
d.Set("cutoff", resp.Cutoff)
d.Set("duration", resp.Duration)
d.Set("enabled", resp.Enabled)
d.Set("allow_unassociated_targets", resp.AllowUnassociatedTargets)
d.Set("schedule", resp.Schedule)

return nil
}
Expand Down

0 comments on commit 93a15cc

Please sign in to comment.