Skip to content

Commit

Permalink
Merge pull request #2349 from Puneeth-n/chore/aws-sfn-update-state-ma…
Browse files Browse the repository at this point in the history
…chine

resource/aws_sfn_state_machine: Support Update State machine call
  • Loading branch information
Ninir authored Nov 22, 2017
2 parents 3ea4a48 + 6c763c1 commit f416a86
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
27 changes: 25 additions & 2 deletions aws/resource_aws_sfn_state_machine.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"fmt"
"log"
"time"

Expand All @@ -16,6 +17,7 @@ func resourceAwsSfnStateMachine() *schema.Resource {
return &schema.Resource{
Create: resourceAwsSfnStateMachineCreate,
Read: resourceAwsSfnStateMachineRead,
Update: resourceAwsSfnStateMachineUpdate,
Delete: resourceAwsSfnStateMachineDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand All @@ -25,7 +27,6 @@ func resourceAwsSfnStateMachine() *schema.Resource {
"definition": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateSfnStateMachineDefinition,
},

Expand All @@ -39,7 +40,6 @@ func resourceAwsSfnStateMachine() *schema.Resource {
"role_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateArn,
},

Expand Down Expand Up @@ -125,6 +125,29 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er
return nil
}

func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn

params := &sfn.UpdateStateMachineInput{
StateMachineArn: aws.String(d.Id()),
Definition: aws.String(d.Get("definition").(string)),
RoleArn: aws.String(d.Get("role_arn").(string)),
}

_, err := conn.UpdateStateMachine(params)

log.Printf("[DEBUG] Updating Step Function State Machine: %#v", params)

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

return resourceAwsSfnStateMachineRead(d, meta)
}

func resourceAwsSfnStateMachineDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn
log.Printf("[DEBUG] Deleting Step Function State Machine: %s", d.Id())
Expand Down
29 changes: 25 additions & 4 deletions aws/resource_aws_sfn_state_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -12,7 +13,7 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSSfnStateMachine_basic(t *testing.T) {
func TestAccAWSSfnStateMachine_createUpdate(t *testing.T) {
name := acctest.RandString(10)

resource.Test(t, resource.TestCase{
Expand All @@ -21,13 +22,25 @@ func TestAccAWSSfnStateMachine_basic(t *testing.T) {
CheckDestroy: testAccCheckAWSSfnStateMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSfnStateMachineBasicConfig(name),
Config: testAccAWSSfnStateMachineConfig(name, 5),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSfnExists("aws_sfn_state_machine.foo"),
resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "status", sfn.StateMachineStatusActive),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "name"),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "creation_date"),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "definition"),
resource.TestMatchResourceAttr("aws_sfn_state_machine.foo", "definition", regexp.MustCompile(`.*\"MaxAttempts\": 5.*`)),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "role_arn"),
),
},
{
Config: testAccAWSSfnStateMachineConfig(name, 10),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSfnExists("aws_sfn_state_machine.foo"),
resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "status", sfn.StateMachineStatusActive),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "name"),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "creation_date"),
resource.TestMatchResourceAttr("aws_sfn_state_machine.foo", "definition", regexp.MustCompile(`.*\"MaxAttempts\": 10.*`)),
resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "role_arn"),
),
},
Expand Down Expand Up @@ -89,7 +102,7 @@ func testAccCheckAWSSfnStateMachineDestroy(s *terraform.State) error {
return fmt.Errorf("Default error in Step Function Test")
}

func testAccAWSSfnStateMachineBasicConfig(rName string) string {
func testAccAWSSfnStateMachineConfig(rName string, rMaxAttempts int) string {
return fmt.Sprintf(`
data "aws_region" "current" {
current = true
Expand Down Expand Up @@ -190,12 +203,20 @@ resource "aws_sfn_state_machine" "foo" {
"HelloWorld": {
"Type": "Task",
"Resource": "${aws_lambda_function.lambda_function_test.arn}",
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 5,
"MaxAttempts": %d,
"BackoffRate": 8.0
}
],
"End": true
}
}
}
EOF
}
`, rName, rName, rName, rName, rName, rName)
`, rName, rName, rName, rName, rName, rName, rMaxAttempts)
}

0 comments on commit f416a86

Please sign in to comment.