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 3bcb97b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 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: 2 * 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,18 @@ 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
if err != nil {
return fmt.Errorf("Failed setting KMS key status to %t: %s", shouldBeEnabled, err)
}

return nil
}

func updateKmsKeyRotationStatus(conn *kms.KMS, d *schema.ResourceData) error {
Expand All @@ -286,10 +292,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: 2 * 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 +307,18 @@ 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
if err != nil {
return fmt.Errorf("Failed setting KMS key rotation status to %t: %s", shouldEnableRotation, err)
}

return nil
}

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

0 comments on commit 3bcb97b

Please sign in to comment.