From ff67906b381d3ddb0d47c5474dff6549fadf486a Mon Sep 17 00:00:00 2001 From: stp Date: Sun, 12 Jan 2020 20:53:00 +0100 Subject: [PATCH 01/14] Enhancement: Step Functions for Express Workflows --- aws/resource_aws_sfn_state_machine.go | 117 +++++- aws/resource_aws_sfn_state_machine_test.go | 386 ++++++++++++++++++ .../docs/r/sfn_state_machine.html.markdown | 66 +++ 3 files changed, 561 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_sfn_state_machine.go b/aws/resource_aws_sfn_state_machine.go index af8f8d0e6ad..b4dcec19a7f 100644 --- a/aws/resource_aws_sfn_state_machine.go +++ b/aws/resource_aws_sfn_state_machine.go @@ -31,6 +31,37 @@ func resourceAwsSfnStateMachine() *schema.Resource { ValidateFunc: validation.StringLenBetween(0, 1024*1024), // 1048576 }, + "logging_configuration": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "log_destination": { + Type: schema.TypeString, + Optional: true, + }, + "include_execution_data": { + Type: schema.TypeBool, + Optional: true, + // Default: false, + }, + "level": { + Type: schema.TypeString, + Optional: true, + // Default: sfn.LogLevelOff, + ValidateFunc: validation.StringInSlice([]string{ + sfn.LogLevelAll, + sfn.LogLevelError, + sfn.LogLevelFatal, + sfn.LogLevelOff, + }, false), + }, + }, + }, + }, + "name": { Type: schema.TypeString, Required: true, @@ -53,11 +84,21 @@ func resourceAwsSfnStateMachine() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "tags": tagsSchema(), "arn": { Type: schema.TypeString, Computed: true, }, + "type": { + Type: schema.TypeString, + Optional: true, + Default: sfn.StateMachineTypeStandard, + ValidateFunc: validation.StringInSlice([]string{ + sfn.StateMachineTypeStandard, + sfn.StateMachineTypeExpress, + }, false), + }, }, } } @@ -65,12 +106,13 @@ func resourceAwsSfnStateMachine() *schema.Resource { func resourceAwsSfnStateMachineCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).sfnconn log.Print("[DEBUG] Creating Step Function State Machine") - params := &sfn.CreateStateMachineInput{ - Definition: aws.String(d.Get("definition").(string)), - Name: aws.String(d.Get("name").(string)), - RoleArn: aws.String(d.Get("role_arn").(string)), - Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().SfnTags(), + Definition: aws.String(d.Get("definition").(string)), + LoggingConfiguration: expandAwsSfnLoggingConfiguration(d.Get("logging_configuration").([]interface{})), + Name: aws.String(d.Get("name").(string)), + RoleArn: aws.String(d.Get("role_arn").(string)), + Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().SfnTags(), + Type: aws.String(d.Get("type").(string)), } var stateMachine *sfn.CreateStateMachineOutput @@ -114,7 +156,6 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig log.Printf("[DEBUG] Reading Step Function State Machine: %s", d.Id()) - sm, err := conn.DescribeStateMachine(&sfn.DescribeStateMachineInput{ StateMachineArn: aws.String(d.Id()), }) @@ -132,8 +173,18 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er d.Set("definition", sm.Definition) d.Set("name", sm.Name) d.Set("role_arn", sm.RoleArn) + d.Set("type", sm.Type) d.Set("status", sm.Status) + loggingConfiguration := flattenAwsSfnLoggingConfiguration(sm.LoggingConfiguration) + + if loggingConfiguration != nil { + err := d.Set("logging_configuration", loggingConfiguration) + if err != nil { + log.Printf("[DEBUG] Error setting logging_configuration %s \n", err) + } + } + if err := d.Set("creation_date", sm.CreationDate.Format(time.RFC3339)); err != nil { log.Printf("[DEBUG] Error setting creation_date: %s", err) } @@ -154,13 +205,21 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).sfnconn - if d.HasChanges("definition", "role_arn") { + if d.HasChange("logging_configuration") && d.Get("type").(string) == sfn.StateMachineTypeExpress { + params.LoggingConfiguration = expandAwsSfnLoggingConfiguration(d.Get("logging_configuration").([]interface{})) + } + + if d.HasChanges("definition", "role_arn", "logging_configuration") { params := &sfn.UpdateStateMachineInput{ StateMachineArn: aws.String(d.Id()), Definition: aws.String(d.Get("definition").(string)), RoleArn: aws.String(d.Get("role_arn").(string)), } + if d.HasChange("logging_configuration") { + params.LoggingConfiguration = expandAwsSfnLoggingConfiguration(d.Get("logging_configuration").([]interface{})) + } + _, err := conn.UpdateStateMachine(params) log.Printf("[DEBUG] Updating Step Function State Machine: %#v", params) @@ -180,7 +239,7 @@ func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) } } - return resourceAwsSfnStateMachineRead(d, meta) + return nil } func resourceAwsSfnStateMachineDelete(d *schema.ResourceData, meta interface{}) error { @@ -206,3 +265,45 @@ func resourceAwsSfnStateMachineDelete(d *schema.ResourceData, meta interface{}) return nil } + +func expandAwsSfnLoggingConfiguration(l []interface{}) *sfn.LoggingConfiguration { + + if len(l) == 0 || l[0] == nil { + return nil + } + + m := l[0].(map[string]interface{}) + + loggingConfiguration := &sfn.LoggingConfiguration{ + Destinations: []*sfn.LogDestination{ + { + CloudWatchLogsLogGroup: &sfn.CloudWatchLogsLogGroup{ + LogGroupArn: aws.String(m["log_destination"].(string)), + }, + }, + }, + IncludeExecutionData: aws.Bool(m["include_execution_data"].(bool)), + Level: aws.String(m["level"].(string)), + } + + return loggingConfiguration +} + +func flattenAwsSfnLoggingConfiguration(loggingConfiguration *sfn.LoggingConfiguration) []interface{} { + + if loggingConfiguration == nil { + return []interface{}{} + } + + m := map[string]interface{}{ + "log_destination": "", + "include_execution_data": aws.BoolValue(loggingConfiguration.IncludeExecutionData), + "level": aws.StringValue(loggingConfiguration.Level), + } + + if len(loggingConfiguration.Destinations) > 0 { + m["log_destination"] = aws.StringValue(loggingConfiguration.Destinations[0].CloudWatchLogsLogGroup.LogGroupArn) + } + + return []interface{}{m} +} diff --git a/aws/resource_aws_sfn_state_machine_test.go b/aws/resource_aws_sfn_state_machine_test.go index 663b6c94bf2..88d48fc3493 100644 --- a/aws/resource_aws_sfn_state_machine_test.go +++ b/aws/resource_aws_sfn_state_machine_test.go @@ -57,6 +57,84 @@ func TestAccAWSSfnStateMachine_createUpdate(t *testing.T) { }) } +func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { + var sm sfn.DescribeStateMachineOutput + name := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSfnStateMachineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSfnStateMachineTypedConfig(sfn.StateMachineTypeExpress, name, 5), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), + 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"), + // resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "logging_configuration"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), + ), + }, + { + Config: testAccAWSSfnStateMachineTypedConfig(sfn.StateMachineTypeExpress, name, 10), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), + 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"), + // resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "logging_configuration"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), + ), + }, + }, + }) +} + +func TestAccAWSSfnStateMachine_standard_createUpdate(t *testing.T) { + var sm sfn.DescribeStateMachineOutput + name := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSfnStateMachineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSfnStateMachineTypedConfig(sfn.StateMachineTypeStandard, name, 5), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), + 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: testAccAWSSfnStateMachineTypedConfig(sfn.StateMachineTypeStandard, name, 10), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), + 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"), + ), + }, + }, + }) +} + func TestAccAWSSfnStateMachine_tags(t *testing.T) { var sm sfn.DescribeStateMachineOutput resourceName := "aws_sfn_state_machine.test" @@ -123,6 +201,46 @@ func TestAccAWSSfnStateMachine_disappears(t *testing.T) { }) } +func TestAccAWSSfnStateMachine_express_LoggingConfiguration(t *testing.T) { + var sm sfn.DescribeStateMachineOutput + name := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSfnStateMachineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration1(sfn.StateMachineTypeExpress, name, sfn.LogLevelError), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), + 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"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelError), + ), + }, + { + Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration1(sfn.StateMachineTypeExpress, name, sfn.LogLevelAll), + 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\": 5.*`)), + resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "role_arn"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelAll), + ), + }, + }, + }) +} + func testAccCheckAWSSfnExists(n string, sm *sfn.DescribeStateMachineOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -351,3 +469,271 @@ EOF } `, rName, tag1Key, tag1Value, tag2Key, tag2Value) } + +func testAccAWSSfnStateMachineTypedConfig(rType string, rName string, rMaxAttempts int) string { + return fmt.Sprintf(` +data "aws_partition" "current" {} + +data "aws_region" "current" {} + +resource "aws_iam_role_policy" "iam_policy_for_lambda" { + name = "iam_policy_for_lambda_%s" + role = "${aws_iam_role.iam_for_lambda.id}" + + policy = < *NOTE:* Logging is only accepted for EXPRESS Workflows. See the [AWS Step Functions Developer Guide](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) for more information about enabling Step Function logging. ```hcl # ... @@ -18,6 +70,7 @@ Provides a Step Function State Machine resource resource "aws_sfn_state_machine" "sfn_state_machine" { name = "my-state-machine" role_arn = "${aws_iam_role.iam_for_sfn.arn}" + type = "EXPRESS" definition = < Date: Wed, 4 Mar 2020 06:49:59 -0800 Subject: [PATCH 02/14] removed express logging restrictions --- aws/resource_aws_sfn_state_machine.go | 10 +++++++++- website/docs/r/sfn_state_machine.html.markdown | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_sfn_state_machine.go b/aws/resource_aws_sfn_state_machine.go index b4dcec19a7f..769e0a3662b 100644 --- a/aws/resource_aws_sfn_state_machine.go +++ b/aws/resource_aws_sfn_state_machine.go @@ -205,7 +205,15 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).sfnconn - if d.HasChange("logging_configuration") && d.Get("type").(string) == sfn.StateMachineTypeExpress { + params := &sfn.UpdateStateMachineInput{ + StateMachineArn: aws.String(d.Id()), + Definition: aws.String(d.Get("definition").(string)), + RoleArn: aws.String(d.Get("role_arn").(string)), + } + + log.Printf("[DEBUG] Updating Step Function State Machine: %#v", params) + + if d.HasChange("logging_configuration") { params.LoggingConfiguration = expandAwsSfnLoggingConfiguration(d.Get("logging_configuration").([]interface{})) } diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index aa2c019bff9..6af037cdf30 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -62,7 +62,7 @@ EOF ### Logging -~> *NOTE:* Logging is only accepted for EXPRESS Workflows. See the [AWS Step Functions Developer Guide](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) for more information about enabling Step Function logging. +~> *NOTE:* See the [AWS Step Functions Developer Guide](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) for more information about enabling Step Function logging. ```hcl # ... @@ -70,7 +70,6 @@ EOF resource "aws_sfn_state_machine" "sfn_state_machine" { name = "my-state-machine" role_arn = "${aws_iam_role.iam_for_sfn.arn}" - type = "EXPRESS" definition = < Date: Wed, 4 Mar 2020 07:22:54 -0800 Subject: [PATCH 03/14] fenced lines fix --- website/docs/r/sfn_state_machine.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index 6af037cdf30..5d0efaf6abb 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -12,6 +12,7 @@ Provides a Step Function State Machine resource ## Example Usage ### Basic (Standard Workflow) + ```hcl # ... From 863f4073e417956cf5471f7da60e65618e00e482 Mon Sep 17 00:00:00 2001 From: graham jenson Date: Wed, 4 Mar 2020 09:39:30 -0800 Subject: [PATCH 04/14] fixing hcl styling --- website/docs/r/sfn_state_machine.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index 5d0efaf6abb..f22773ac417 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -37,6 +37,7 @@ EOF ``` ### Basic (Express Workflow) + ```hcl # ... From c0f10b23fd46a92a4e9302f6358a77966d514d40 Mon Sep 17 00:00:00 2001 From: graham jenson Date: Wed, 4 Mar 2020 09:53:06 -0800 Subject: [PATCH 05/14] fix styling --- website/docs/r/sfn_state_machine.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index f22773ac417..ca81efa3fc7 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -107,6 +107,7 @@ The following arguments are supported: * `type` - (Optional) Determines whether a Standard or Express state machine is created. The default is STANDARD. You cannot update the type of a state machine once it has been created. Valid Values: STANDARD | EXPRESS ### `logging_configuration` Configuration Block + * `log_destination` - (Optional) Amazon Resource Name (ARN) of CloudWatch log group. Make sure the State Machine does have the right IAM Policies for Logging. * `include_execution_data` - (Optional) Determines whether execution data is included in your log. When set to FALSE, data is excluded. * `level` - (Optional) Defines which category of execution history events are logged. Valid Values: ALL | ERROR | FATAL | OFF From 7bcc4d0c8cd0461998657cb9238e398af2f9e3b6 Mon Sep 17 00:00:00 2001 From: graham jenson Date: Thu, 11 Jun 2020 09:49:34 -0700 Subject: [PATCH 06/14] force new --- aws/resource_aws_sfn_state_machine.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_sfn_state_machine.go b/aws/resource_aws_sfn_state_machine.go index 769e0a3662b..f10d32a2a47 100644 --- a/aws/resource_aws_sfn_state_machine.go +++ b/aws/resource_aws_sfn_state_machine.go @@ -93,6 +93,7 @@ func resourceAwsSfnStateMachine() *schema.Resource { "type": { Type: schema.TypeString, Optional: true, + ForceNew: true, Default: sfn.StateMachineTypeStandard, ValidateFunc: validation.StringInSlice([]string{ sfn.StateMachineTypeStandard, From c40cff7e4041f50a1b0d88b11124de4ce7ff506e Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Mon, 22 Jun 2020 10:18:05 -0700 Subject: [PATCH 07/14] align docs --- website/docs/r/sfn_state_machine.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index ca81efa3fc7..c34ebaf1c88 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -88,10 +88,10 @@ resource "aws_sfn_state_machine" "sfn_state_machine" { EOF logging_configuration { - log_destination = "${aws_cloudwatch_log_group.log_group_for_sfn.arn}" - include_execution_data = true - level = "ERROR" - } + log_destination = "${aws_cloudwatch_log_group.log_group_for_sfn.arn}" + include_execution_data = true + level = "ERROR" + } } ``` From 4db146671e08c4714161733e99a6c353da3c2295 Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Sun, 28 Jun 2020 22:12:03 -0700 Subject: [PATCH 08/14] Update aws/resource_aws_sfn_state_machine_test.go Co-authored-by: Dexter Miguel --- aws/resource_aws_sfn_state_machine_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/resource_aws_sfn_state_machine_test.go b/aws/resource_aws_sfn_state_machine_test.go index 88d48fc3493..c13bd8e7005 100644 --- a/aws/resource_aws_sfn_state_machine_test.go +++ b/aws/resource_aws_sfn_state_machine_test.go @@ -76,7 +76,6 @@ func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { 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"), - // resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "logging_configuration"), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), ), From 13df67915f2ae371afc5099b8b3447ebccb41e93 Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Sun, 28 Jun 2020 22:12:12 -0700 Subject: [PATCH 09/14] Update aws/resource_aws_sfn_state_machine_test.go Co-authored-by: Dexter Miguel --- aws/resource_aws_sfn_state_machine_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/resource_aws_sfn_state_machine_test.go b/aws/resource_aws_sfn_state_machine_test.go index c13bd8e7005..d8a086dcfa4 100644 --- a/aws/resource_aws_sfn_state_machine_test.go +++ b/aws/resource_aws_sfn_state_machine_test.go @@ -89,7 +89,6 @@ func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { 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"), - // resource.TestCheckResourceAttrSet("aws_sfn_state_machine.foo", "logging_configuration"), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), ), From 5f3f198d75292963b481f62c85510c9cfc7d0a0f Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Sun, 28 Jun 2020 22:12:36 -0700 Subject: [PATCH 10/14] Update website/docs/r/sfn_state_machine.html.markdown Co-authored-by: Dexter Miguel --- website/docs/r/sfn_state_machine.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index c34ebaf1c88..0509c807623 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -103,7 +103,7 @@ The following arguments are supported: * `definition` - (Required) The Amazon States Language definition of the state machine. * `role_arn` - (Required) The Amazon Resource Name (ARN) of the IAM role to use for this state machine. * `tags` - (Optional) Key-value map of resource tags -* `logging_configuration` - (Optional) Defines what execution history events are logged and where they are logged. The logging_configuration parameter is only valid when type is set to EXPRESS. By default, the level is set to OFF. For more information see [Logging Express Workflows](https://docs.aws.amazon.com/step-functions/latest/dg/cw-logs.html) and [Log Levels](https://docs.aws.amazon.com/step-functions/latest/dg/cloudwatch-log-level.html) in the AWS Step Functions User Guide. +* `logging_configuration` - (Optional) Defines what execution history events are logged and where they are logged. The `logging_configuration` parameter is only valid when `type` is set to `EXPRESS`. Defaults to `OFF`. For more information see [Logging Express Workflows](https://docs.aws.amazon.com/step-functions/latest/dg/cw-logs.html) and [Log Levels](https://docs.aws.amazon.com/step-functions/latest/dg/cloudwatch-log-level.html) in the AWS Step Functions User Guide. * `type` - (Optional) Determines whether a Standard or Express state machine is created. The default is STANDARD. You cannot update the type of a state machine once it has been created. Valid Values: STANDARD | EXPRESS ### `logging_configuration` Configuration Block From 817a992641ecd49d572868812d2582b841df514e Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Wed, 1 Jul 2020 17:38:03 -0700 Subject: [PATCH 11/14] new test format --- aws/resource_aws_sfn_state_machine_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_sfn_state_machine_test.go b/aws/resource_aws_sfn_state_machine_test.go index d8a086dcfa4..4701b0c9c7b 100644 --- a/aws/resource_aws_sfn_state_machine_test.go +++ b/aws/resource_aws_sfn_state_machine_test.go @@ -225,7 +225,7 @@ func TestAccAWSSfnStateMachine_express_LoggingConfiguration(t *testing.T) { { Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration1(sfn.StateMachineTypeExpress, name, sfn.LogLevelAll), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSSfnExists("aws_sfn_state_machine.foo"), + testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), 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"), From b99c8a84051a0463dfa24e01f3fba8d1b0a7573d Mon Sep 17 00:00:00 2001 From: Graham Jenson Date: Wed, 1 Jul 2020 17:44:49 -0700 Subject: [PATCH 12/14] fixing linter --- website/docs/r/sfn_state_machine.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index 0509c807623..0cb2df13867 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -86,11 +86,11 @@ resource "aws_sfn_state_machine" "sfn_state_machine" { } } EOF - + logging_configuration { - log_destination = "${aws_cloudwatch_log_group.log_group_for_sfn.arn}" + log_destination = "${aws_cloudwatch_log_group.log_group_for_sfn.arn}" include_execution_data = true - level = "ERROR" + level = "ERROR" } } ``` From e6e140437f165d1cf2e1efe52d2bcbc643038515 Mon Sep 17 00:00:00 2001 From: bill-rich Date: Tue, 2 Feb 2021 16:49:47 -0800 Subject: [PATCH 13/14] Remove redundant code and modify test --- aws/resource_aws_sfn_state_machine.go | 23 +------- aws/resource_aws_sfn_state_machine_test.go | 66 +++++++++++----------- 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/aws/resource_aws_sfn_state_machine.go b/aws/resource_aws_sfn_state_machine.go index f10d32a2a47..0abf61bd088 100644 --- a/aws/resource_aws_sfn_state_machine.go +++ b/aws/resource_aws_sfn_state_machine.go @@ -45,12 +45,10 @@ func resourceAwsSfnStateMachine() *schema.Resource { "include_execution_data": { Type: schema.TypeBool, Optional: true, - // Default: false, }, "level": { Type: schema.TypeString, Optional: true, - // Default: sfn.LogLevelOff, ValidateFunc: validation.StringInSlice([]string{ sfn.LogLevelAll, sfn.LogLevelError, @@ -179,11 +177,8 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er loggingConfiguration := flattenAwsSfnLoggingConfiguration(sm.LoggingConfiguration) - if loggingConfiguration != nil { - err := d.Set("logging_configuration", loggingConfiguration) - if err != nil { - log.Printf("[DEBUG] Error setting logging_configuration %s \n", err) - } + if err := d.Set("logging_configuration", loggingConfiguration); err != nil { + log.Printf("[DEBUG] Error setting logging_configuration %s", err) } if err := d.Set("creation_date", sm.CreationDate.Format(time.RFC3339)); err != nil { @@ -206,18 +201,6 @@ func resourceAwsSfnStateMachineRead(d *schema.ResourceData, meta interface{}) er 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)), - } - - log.Printf("[DEBUG] Updating Step Function State Machine: %#v", params) - - if d.HasChange("logging_configuration") { - params.LoggingConfiguration = expandAwsSfnLoggingConfiguration(d.Get("logging_configuration").([]interface{})) - } - if d.HasChanges("definition", "role_arn", "logging_configuration") { params := &sfn.UpdateStateMachineInput{ StateMachineArn: aws.String(d.Id()), @@ -248,7 +231,7 @@ func resourceAwsSfnStateMachineUpdate(d *schema.ResourceData, meta interface{}) } } - return nil + return resourceAwsSfnStateMachineRead(d, meta) } func resourceAwsSfnStateMachineDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/aws/resource_aws_sfn_state_machine_test.go b/aws/resource_aws_sfn_state_machine_test.go index 4701b0c9c7b..b215f26fa39 100644 --- a/aws/resource_aws_sfn_state_machine_test.go +++ b/aws/resource_aws_sfn_state_machine_test.go @@ -57,7 +57,7 @@ func TestAccAWSSfnStateMachine_createUpdate(t *testing.T) { }) } -func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { +func TestAccAWSSfnStateMachine_expressUpdate(t *testing.T) { var sm sfn.DescribeStateMachineOutput name := acctest.RandString(10) @@ -76,8 +76,7 @@ func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { 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"), - resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), - resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "type", "EXPRESS"), ), }, { @@ -89,15 +88,14 @@ func TestAccAWSSfnStateMachine_express_createUpdate(t *testing.T) { 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"), - resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.#", "1"), - resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "logging_configuration.0.level", sfn.LogLevelOff), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "type", "EXPRESS"), ), }, }, }) } -func TestAccAWSSfnStateMachine_standard_createUpdate(t *testing.T) { +func TestAccAWSSfnStateMachine_standardUpdate(t *testing.T) { var sm sfn.DescribeStateMachineOutput name := acctest.RandString(10) @@ -116,6 +114,7 @@ func TestAccAWSSfnStateMachine_standard_createUpdate(t *testing.T) { 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"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "type", "STANDARD"), ), }, { @@ -127,6 +126,7 @@ func TestAccAWSSfnStateMachine_standard_createUpdate(t *testing.T) { 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"), + resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "type", "STANDARD"), ), }, }, @@ -199,7 +199,7 @@ func TestAccAWSSfnStateMachine_disappears(t *testing.T) { }) } -func TestAccAWSSfnStateMachine_express_LoggingConfiguration(t *testing.T) { +func TestAccAWSSfnStateMachine_expressLoggingConfiguration(t *testing.T) { var sm sfn.DescribeStateMachineOutput name := acctest.RandString(10) @@ -209,7 +209,7 @@ func TestAccAWSSfnStateMachine_express_LoggingConfiguration(t *testing.T) { CheckDestroy: testAccCheckAWSSfnStateMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration1(sfn.StateMachineTypeExpress, name, sfn.LogLevelError), + Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration(sfn.StateMachineTypeExpress, name, sfn.LogLevelError), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "status", sfn.StateMachineStatusActive), @@ -223,7 +223,7 @@ func TestAccAWSSfnStateMachine_express_LoggingConfiguration(t *testing.T) { ), }, { - Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration1(sfn.StateMachineTypeExpress, name, sfn.LogLevelAll), + Config: testAccAWSSfnStateMachineExpressConfigLogConfiguration(sfn.StateMachineTypeExpress, name, sfn.LogLevelAll), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSfnExists("aws_sfn_state_machine.foo", &sm), resource.TestCheckResourceAttr("aws_sfn_state_machine.foo", "status", sfn.StateMachineStatusActive), @@ -475,7 +475,7 @@ data "aws_partition" "current" {} data "aws_region" "current" {} resource "aws_iam_role_policy" "iam_policy_for_lambda" { - name = "iam_policy_for_lambda_%s" + name = "iam_policy_for_lambda_%[1]s" role = "${aws_iam_role.iam_for_lambda.id}" policy = < Date: Tue, 2 Feb 2021 22:06:53 -0800 Subject: [PATCH 14/14] Fix formatting --- website/docs/r/sfn_state_machine.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index 0cb2df13867..92f03321730 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -18,7 +18,7 @@ Provides a Step Function State Machine resource resource "aws_sfn_state_machine" "sfn_state_machine" { name = "my-state-machine" - role_arn = "${aws_iam_role.iam_for_sfn.arn}" + role_arn = aws_iam_role.iam_for_sfn.arn definition = <