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/aws_kinesis_analytics_application: Add 'start_application' attribute #17784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changelog/17784.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_kinesis_analytics_application: Add `start_application` attribute
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
```

```release-note:enhancement
resource/aws_kinesis_analytics_application: `starting_position_configuration` can be specified when starting an application
```
28 changes: 26 additions & 2 deletions aws/internal/service/kinesisanalytics/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,42 @@ package finder
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kinesisanalytics"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// ApplicationByName returns the application corresponding to the specified name.
func ApplicationByName(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
// ApplicationDetailByName returns the application corresponding to the specified name.
// Returns NotFoundError if no application is found.
func ApplicationDetailByName(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
input := &kinesisanalytics.DescribeApplicationInput{
ApplicationName: aws.String(name),
}

return ApplicationDetail(conn, input)
}

// ApplicationDetail returns the application details corresponding to the specified name.
// Returns NotFoundError if no application is found.
func ApplicationDetail(conn *kinesisanalytics.KinesisAnalytics, input *kinesisanalytics.DescribeApplicationInput) (*kinesisanalytics.ApplicationDetail, error) {
output, err := conn.DescribeApplication(input)

if tfawserr.ErrCodeEquals(err, kinesisanalytics.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.ApplicationDetail == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output.ApplicationDetail, nil
}
19 changes: 7 additions & 12 deletions aws/internal/service/kinesisanalytics/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@ package waiter
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kinesisanalytics"
"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/kinesisanalytics/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
applicationStatusNotFound = "NotFound"
applicationStatusUnknown = "Unknown"
)

// ApplicationStatus fetches the Application and its Status
// ApplicationStatus fetches the ApplicationDetail and its Status
func ApplicationStatus(conn *kinesisanalytics.KinesisAnalytics, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
application, err := finder.ApplicationByName(conn, name)
applicationDetail, err := finder.ApplicationDetailByName(conn, name)

if tfawserr.ErrCodeEquals(err, kinesisanalytics.ErrCodeResourceNotFoundException) {
return nil, applicationStatusNotFound, nil
if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, applicationStatusUnknown, err
return nil, "", err
}

return application, aws.StringValue(application.ApplicationStatus), nil
return applicationDetail, aws.StringValue(applicationDetail.ApplicationStatus), nil
}
}
69 changes: 65 additions & 4 deletions aws/internal/service/kinesisanalytics/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,79 @@ import (
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
ApplicationDeletedTimeout = 5 * time.Minute
ApplicationStartedTimeout = 5 * time.Minute
ApplicationStoppedTimeout = 5 * time.Minute
ApplicationUpdatedTimeout = 5 * time.Minute
)

// ApplicationDeleted waits for an Application to return Deleted
func ApplicationDeleted(conn *kinesisanalytics.KinesisAnalytics, name string, timeout time.Duration) (*kinesisanalytics.ApplicationSummary, error) {
func ApplicationDeleted(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{kinesisanalytics.ApplicationStatusRunning, kinesisanalytics.ApplicationStatusDeleting},
Pending: []string{kinesisanalytics.ApplicationStatusDeleting},
Target: []string{},
Refresh: ApplicationStatus(conn, name),
Timeout: timeout,
Timeout: ApplicationDeletedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*kinesisanalytics.ApplicationDetail); ok {
return v, err
}

return nil, err
}

// ApplicationStarted waits for an Application to start
func ApplicationStarted(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{kinesisanalytics.ApplicationStatusStarting},
Target: []string{kinesisanalytics.ApplicationStatusRunning},
Refresh: ApplicationStatus(conn, name),
Timeout: ApplicationStartedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*kinesisanalytics.ApplicationDetail); ok {
return v, err
}

return nil, err
}

// ApplicationStopped waits for an Application to stop
func ApplicationStopped(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{kinesisanalytics.ApplicationStatusStopping},
Target: []string{kinesisanalytics.ApplicationStatusReady},
Refresh: ApplicationStatus(conn, name),
Timeout: ApplicationStoppedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*kinesisanalytics.ApplicationDetail); ok {
return v, err
}

return nil, err
}

// ApplicationUpdated waits for an Application to update
func ApplicationUpdated(conn *kinesisanalytics.KinesisAnalytics, name string) (*kinesisanalytics.ApplicationDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{kinesisanalytics.ApplicationStatusUpdating},
Target: []string{kinesisanalytics.ApplicationStatusReady, kinesisanalytics.ApplicationStatusRunning},
Refresh: ApplicationStatus(conn, name),
Timeout: ApplicationUpdatedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*kinesisanalytics.ApplicationSummary); ok {
if v, ok := outputRaw.(*kinesisanalytics.ApplicationDetail); ok {
return v, err
}

Expand Down
Loading