-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider: Introduce shared IAM propagation timeout, refactor KMS Key …
…creation to that timeout and add KMS Key deletion to internal waiter package Reference: #7646 Reference: #12840 The Terraform AWS Provider codebase contains many varied timeouts for handling IAM propagation retries. Here we introduce a shared constant for this amount of time. The choice of 2 minutes is based on that amount of time being: - Most widely used across resources - Based on lack of historical bug reports across those resources that implement that amount of time, most successful - Ensuring a reasonable user experience (not waiting too long) should there be an actual misconfiguration As an initial implementation of this IAM propagation timeout and further showing the potential waiter package refactoring, this fixes shorter IAM timeout implementations in the `aws_kms_key` and `aws_kms_external_key` resources, while also refactoring the pending deletion logic. This second change is designed as an inflection point for how we want to handle imports across multiple waiter packages, with the preference of this initial implementation to name the Go import of the outside service, `iamwaiter`, or generically SERVICEwaiter. If agreed, this will be added to the proposal and the refactoring documentation. NOTE: There is other `StateChangeConf` / `StateRefreshFunc` logic in these KMS resources, but this change is solely focused on highlighting the multiple import situation, and those will be handled later. Output from acceptance testing: ``` --- PASS: TestAccAWSKmsExternalKey_basic (19.53s) --- PASS: TestAccAWSKmsExternalKey_DeletionWindowInDays (31.61s) --- PASS: TestAccAWSKmsExternalKey_Description (32.11s) --- PASS: TestAccAWSKmsExternalKey_disappears (13.84s) --- PASS: TestAccAWSKmsExternalKey_Enabled (312.55s) --- PASS: TestAccAWSKmsExternalKey_KeyMaterialBase64 (104.29s) --- PASS: TestAccAWSKmsExternalKey_Policy (33.78s) --- PASS: TestAccAWSKmsExternalKey_Tags (43.70s) --- PASS: TestAccAWSKmsExternalKey_ValidTo (165.77s) --- PASS: TestAccAWSKmsKey_asymmetricKey (18.20s) --- PASS: TestAccAWSKmsKey_basic (21.13s) --- PASS: TestAccAWSKmsKey_disappears (13.92s) --- PASS: TestAccAWSKmsKey_isEnabled (236.91s) --- PASS: TestAccAWSKmsKey_policy (35.34s) --- PASS: TestAccAWSKmsKey_Policy_IamRole (34.14s) --- PASS: TestAccAWSKmsKey_Policy_IamServiceLinkedRole (44.80s) --- PASS: TestAccAWSKmsKey_tags (34.65s) ```
- Loading branch information
Showing
7 changed files
with
264 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
const ( | ||
// Maximum amount of time to wait for IAM changes to propagate | ||
// This timeout should not be increased without strong consideration | ||
// as this will negatively impact user experience when configurations | ||
// have incorrect references or permissions. | ||
// Reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_eventual-consistency | ||
PropagationTimeout = 2 * time.Minute | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/kms" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
// KeyState fetches the Key and its State | ||
func KeyState(conn *kms.KMS, keyID string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
input := &kms.DescribeKeyInput{ | ||
KeyId: aws.String(keyID), | ||
} | ||
|
||
output, err := conn.DescribeKey(input) | ||
|
||
if err != nil { | ||
return nil, kms.KeyStateUnavailable, err | ||
} | ||
|
||
if output == nil || output.KeyMetadata == nil { | ||
return output, kms.KeyStateUnavailable, nil | ||
} | ||
|
||
return output, aws.StringValue(output.KeyMetadata.KeyState), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/kms" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
const ( | ||
// Maximum amount of time to wait for KeyState to return PendingDeletion | ||
KeyStatePendingDeletionTimeout = 20 * time.Minute | ||
) | ||
|
||
// KeyStatePendingDeletion waits for KeyState to return PendingDeletion | ||
func KeyStatePendingDeletion(conn *kms.KMS, keyID string) (*kms.DescribeKeyOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
kms.KeyStateDisabled, | ||
kms.KeyStateEnabled, | ||
}, | ||
Target: []string{kms.KeyStatePendingDeletion}, | ||
Refresh: KeyState(conn, keyID), | ||
Timeout: KeyStatePendingDeletionTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*kms.DescribeKeyOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.