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

resource/aws_sfn_state_machine: Support Update State machine call #2349

Merged

Conversation

Puneeth-n
Copy link
Contributor

Resolves #2341

requires #2344 to be merged first

@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Nov 20, 2017
@Ninir Ninir changed the title support Update State machine call resource/aws_sfn_state_machine: Support Update State machine call Nov 20, 2017
Copy link
Contributor

@Ninir Ninir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Puneeth-n

As asked, just left a few comments to address before getting this merged in! :)

Thanks for the work! 🙂 🚀

@@ -125,6 +124,32 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er
return nil
}

func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sfnconn
log.Printf("[DEBUG] Updating Step Function State Machine: %s", d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this one before 137 and log the overall params structure? as in:

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

if err != nil {

if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "NotFoundException" || awserr.Code() == "StateMachineDoesNotExist" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the 2 above line for something like:

if isAWSErr(err, "StateMachineDoesNotExist", "something") {
...
}

In place of something, you should write something that is sent back by the AWS API. This parameter is used by the function to check whether err.Message() contains the string you are passing.

if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "NotFoundException" || awserr.Code() == "StateMachineDoesNotExist" {
d.SetId("")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In place of these 2 lines, it would be preferable to return an error, as in:

return fmt.Errorf("Error updating Step Function State Machine: %s", err)

Setting an ID to empty removes it from the state, step done by the Read part, always happening before updating/deleting

@Puneeth-n Puneeth-n force-pushed the chore/aws-sfn-update-state-machine branch from fb716b7 to 23fe7ea Compare November 21, 2017 10:37
@Puneeth-n
Copy link
Contributor Author

@Ninir done :)

@Ninir
Copy link
Contributor

Ninir commented Nov 21, 2017

Could you add an acceptance test with 2 steps (one for creation, the other one for update)? thanks :)

@Puneeth-n Puneeth-n force-pushed the chore/aws-sfn-update-state-machine branch from 23fe7ea to f55d3f8 Compare November 21, 2017 17:48
@Puneeth-n
Copy link
Contributor Author

@Ninir I am not sure how I can check the sfn definition changes in the acceptance tests.

root@5f4b89633452:/go/src/github.com/terraform-providers/terraform-provider-aws# make testacc TESTARGS='-run=TestAccAWSSfnStateMachine_createUpdate'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccAWSSfnStateMachine_createUpdate -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSSfnStateMachine_createUpdate
--- PASS: TestAccAWSSfnStateMachine_createUpdate (84.16s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	84.182s

@Puneeth-n Puneeth-n force-pushed the chore/aws-sfn-update-state-machine branch from f55d3f8 to 5010a1d Compare November 21, 2017 17:50
@Puneeth-n Puneeth-n force-pushed the chore/aws-sfn-update-state-machine branch from 5010a1d to 6c763c1 Compare November 21, 2017 19:13
@Ninir
Copy link
Contributor

Ninir commented Nov 21, 2017

@Puneeth-n We could store the output and use it afterwards, as in https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_flow_log_test.go#L15-L29

We could then check if the ID changed, and hash the structure to ensure that the content changed too. Thoughts?

@Puneeth-n
Copy link
Contributor Author

Puneeth-n commented Nov 21, 2017

@Ninir I used regex to check the output. after the state machine was updated. what do you think about it?

@Ninir
Copy link
Contributor

Ninir commented Nov 21, 2017

@Puneeth-n Depending on the regex written, this could be sufficient, nice idea :)

@Puneeth-n
Copy link
Contributor Author

@Ninir I have already included it in the Acceptance tests. Let me know if you want any changes.

Copy link
Contributor

@Ninir Ninir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Puneeth-n

This looks very good to me :)

make testacc TEST=./aws TESTARGS='-run=TestAccAWSSfnStateMachine_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSfnStateMachine_ -timeout 120m
=== RUN   TestAccAWSSfnStateMachine_createUpdate
--- PASS: TestAccAWSSfnStateMachine_createUpdate (53.01s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	53.054s

Thanks a lot for the work and reactivity! 🚀 😄

@Ninir Ninir merged commit f416a86 into hashicorp:master Nov 22, 2017
@Puneeth-n
Copy link
Contributor Author

@Ninir Thanks a lot :) Wanted to get this feature into mainline so that we can get rid of our fork. :)

@Puneeth-n Puneeth-n deleted the chore/aws-sfn-update-state-machine branch November 30, 2017 20:33
@ghost
Copy link

ghost commented Apr 10, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Step function update state machine
2 participants