Skip to content
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

Merged
merged 26 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3732bdc
Add mwaa_environment
shuheiktgw Dec 18, 2020
19ab800
Add tests for mwaa_environment
shuheiktgw Dec 18, 2020
60ca28b
Add a documentation for mwaa_environment
shuheiktgw Dec 18, 2020
0217432
Use aws.StringValue instead
shuheiktgw Dec 18, 2020
bb92fe1
Use values functions instead for mwaa_environment
shuheiktgw Jan 16, 2021
05aaf6e
Move tags attribute up to keep alphabetical ordering for mwaa_environ…
shuheiktgw Jan 16, 2021
b7d75ad
Remove unnecessary arn set from mwaa_environment read function
shuheiktgw Jan 16, 2021
a26f8dc
Wrap error messages with context for mwaa_environment
shuheiktgw Jan 16, 2021
1e0ac6a
Use HasChangesExcept instead of HasChange for meaa_environment
shuheiktgw Jan 16, 2021
ed8adb9
Split the waiters into separate packages for meaa_environment
shuheiktgw Jan 16, 2021
4250e2b
Remove an airflow prefix from meaa_environment test S3 bucket names
shuheiktgw Jan 16, 2021
02c098b
Format files
shuheiktgw Jan 16, 2021
dc37143
Fix EnvironmentDeleted waiter target statuses
shuheiktgw Jan 16, 2021
456e595
Improve mwaa_environment error messages
shuheiktgw Jan 17, 2021
8110889
Add back HasChange to check mwaa_environment updates
shuheiktgw Jan 18, 2021
d6074e9
Remove the delay on creation
shuheiktgw Apr 3, 2021
dfbfb5d
Remove the delay on update and deletion too
shuheiktgw Apr 3, 2021
24c1092
Update the markdown format from hcl to terraform
shuheiktgw Apr 3, 2021
68d70a7
Update the documentation on the security_group_ids arguments
shuheiktgw Apr 3, 2021
43ab58a
Add validation to execution_role_arn
shuheiktgw Apr 3, 2021
34831ee
Merge branch 'main' of github.com:hashicorp/terraform-provider-aws in…
shuheiktgw Apr 3, 2021
84825bc
Support the min_workers argument
shuheiktgw Apr 3, 2021
4c2cb35
Add nil check on the environment
shuheiktgw Apr 3, 2021
7902e1e
Add ErrorChecks to the tests
shuheiktgw Apr 3, 2021
07d84e9
Miscellaneous changes on the tests
shuheiktgw Apr 3, 2021
fde9ee0
Make some arguments computed
shuheiktgw Apr 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/servicetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var mapServiceNames = []string{
"medialive",
"mediapackage",
"mq",
"mwaa",
"opsworks",
"qldb",
"pinpoint",
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var serviceNames = []string{
"mediapackage",
"mediastore",
"mq",
"mwaa",
"neptune",
"networkfirewall",
"networkmanager",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import (
"github.com/aws/aws-sdk-go/service/mediapackage"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/aws/aws-sdk-go/service/mwaa"
"github.com/aws/aws-sdk-go/service/neptune"
"github.com/aws/aws-sdk-go/service/networkfirewall"
"github.com/aws/aws-sdk-go/service/networkmanager"
Expand Down Expand Up @@ -283,6 +284,8 @@ func ServiceClientType(serviceName string) string {
funcType = reflect.TypeOf(mediastore.New)
case "mq":
funcType = reflect.TypeOf(mq.New)
case "mwaa":
funcType = reflect.TypeOf(mwaa.New)
case "neptune":
funcType = reflect.TypeOf(neptune.New)
case "networkfirewall":
Expand Down Expand Up @@ -409,6 +412,8 @@ func ServiceListTagsFunction(serviceName string) string {
return "ListTags"
case "mq":
return "ListTags"
case "mwaa":
return "ListTags"
case "opsworks":
return "ListTags"
case "redshift":
Expand Down
10 changes: 10 additions & 0 deletions aws/internal/keyvaluetags/service_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions aws/internal/keyvaluetags/update_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions aws/internal/service/mwaa/finder/finder.go
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
}
35 changes: 35 additions & 0 deletions aws/internal/service/mwaa/waiter/status.go
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
}
}
82 changes: 82 additions & 0 deletions aws/internal/service/mwaa/waiter/waiter.go
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
Copy link
Contributor

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. 👍


// 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func Provider() *schema.Provider {
"aws_msk_cluster": resourceAwsMskCluster(),
"aws_msk_configuration": resourceAwsMskConfiguration(),
"aws_msk_scram_secret_association": resourceAwsMskScramSecretAssociation(),
"aws_mwaa_environment": resourceAwsMwaaEnvironment(),
"aws_nat_gateway": resourceAwsNatGateway(),
"aws_network_acl": resourceAwsNetworkAcl(),
"aws_default_network_acl": resourceAwsDefaultNetworkAcl(),
Expand Down
Loading