From 3bcb97bd4e212914cd24bef3dd4d210d63215918 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 | 32 +++++++++++++------ 1 file changed, 22 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..5b0388c957b1 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: 2 * 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,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 { @@ -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) @@ -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 {