opentofu/builtin/providers/aws/resource_aws_sfn_activity_test.go
Gauthier Wallet 4da1451971 Added Step Function resources (State Machine & Activity) (#11420)
* Added Step Function Activity & Step Function State Machine

* Added SFN State Machine documentation

* Added aws_sfn_activity & documentation

* Allowed import of sfn resources

* Added more checks on tests, fixed documentation

* Handled the update case of a SFN function (might be already deleting)

* Removed the State Machine import test file

* Fixed the eventual consistency of the read after delete for SFN functions
2017-01-31 20:17:38 +00:00

107 lines
2.6 KiB
Go

package aws
import (
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"time"
)
func TestAccAWSSfnActivity_basic(t *testing.T) {
name := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSfnActivityDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSfnActivityBasicConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSfnActivityExists("aws_sfn_activity.foo"),
resource.TestCheckResourceAttr("aws_sfn_activity.foo", "name", name),
resource.TestCheckResourceAttrSet("aws_sfn_activity.foo", "creation_date"),
),
},
},
})
}
func testAccCheckAWSSfnActivityExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Step Function ID set")
}
conn := testAccProvider.Meta().(*AWSClient).sfnconn
_, err := conn.DescribeActivity(&sfn.DescribeActivityInput{
ActivityArn: aws.String(rs.Primary.ID),
})
if err != nil {
return err
}
return nil
}
}
func testAccCheckAWSSfnActivityDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).sfnconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_sfn_activity" {
continue
}
// Retrying as Read after Delete is not always consistent
retryErr := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
_, err = conn.DescribeActivity(&sfn.DescribeActivityInput{
ActivityArn: aws.String(rs.Primary.ID),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ActivityDoesNotExist" {
return nil
}
return resource.NonRetryableError(err)
}
// If there are no errors, the removal failed
// and the object is not yet removed.
return resource.RetryableError(fmt.Errorf("Expected AWS Step Function Activity to be destroyed, but was still found, retrying"))
})
if retryErr != nil {
return retryErr
}
return nil
}
return fmt.Errorf("Default error in Step Function Test")
}
func testAccAWSSfnActivityBasicConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_sfn_activity" "foo" {
name = "%s"
}
`, rName)
}