From 853a95eb5d814667bd0478f242d812cfa8a7d604 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 26 Feb 2016 13:23:26 +0000 Subject: [PATCH] wip - consistency workarounds --- builtin/providers/aws/resource_aws_kms_key.go | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/builtin/providers/aws/resource_aws_kms_key.go b/builtin/providers/aws/resource_aws_kms_key.go index 04faff1a0ef5..e36552b95c68 100644 --- a/builtin/providers/aws/resource_aws_kms_key.go +++ b/builtin/providers/aws/resource_aws_kms_key.go @@ -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) @@ -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 { @@ -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) @@ -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 {