Skip to content

Commit d3149d7

Browse files
authored
Add support for order in action (#62)
1 parent da9b228 commit d3149d7

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

docs/resources/port_action.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Action resource
3232
- `gitlab_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--gitlab_method))
3333
- `icon` (String) Icon
3434
- `kafka_method` (Object) The invocation method of the action (see [below for nested schema](#nestedatt--kafka_method))
35+
- `order_properties` (List of String) Order properties
3536
- `required_approval` (Boolean) Require approval before invoking the action
3637
- `user_properties` (Attributes) User properties (see [below for nested schema](#nestedatt--user_properties))
3738
- `webhook_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--webhook_method))

internal/cli/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type (
158158
ActionUserInputs = struct {
159159
Properties map[string]ActionProperty `json:"properties"`
160160
Required []string `json:"required,omitempty"`
161+
Order []string `json:"order,omitempty"`
161162
}
162163

163164
Blueprint struct {

port/action/actionStateToPortBody.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/port-labs/terraform-provider-port-labs/internal/cli"
77
"github.com/port-labs/terraform-provider-port-labs/internal/consts"
8+
"github.com/port-labs/terraform-provider-port-labs/internal/utils"
89
)
910

1011
func actionDataSetToPortBody(dataSet *DatasetModel) *cli.Dataset {
@@ -85,6 +86,15 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel, bp *cli.Bluep
8586
action.UserInputs.Properties = make(map[string]cli.ActionProperty)
8687
}
8788

89+
if !data.OrderProperties.IsNull() {
90+
order, err := utils.TerraformListToGoArray(ctx, data.OrderProperties, "string")
91+
if err != nil {
92+
return nil, err
93+
}
94+
orderString := utils.InterfaceToStringArray(order)
95+
action.UserInputs.Order = orderString
96+
}
97+
8898
return action, nil
8999
}
90100

port/action/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ type ActionModel struct {
165165
UserProperties *UserPropertiesModel `tfsdk:"user_properties"`
166166
ApprovalWebhookNotification *ApprovalWebhookNotificationModel `tfsdk:"approval_webhook_notification"`
167167
ApprovalEmailNotification types.Object `tfsdk:"approval_email_notification"`
168+
OrderProperties types.List `tfsdk:"order_properties"`
168169
}

port/action/refreshActionState.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode
190190
}
191191
}
192192
state.UserProperties = properties
193+
if len(a.UserInputs.Order) > 0 {
194+
state.OrderProperties = flex.GoArrayStringToTerraformList(ctx, a.UserInputs.Order)
195+
}
193196
}
194197
return nil
195198
}

port/action/resource_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,50 @@ func TestAccPortActionJqDefault(t *testing.T) {
585585
})
586586

587587
}
588+
589+
func TestAccPortActionOrderProperties(t *testing.T) {
590+
identifier := utils.GenID()
591+
actionIdentifier := utils.GenID()
592+
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
593+
resource "port_action" "action1" {
594+
title = "Action 1"
595+
identifier = "%s"
596+
icon = "Terraform"
597+
blueprint = port_blueprint.microservice.id
598+
trigger = "DAY-2"
599+
kafka_method = {}
600+
order_properties = ["myStringIdentifier2", "myStringIdentifier1"]
601+
user_properties = {
602+
string_props = {
603+
myStringIdentifier1 = {
604+
title = "myStringIdentifier1"
605+
required = false
606+
}
607+
myStringIdentifier2 = {
608+
title = "myStringIdentifier2"
609+
required = false
610+
}
611+
}
612+
}
613+
}`, actionIdentifier)
614+
615+
resource.Test(t, resource.TestCase{
616+
PreCheck: func() { acctest.TestAccPreCheck(t) },
617+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
618+
619+
Steps: []resource.TestStep{
620+
{
621+
Config: acctest.ProviderConfig + testAccActionConfigCreate,
622+
Check: resource.ComposeTestCheckFunc(
623+
resource.TestCheckResourceAttr("port_action.action1", "title", "Action 1"),
624+
resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier),
625+
resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"),
626+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier1.title", "myStringIdentifier1"),
627+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.title", "myStringIdentifier2"),
628+
resource.TestCheckResourceAttr("port_action.action1", "order_properties.0", "myStringIdentifier2"),
629+
resource.TestCheckResourceAttr("port_action.action1", "order_properties.1", "myStringIdentifier1"),
630+
),
631+
},
632+
},
633+
})
634+
}

port/action/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ func ActionSchema() map[string]schema.Attribute {
230230
},
231231
},
232232
},
233+
"order_properties": schema.ListAttribute{
234+
MarkdownDescription: "Order properties",
235+
Optional: true,
236+
ElementType: types.StringType,
237+
},
233238
"user_properties": schema.SingleNestedAttribute{
234239
MarkdownDescription: "User properties",
235240
Optional: true,

0 commit comments

Comments
 (0)