-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/user_pool_domain - remove from state when deleted + move waiters to their own package #14732
Merged
bflad
merged 4 commits into
hashicorp:master
from
DrFaust92:r/user_pool_domain_disappears
Aug 19, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
aws/internal/service/cognitoidentityprovider/waiter/status.go
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,33 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
userPoolDomainStatusNotFound = "NotFound" | ||
userPoolDomainStatusUnknown = "Unknown" | ||
) | ||
|
||
// UserPoolDomainStatus fetches the Operation and its Status | ||
func UserPoolDomainStatus(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
input := &cognitoidentityprovider.DescribeUserPoolDomainInput{ | ||
Domain: aws.String(domain), | ||
} | ||
|
||
output, err := conn.DescribeUserPoolDomain(input) | ||
|
||
if err != nil { | ||
return nil, userPoolDomainStatusUnknown, err | ||
} | ||
|
||
if output == nil { | ||
return nil, userPoolDomainStatusNotFound, nil | ||
} | ||
|
||
return output, aws.StringValue(output.DomainDescription.Status), nil | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
aws/internal/service/cognitoidentityprovider/waiter/waiter.go
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,56 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
// Maximum amount of time to wait for an Operation to return Success | ||
UserPoolDomainDeleteTimeout = 1 * time.Minute | ||
) | ||
|
||
// UserPoolDomainDeleted waits for an Operation to return Success | ||
func UserPoolDomainDeleted(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string) (*cognitoidentityprovider.DescribeUserPoolDomainOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
cognitoidentityprovider.DomainStatusTypeUpdating, | ||
cognitoidentityprovider.DomainStatusTypeDeleting, | ||
}, | ||
Target: []string{""}, | ||
Refresh: UserPoolDomainStatus(conn, domain), | ||
Timeout: UserPoolDomainDeleteTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*cognitoidentityprovider.DescribeUserPoolDomainOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func UserPoolDomainCreated(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string, timeout time.Duration) (*cognitoidentityprovider.DescribeUserPoolDomainOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
cognitoidentityprovider.DomainStatusTypeCreating, | ||
cognitoidentityprovider.DomainStatusTypeUpdating, | ||
}, | ||
Target: []string{ | ||
cognitoidentityprovider.DomainStatusTypeActive, | ||
}, | ||
Refresh: UserPoolDomainStatus(conn, domain), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*cognitoidentityprovider.DescribeUserPoolDomainOutput); 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "correct" way to do this is
Target: []string{},
:https://github.com/terraform-providers/terraform-provider-aws/blob/691d0645ceed9453a8fc77a88e7fb0fce29b1ad3/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/state.go#L122-L131
This code runs when the
StateRefreshFunc
returnsnil, "anything", nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this failed for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess the AWS API may be returning a non-null response but the status is
""
.Target: []string{""},
must be required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what's happening here: