Skip to content

Commit

Permalink
wip - consistency workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Simko committed Feb 26, 2016
1 parent 0bb7f78 commit 853a95e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions builtin/providers/aws/resource_aws_kms_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ func updateKmsKeyStatus(conn *kms.KMS, id string, shouldBeEnabled bool) error {

// Wait for propagation since KMS is eventually consistent
wait := resource.StateChangeConf{
Pending: []string{fmt.Sprintf("%t", !shouldBeEnabled)},
Target: []string{fmt.Sprintf("%t", shouldBeEnabled)},
Timeout: 5 * time.Minute,
MinTimeout: 60 * time.Second,
Pending: []string{fmt.Sprintf("%t", !shouldBeEnabled)},
Target: []string{fmt.Sprintf("%t", shouldBeEnabled)},
Timeout: 5 * time.Minute,
MinTimeout: 60 * time.Second,
ContinuousTargetOccurence: 10,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if KMS key %s enabled status is %t",
id, shouldBeEnabled)
Expand All @@ -255,13 +256,14 @@ func updateKmsKeyStatus(conn *kms.KMS, id string, shouldBeEnabled bool) error {
return resp, "FAILED", err
}
status := fmt.Sprintf("%t", *resp.KeyMetadata.Enabled)
log.Printf("[DEBUG] KMS key %s status received: %s, retrying", id, status)

return resp, status, nil
},
}

_, err = wait.WaitForState()
return err
return fmt.Errorf("Failed setting KMS key status to %t: %s", shouldBeEnabled, err)
}

func updateKmsKeyRotationStatus(conn *kms.KMS, d *schema.ResourceData) error {
Expand All @@ -286,10 +288,11 @@ func updateKmsKeyRotationStatus(conn *kms.KMS, d *schema.ResourceData) error {

// Wait for propagation since KMS is eventually consistent
wait := resource.StateChangeConf{
Pending: []string{fmt.Sprintf("%t", !shouldEnableRotation)},
Target: []string{fmt.Sprintf("%t", shouldEnableRotation)},
Timeout: 5 * time.Minute,
MinTimeout: 60 * time.Second,
Pending: []string{fmt.Sprintf("%t", !shouldEnableRotation)},
Target: []string{fmt.Sprintf("%t", shouldEnableRotation)},
Timeout: 5 * time.Minute,
MinTimeout: 60 * time.Second,
ContinuousTargetOccurence: 10,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if KMS key %s rotation status is %t",
d.Id(), shouldEnableRotation)
Expand All @@ -300,13 +303,14 @@ func updateKmsKeyRotationStatus(conn *kms.KMS, d *schema.ResourceData) error {
return resp, "FAILED", err
}
status := fmt.Sprintf("%t", *resp.KeyRotationEnabled)
log.Printf("[DEBUG] KMS key %s rotation status received: %s, retrying", d.Id(), status)

return resp, status, nil
},
}

_, err = wait.WaitForState()
return err
return fmt.Errorf("Failed setting KMS key rotation status to %t: %s", shouldEnableRotation, err)
}

func resourceAwsKmsKeyDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down

0 comments on commit 853a95e

Please sign in to comment.