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

SFN State Machine Express support #11374

Closed
wants to merge 13 commits into from
37 changes: 25 additions & 12 deletions aws/resource_aws_sfn_state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"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-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -54,6 +53,16 @@ func resourceAwsSfnStateMachine() *schema.Resource {
Computed: true,
},
"tags": tagsSchema(),
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: sfn.StateMachineTypeStandard,
ValidateFunc: validation.StringInSlice([]string{
sfn.StateMachineTypeStandard,
sfn.StateMachineTypeExpress,
}, false),
},
},
}
}
Expand All @@ -66,20 +75,25 @@ func resourceAwsSfnStateMachineCreate(d *schema.ResourceData, meta interface{})
Definition: aws.String(d.Get("definition").(string)),
Name: aws.String(d.Get("name").(string)),
RoleArn: aws.String(d.Get("role_arn").(string)),
Type: aws.String(d.Get("type").(string)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().SfnTags(),
}

var activity *sfn.CreateStateMachineOutput
var stateMachine *sfn.CreateStateMachineOutput

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
activity, err = conn.CreateStateMachine(params)
stateMachine, err = conn.CreateStateMachine(params)

if err != nil {
// Note: the instance may be in a deleting mode, hence the retry
// when creating the step function. This can happen when we are
// updating the resource (since there is no update API call).
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "StateMachineDeleting" {
if isAWSErr(err, sfn.ErrCodeStateMachineDeleting, "") {
return resource.RetryableError(err)
}
//This is done to deal with IAM eventual consistency
if isAWSErr(err, "AccessDeniedException", "") {
return resource.RetryableError(err)
}

Expand All @@ -89,14 +103,14 @@ func resourceAwsSfnStateMachineCreate(d *schema.ResourceData, meta interface{})
return nil
})
if isResourceTimeoutError(err) {
activity, err = conn.CreateStateMachine(params)
stateMachine, err = conn.CreateStateMachine(params)
}

if err != nil {
return fmt.Errorf("Error creating Step Function State Machine: %s", err)
}

d.SetId(*activity.StateMachineArn)
d.SetId(*stateMachine.StateMachineArn)

return resourceAwsSfnStateMachineRead(d, meta)
}
Expand All @@ -110,11 +124,9 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er
})
if err != nil {

if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "NotFoundException" || awserr.Code() == "StateMachineDoesNotExist" {
d.SetId("")
return nil
}
if isAWSErr(err, sfn.ErrCodeStateMachineDoesNotExist, "") {
d.SetId("")
return nil
}
return err
}
Expand All @@ -123,6 +135,7 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er
d.Set("name", sm.Name)
d.Set("role_arn", sm.RoleArn)
d.Set("status", sm.Status)
d.Set("type", sm.Type)

if err := d.Set("creation_date", sm.CreationDate.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Error setting creation_date: %s", err)
Expand Down Expand Up @@ -155,7 +168,7 @@ func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{})
log.Printf("[DEBUG] Updating Step Function State Machine: %#v", params)

if err != nil {
if isAWSErr(err, "StateMachineDoesNotExist", "State Machine Does Not Exist") {
if isAWSErr(err, sfn.ErrCodeStateMachineDoesNotExist, "State Machine Does Not Exist") {
return fmt.Errorf("Error updating Step Function State Machine: %s", err)
}
return err
Expand Down
Loading