-
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/mwaa_environment - new resource #16616
Changes from 15 commits
3732bdc
19ab800
60ca28b
0217432
bb92fe1
05aaf6e
b7d75ad
a26f8dc
1e0ac6a
ed8adb9
4250e2b
02c098b
dc37143
456e595
8110889
d6074e9
dfbfb5d
24c1092
68d70a7
43ab58a
34831ee
84825bc
4c2cb35
7902e1e
07d84e9
fde9ee0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package finder | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/mwaa" | ||
) | ||
|
||
// EnvironmentByName returns the MWAA Environment corresponding to the specified Name. | ||
// Returns nil if no environment is found. | ||
func EnvironmentByName(conn *mwaa.MWAA, name string) (*mwaa.Environment, error) { | ||
input := &mwaa.GetEnvironmentInput{ | ||
Name: aws.String(name), | ||
} | ||
|
||
output, err := conn.GetEnvironment(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil { | ||
return nil, nil | ||
} | ||
|
||
return output.Environment, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/mwaa" | ||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/mwaa/finder" | ||
) | ||
|
||
const ( | ||
environmentStatusNotFound = "NotFound" | ||
environmentStatusUnknown = "Unknown" | ||
) | ||
|
||
// EnvironmentStatus fetches the Environment and its Status | ||
func EnvironmentStatus(conn *mwaa.MWAA, name string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
environment, err := finder.EnvironmentByName(conn, name) | ||
|
||
if tfawserr.ErrCodeEquals(err, mwaa.ErrCodeResourceNotFoundException) { | ||
return nil, environmentStatusNotFound, nil | ||
} | ||
|
||
if err != nil { | ||
return nil, environmentStatusUnknown, err | ||
} | ||
|
||
if environment == nil { | ||
return nil, environmentStatusNotFound, nil | ||
} | ||
|
||
return environment, aws.StringValue(environment.Status), nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/mwaa" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
// Maximum amount of time to wait for an environment creation | ||
EnvironmentCreatedTimeout = 90 * time.Minute | ||
// Amount of delay to check an environment status | ||
EnvironmentCreatedDelay = 1 * time.Minute | ||
|
||
// Maximum amount of time to wait for an environment update | ||
EnvironmentUpdatedTimeout = 90 * time.Minute | ||
// Amount of delay to check an environment status | ||
EnvironmentUpdatedDelay = 1 * time.Minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open question: Can we lower this mandatory 1 minute delay to 15 seconds (or remove it altogether)? |
||
|
||
// Maximum amount of time to wait for an environment deletion | ||
EnvironmentDeletedTimeout = 90 * time.Minute | ||
// Amount of delay to check an environment status | ||
EnvironmentDeletedDelay = 1 * time.Minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar question here. 👍 |
||
) | ||
|
||
// EnvironmentCreated waits for a Environment to return AVAILABLE | ||
func EnvironmentCreated(conn *mwaa.MWAA, name string) (*mwaa.Environment, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{mwaa.EnvironmentStatusCreating}, | ||
Target: []string{mwaa.EnvironmentStatusAvailable}, | ||
Refresh: EnvironmentStatus(conn, name), | ||
Timeout: EnvironmentCreatedTimeout, | ||
Delay: EnvironmentCreatedDelay, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if v, ok := outputRaw.(*mwaa.Environment); ok { | ||
return v, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
// EnvironmentUpdated waits for a Environment to return AVAILABLE | ||
func EnvironmentUpdated(conn *mwaa.MWAA, name string) (*mwaa.Environment, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{mwaa.EnvironmentStatusUpdating}, | ||
Target: []string{mwaa.EnvironmentStatusAvailable}, | ||
Refresh: EnvironmentStatus(conn, name), | ||
Timeout: EnvironmentUpdatedTimeout, | ||
Delay: EnvironmentUpdatedDelay, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if v, ok := outputRaw.(*mwaa.Environment); ok { | ||
return v, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
// EnvironmentDeleted waits for a Environment to be deleted | ||
func EnvironmentDeleted(conn *mwaa.MWAA, name string) (*mwaa.Environment, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{mwaa.EnvironmentStatusDeleting}, | ||
Target: []string{}, | ||
Refresh: EnvironmentStatus(conn, name), | ||
Timeout: EnvironmentDeletedTimeout, | ||
Delay: EnvironmentDeletedDelay, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if v, ok := outputRaw.(*mwaa.Environment); ok { | ||
return v, err | ||
} | ||
|
||
return nil, err | ||
} |
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.
Open question: Is it possible to forego this mandatory 1 minute delay on creation? The waiter will automatically handle a
nil
response from the refresh function as a retryable condition. 👍