Skip to content

Commit

Permalink
r/aws_sfn_state_machine: Cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jul 29, 2024
1 parent 16fc9b8 commit 1604008
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions internal/service/sfn/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func resourceStateMachine() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrKMSKeyID: {
Type: schema.TypeString,
Optional: true,
},
"kms_data_key_reuse_period_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(60, 900),
},
names.AttrKMSKeyID: {
Type: schema.TypeString,
Optional: true,
},
names.AttrType: {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -142,23 +142,23 @@ func resourceStateMachine() *schema.Resource {
Default: false,
Optional: true,
},
"revision_id": {
Type: schema.TypeString,
Computed: true,
},
names.AttrRoleARN: {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidARN,
},
"revision_id": {
"state_machine_version_arn": {
Type: schema.TypeString,
Computed: true,
},
names.AttrStatus: {
Type: schema.TypeString,
Computed: true,
},
"state_machine_version_arn": {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"tracing_configuration": {
Expand Down Expand Up @@ -207,14 +207,14 @@ func resourceStateMachineCreate(ctx context.Context, d *schema.ResourceData, met
Type: awstypes.StateMachineType(d.Get(names.AttrType).(string)),
}

if v, ok := d.GetOk(names.AttrLoggingConfiguration); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.LoggingConfiguration = expandLoggingConfiguration(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk(names.AttrEncryptionConfiguration); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.EncryptionConfiguration = expandEncryptionConfiguration(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk(names.AttrLoggingConfiguration); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.LoggingConfiguration = expandLoggingConfiguration(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk("tracing_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.TracingConfiguration = expandTracingConfiguration(v.([]interface{})[0].(map[string]interface{}))
}
Expand All @@ -231,8 +231,7 @@ func resourceStateMachineCreate(ctx context.Context, d *schema.ResourceData, met
return sdkdiag.AppendErrorf(diags, "creating Step Functions State Machine (%s): %s", name, err)
}

arn := aws.ToString(outputRaw.(*sfn.CreateStateMachineOutput).StateMachineArn)
d.SetId(arn)
d.SetId(aws.ToString(outputRaw.(*sfn.CreateStateMachineOutput).StateMachineArn))

return append(diags, resourceStateMachineRead(ctx, d, meta)...)
}
Expand Down Expand Up @@ -261,27 +260,25 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta
}
d.Set("definition", output.Definition)
d.Set(names.AttrDescription, output.Description)
if output.LoggingConfiguration != nil {
if err := d.Set(names.AttrLoggingConfiguration, []interface{}{flattenLoggingConfiguration(output.LoggingConfiguration)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting logging_configuration: %s", err)
}
} else {
d.Set(names.AttrLoggingConfiguration, nil)
}

if output.EncryptionConfiguration != nil {
if err := d.Set(names.AttrEncryptionConfiguration, []interface{}{flattenEncryptionConfiguration(output.EncryptionConfiguration)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting encryption_configuration: %s", err)
}
} else {
d.Set(names.AttrEncryptionConfiguration, nil)
}

if output.LoggingConfiguration != nil {
if err := d.Set(names.AttrLoggingConfiguration, []interface{}{flattenLoggingConfiguration(output.LoggingConfiguration)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting logging_configuration: %s", err)
}
} else {
d.Set(names.AttrLoggingConfiguration, nil)
}
d.Set(names.AttrName, output.Name)
d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(output.Name)))
d.Set("publish", d.Get("publish").(bool))
d.Set(names.AttrRoleARN, output.RoleArn)
d.Set("revision_id", output.RevisionId)
d.Set(names.AttrRoleARN, output.RoleArn)
d.Set(names.AttrStatus, output.Status)
if output.TracingConfiguration != nil {
if err := d.Set("tracing_configuration", []interface{}{flattenTracingConfiguration(output.TracingConfiguration)}); err != nil {
Expand Down Expand Up @@ -318,15 +315,18 @@ func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, met

if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
// "You must include at least one of definition or roleArn or you will receive a MissingRequiredParameter error"
publish := d.Get("publish").(bool)
input := &sfn.UpdateStateMachineInput{
Definition: aws.String(d.Get("definition").(string)),
Publish: publish,
RoleArn: aws.String(d.Get(names.AttrRoleARN).(string)),
StateMachineArn: aws.String(d.Id()),
Publish: d.Get("publish").(bool),
}

if v, ok := d.GetOk("publish"); ok && v == true {
input.VersionDescription = aws.String(d.Get("version_description").(string))
if d.HasChange(names.AttrEncryptionConfiguration) {
if v, ok := d.GetOk(names.AttrEncryptionConfiguration); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.EncryptionConfiguration = expandEncryptionConfiguration(v.([]interface{})[0].(map[string]interface{}))
}
}

if d.HasChange(names.AttrLoggingConfiguration) {
Expand All @@ -335,18 +335,16 @@ func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, met
}
}

if d.HasChange(names.AttrEncryptionConfiguration) {
if v, ok := d.GetOk(names.AttrEncryptionConfiguration); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.EncryptionConfiguration = expandEncryptionConfiguration(v.([]interface{})[0].(map[string]interface{}))
}
}

if d.HasChange("tracing_configuration") {
if v, ok := d.GetOk("tracing_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.TracingConfiguration = expandTracingConfiguration(v.([]interface{})[0].(map[string]interface{}))
}
}

if publish {
input.VersionDescription = aws.String(d.Get("version_description").(string))
}

_, err := conn.UpdateStateMachine(ctx, input)

if err != nil {
Expand Down

0 comments on commit 1604008

Please sign in to comment.