Skip to content

Commit a37f2f7

Browse files
authored
Fixes #60 by exposing the action ID as a property. (#65)
1 parent 15d19b9 commit a37f2f7

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

docs/resources/process_step.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ resource "octopusdeploy_process_step" "deploy_package" {
137137

138138
### Read-Only
139139

140+
- `action_id` (String) The ID of the first action created in the step.
140141
- `id` (String) The unique ID for this resource.
141142

142143
<a id="nestedatt--container"></a>

octopusdeploy_framework/resource_process_step.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package octopusdeploy_framework
33
import (
44
"context"
55
"fmt"
6+
"strings"
7+
68
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
79
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
810
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies"
@@ -17,7 +19,6 @@ import (
1719
"github.com/hashicorp/terraform-plugin-framework/types"
1820
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1921
"github.com/hashicorp/terraform-plugin-log/tflog"
20-
"strings"
2122
)
2223

2324
var _ resource.ResourceWithImportState = &processStepResource{}
@@ -505,6 +506,7 @@ func mapProcessStepToState(process processWrapper, step *deployments.DeploymentS
505506
}
506507

507508
func mapProcessStepActionToState(action *deployments.DeploymentAction, state *schemas.ProcessStepResourceModel) diag.Diagnostics {
509+
state.ActionID = types.StringValue(action.GetID())
508510
state.Type = types.StringValue(action.ActionType)
509511
state.Slug = types.StringValue(action.Slug)
510512
state.IsRequired = types.BoolValue(action.IsRequired)

octopusdeploy_framework/resource_process_step_mapping_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package octopusdeploy_framework
22

33
import (
44
"context"
5+
"testing"
6+
57
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
68
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
79
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies"
@@ -12,7 +14,6 @@ import (
1214
"github.com/hashicorp/terraform-plugin-framework/attr"
1315
"github.com/hashicorp/terraform-plugin-framework/types"
1416
"github.com/stretchr/testify/assert"
15-
"testing"
1617
)
1718

1819
func TestAccMapProcessStepFromStateWithAllAttributes(t *testing.T) {
@@ -396,6 +397,7 @@ func TestAccMapProcessStepToStateWithAllAttributes(t *testing.T) {
396397
"Octopus.Action.Script.ScriptBody": types.StringValue("Write-Host \"Step 1, Action 1\""),
397398
}),
398399
}
400+
expectedState.ActionID = types.StringValue(step.Actions[0].ID)
399401
expectedState.ID = types.StringValue(step.ID)
400402

401403
assert.Equal(t, expectedState, state)
@@ -562,6 +564,7 @@ func TestAccMapProcessStepToStateWithAllAttributesForRunbook(t *testing.T) {
562564
}),
563565
}
564566
expectedState.ID = types.StringValue(step.ID)
567+
expectedState.ActionID = types.StringValue(step.Actions[0].ID)
565568

566569
assert.Equal(t, expectedState, state)
567570
}

octopusdeploy_framework/resource_process_step_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package octopusdeploy_framework
22

33
import (
44
"fmt"
5+
"testing"
6+
57
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
68
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
79
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
810
"github.com/hashicorp/terraform-plugin-testing/terraform"
9-
"testing"
1011
)
1112

1213
func TestAccOctopusDeployProcessStepRunScript(t *testing.T) {
@@ -69,6 +70,7 @@ func testCheckResourceProcessStepRunScriptAttributes(step string, script string)
6970
return resource.ComposeTestCheckFunc(
7071
resource.TestCheckResourceAttrSet(qualifiedName, "id"),
7172
resource.TestCheckResourceAttr(qualifiedName, "name", step),
73+
resource.TestCheckResourceAttrSet(qualifiedName, "action_id"),
7274
resource.TestCheckResourceAttr(qualifiedName, "type", "Octopus.Script"),
7375
resource.TestCheckResourceAttr(qualifiedName, "properties.Octopus.Action.TargetRoles", "role-one"),
7476
resource.TestCheckResourceAttr(qualifiedName, "execution_properties.Octopus.Action.RunOnServer", "True"),

octopusdeploy_framework/schemas/process_step.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (p ProcessStepSchema) GetResourceSchema() resourceSchema.Schema {
5858
DefaultEmpty().
5959
Build(),
6060

61+
"action_id": util.ResourceString().
62+
Description("The ID of the first action created in the step.").
63+
Computed().
64+
PlanModifiers(stringplanmodifier.UseStateForUnknown()).
65+
Build(),
6166
"type": util.ResourceString().
6267
Description("Execution type of the step.").
6368
Required().
@@ -150,6 +155,7 @@ type ProcessStepResourceModel struct {
150155
Condition types.String `tfsdk:"condition"`
151156
Properties types.Map `tfsdk:"properties"`
152157

158+
ActionID types.String `tfsdk:"action_id"`
153159
Type types.String `tfsdk:"type"`
154160
Slug types.String `tfsdk:"slug"`
155161
IsDisabled types.Bool `tfsdk:"is_disabled"`

0 commit comments

Comments
 (0)