Skip to content

Commit

Permalink
r/aws_globalaccelerator_accelerator: Use internal finder package. Add…
Browse files Browse the repository at this point in the history
… '_disappears' test (hashicorp#13826, hashicorp#13527).

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAwsGlobalAcceleratorAccelerator_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAwsGlobalAcceleratorAccelerator_ -timeout 120m
=== RUN   TestAccAwsGlobalAcceleratorAccelerator_basic
=== PAUSE TestAccAwsGlobalAcceleratorAccelerator_basic
=== RUN   TestAccAwsGlobalAcceleratorAccelerator_disappears
=== PAUSE TestAccAwsGlobalAcceleratorAccelerator_disappears
=== RUN   TestAccAwsGlobalAcceleratorAccelerator_update
=== PAUSE TestAccAwsGlobalAcceleratorAccelerator_update
=== RUN   TestAccAwsGlobalAcceleratorAccelerator_attributes
=== PAUSE TestAccAwsGlobalAcceleratorAccelerator_attributes
=== RUN   TestAccAwsGlobalAcceleratorAccelerator_tags
=== PAUSE TestAccAwsGlobalAcceleratorAccelerator_tags
=== CONT  TestAccAwsGlobalAcceleratorAccelerator_basic
=== CONT  TestAccAwsGlobalAcceleratorAccelerator_attributes
=== CONT  TestAccAwsGlobalAcceleratorAccelerator_tags
=== CONT  TestAccAwsGlobalAcceleratorAccelerator_update
=== CONT  TestAccAwsGlobalAcceleratorAccelerator_disappears
--- PASS: TestAccAwsGlobalAcceleratorAccelerator_disappears (68.53s)
--- PASS: TestAccAwsGlobalAcceleratorAccelerator_basic (77.55s)
--- PASS: TestAccAwsGlobalAcceleratorAccelerator_tags (101.99s)
--- PASS: TestAccAwsGlobalAcceleratorAccelerator_update (103.04s)
--- PASS: TestAccAwsGlobalAcceleratorAccelerator_attributes (112.32s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	112.414s
  • Loading branch information
ewbankkit committed Feb 11, 2021
1 parent bd18053 commit 46e939b
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 149 deletions.
62 changes: 62 additions & 0 deletions aws/internal/service/globalaccelerator/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,70 @@ package finder
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/globalaccelerator"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// AcceleratorByARN returns the accelerator corresponding to the specified ARN.
// Returns NotFoundError if no accelerator is found.
func AcceleratorByARN(conn *globalaccelerator.GlobalAccelerator, arn string) (*globalaccelerator.Accelerator, error) {
input := &globalaccelerator.DescribeAcceleratorInput{
AcceleratorArn: aws.String(arn),
}

output, err := conn.DescribeAccelerator(input)

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

if err != nil {
return nil, err
}

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

return output.Accelerator, nil
}

// AcceleratorAttributesByARN returns the accelerator corresponding to the specified ARN.
// Returns NotFoundError if no accelerator is found.
func AcceleratorAttributesByARN(conn *globalaccelerator.GlobalAccelerator, arn string) (*globalaccelerator.AcceleratorAttributes, error) {
input := &globalaccelerator.DescribeAcceleratorAttributesInput{
AcceleratorArn: aws.String(arn),
}

output, err := conn.DescribeAcceleratorAttributes(input)

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

if err != nil {
return nil, err
}

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

return output.AcceleratorAttributes, nil
}

// EndpointGroupByARN returns the endpoint group corresponding to the specified ARN.
func EndpointGroupByARN(conn *globalaccelerator.GlobalAccelerator, arn string) (*globalaccelerator.EndpointGroup, error) {
input := &globalaccelerator.DescribeEndpointGroupInput{
Expand Down
26 changes: 26 additions & 0 deletions aws/internal/service/globalaccelerator/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/globalaccelerator"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/globalaccelerator/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

// AcceleratorStatus fetches the Accelerator and its Status
func AcceleratorStatus(conn *globalaccelerator.GlobalAccelerator, arn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
accelerator, err := finder.AcceleratorByARN(conn, arn)

if tfresource.NotFound(err) {
return nil, "", nil
}

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

return accelerator, aws.StringValue(accelerator.Status), nil
}
}
26 changes: 26 additions & 0 deletions aws/internal/service/globalaccelerator/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/globalaccelerator"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// AcceleratorDeployed waits for an Accelerator to return Deployed
func AcceleratorDeployed(conn *globalaccelerator.GlobalAccelerator, arn string, timeout time.Duration) (*globalaccelerator.Accelerator, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: AcceleratorStatus(conn, arn),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}
Loading

0 comments on commit 46e939b

Please sign in to comment.