Skip to content

Commit

Permalink
Add automation run created and any run change event trigger support (#…
Browse files Browse the repository at this point in the history
…177)

* added models and schemas for the new `RUN_CREATED` and `ANY_RUN_CHANGE` automation events

* added tests for the new event types

* updated docs with the new event types
  • Loading branch information
pazhersh authored Sep 9, 2024
1 parent 99381ce commit f2571a4
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/resources/port_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ Optional:
Optional:

- `any_entity_change_event` (Attributes) Any entity change event trigger (see [below for nested schema](#nestedatt--automation_trigger--any_entity_change_event))
- `any_run_change_event` (Attributes) Any run change event trigger (see [below for nested schema](#nestedatt--automation_trigger--any_run_change_event))
- `entity_created_event` (Attributes) Entity created event trigger (see [below for nested schema](#nestedatt--automation_trigger--entity_created_event))
- `entity_deleted_event` (Attributes) Entity deleted event trigger (see [below for nested schema](#nestedatt--automation_trigger--entity_deleted_event))
- `entity_updated_event` (Attributes) Entity updated event trigger (see [below for nested schema](#nestedatt--automation_trigger--entity_updated_event))
- `jq_condition` (Attributes) JQ condition for automation trigger (see [below for nested schema](#nestedatt--automation_trigger--jq_condition))
- `run_created_event` (Attributes) Run created event trigger (see [below for nested schema](#nestedatt--automation_trigger--run_created_event))
- `run_updated_event` (Attributes) Run updated event trigger (see [below for nested schema](#nestedatt--automation_trigger--run_updated_event))
- `timer_property_expired_event` (Attributes) Timer property expired event trigger (see [below for nested schema](#nestedatt--automation_trigger--timer_property_expired_event))

Expand All @@ -370,6 +372,14 @@ Required:
- `blueprint_identifier` (String) The blueprint identifier of the changed entity


<a id="nestedatt--automation_trigger--any_run_change_event"></a>
### Nested Schema for `automation_trigger.any_run_change_event`

Required:

- `action_identifier` (String) The action identifier of the changed run


<a id="nestedatt--automation_trigger--entity_created_event"></a>
### Nested Schema for `automation_trigger.entity_created_event`

Expand Down Expand Up @@ -406,6 +416,14 @@ Optional:
- `combinator` (String) The combinator of the condition


<a id="nestedatt--automation_trigger--run_created_event"></a>
### Nested Schema for `automation_trigger.run_created_event`

Required:

- `action_identifier` (String) The action identifier of the created run


<a id="nestedatt--automation_trigger--run_updated_event"></a>
### Nested Schema for `automation_trigger.run_updated_event`

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/port_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ description: |-
resource "portintegration" "mycustomintegration" {
installationid = "my-custom-integration-id"
title = "My Custom Integration"
version = "1.33.7" # Optional, can be omitted
config = jsonencode({
createMissingRelatedEntitiesboolean = true
deleteDependentEntities = true,
Expand Down Expand Up @@ -56,7 +55,6 @@ Docs about how to import existing integrations and manage their mappings can be
resource "port_integration" "my_custom_integration" {
installation_id = "my-custom-integration-id"
title = "My Custom Integration"
version = "1.33.7" # Optional, can be omitted
config = jsonencode({
createMissingRelatedEntitiesboolean = true
deleteDependentEntities = true,
Expand Down
2 changes: 2 additions & 0 deletions internal/consts/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
EntityDeleted = "ENTITY_DELETED"
TimerPropertyExpired = "TIMER_PROPERTY_EXPIRED"
AnyEntityChange = "ANY_ENTITY_CHANGE"
RunCreated = "RUN_CREATED"
RunUpdated = "RUN_UPDATED"
AnyRunChange = "ANY_RUN_CHANGE"
JqCondition = "JQ"
)
14 changes: 14 additions & 0 deletions port/action/actionStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,27 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error)
}
}

if data.AutomationTrigger.RunCreatedEvent != nil {
automationTrigger.Event = &cli.TriggerEvent{
Type: consts.RunCreated,
ActionIdentifier: data.AutomationTrigger.RunCreatedEvent.ActionIdentifier.ValueStringPointer(),
}
}

if data.AutomationTrigger.RunUpdatedEvent != nil {
automationTrigger.Event = &cli.TriggerEvent{
Type: consts.RunUpdated,
ActionIdentifier: data.AutomationTrigger.RunUpdatedEvent.ActionIdentifier.ValueStringPointer(),
}
}

if data.AutomationTrigger.AnyRunChangeEvent != nil {
automationTrigger.Event = &cli.TriggerEvent{
Type: consts.AnyRunChange,
ActionIdentifier: data.AutomationTrigger.AnyRunChangeEvent.ActionIdentifier.ValueStringPointer(),
}
}

return automationTrigger, nil
}

Expand Down
10 changes: 10 additions & 0 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,18 @@ type TimerPropertyExpiredEventModel struct {
PropertyIdentifier types.String `tfsdk:"property_identifier"`
}

type RunCreatedEvent struct {
ActionIdentifier types.String `tfsdk:"action_identifier"`
}

type RunUpdatedEvent struct {
ActionIdentifier types.String `tfsdk:"action_identifier"`
}

type AnyRunChangeEvent struct {
ActionIdentifier types.String `tfsdk:"action_identifier"`
}

type JqConditionModel struct {
Expressions []types.String `tfsdk:"expressions"`
Combinator types.String `tfsdk:"combinator"`
Expand All @@ -321,7 +329,9 @@ type AutomationTriggerModel struct {
EntityDeletedEvent *EntityDeletedEventModel `tfsdk:"entity_deleted_event"`
AnyEntityChangeEvent *AnyEntityChangeEventModel `tfsdk:"any_entity_change_event"`
TimerPropertyExpiredEvent *TimerPropertyExpiredEventModel `tfsdk:"timer_property_expired_event"`
RunCreatedEvent *RunCreatedEvent `tfsdk:"run_created_event"`
RunUpdatedEvent *RunUpdatedEvent `tfsdk:"run_updated_event"`
AnyRunChangeEvent *AnyRunChangeEvent `tfsdk:"any_run_change_event"`
JqCondition *JqConditionModel `tfsdk:"jq_condition"`
}

Expand Down
12 changes: 12 additions & 0 deletions port/action/refreshActionState.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,24 @@ func writeTriggerToResource(ctx context.Context, a *cli.Action, state *ActionMod
}
}

if a.Trigger.Event.Type == consts.RunCreated {
automationTrigger.RunCreatedEvent = &RunCreatedEvent{
ActionIdentifier: types.StringValue(*a.Trigger.Event.ActionIdentifier),
}
}

if a.Trigger.Event.Type == consts.RunUpdated {
automationTrigger.RunUpdatedEvent = &RunUpdatedEvent{
ActionIdentifier: types.StringValue(*a.Trigger.Event.ActionIdentifier),
}
}

if a.Trigger.Event.Type == consts.AnyRunChange {
automationTrigger.AnyRunChangeEvent = &AnyRunChangeEvent{
ActionIdentifier: types.StringValue(*a.Trigger.Event.ActionIdentifier),
}
}

state.AutomationTrigger = automationTrigger
}

Expand Down
108 changes: 108 additions & 0 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,57 @@ func TestAccPortAutomationTimerPropertyExpired(t *testing.T) {
})
}

func TestAccPortAutomationRunCreated(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "self_serve_action" {
title = "self serve action"
identifier = "self_serve_action"
icon = "Terraform"
self_service_trigger = {
operation = "CREATE"
user_properties = {
}
}
kafka_method = {}
}
resource "port_action" "create_microservice" {
title = "TF Provider Test"
identifier = "%s"
icon = "Terraform"
automation_trigger = {
run_created_event = {
action_identifier = "self_serve_action"
}
}
kafka_method = {}
depends_on = [port_action.self_serve_action]
}`, actionIdentifier)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_action.create_microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_created_event.action_identifier", "self_serve_action"),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
},
},
})
}

func TestAccPortAutomationRunUpdated(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
Expand Down Expand Up @@ -1609,6 +1660,63 @@ func TestAccPortAutomationRunUpdated(t *testing.T) {
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_updated_event.action_identifier", "self_serve_action"),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
},
},
})
}

func TestAccPortAutomationAnyRunChange(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "self_serve_action" {
title = "self serve action"
identifier = "self_serve_action"
icon = "Terraform"
self_service_trigger = {
operation = "CREATE"
user_properties = {
}
}
kafka_method = {}
}
resource "port_action" "create_microservice" {
title = "TF Provider Test"
identifier = "%s"
icon = "Terraform"
automation_trigger = {
any_run_change_event = {
action_identifier = "self_serve_action"
}
}
kafka_method = {}
depends_on = [port_action.self_serve_action]
}`, actionIdentifier)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_action.create_microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.any_run_change_event.action_identifier", "self_serve_action"),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
},
},
})
}
Expand Down
22 changes: 22 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ func ActionSchema() map[string]schema.Attribute {
path.MatchRelative().AtParent().AtName("entity_deleted_event"),
path.MatchRelative().AtParent().AtName("any_entity_change_event"),
path.MatchRelative().AtParent().AtName("timer_property_expired_event"),
path.MatchRelative().AtParent().AtName("run_created_event"),
path.MatchRelative().AtParent().AtName("run_updated_event"),
path.MatchRelative().AtParent().AtName("any_run_change_event"),
),
},
},
Expand Down Expand Up @@ -209,6 +211,16 @@ func ActionSchema() map[string]schema.Attribute {
},
},
},
"run_created_event": schema.SingleNestedAttribute{
MarkdownDescription: "Run created event trigger",
Optional: true,
Attributes: map[string]schema.Attribute{
"action_identifier": schema.StringAttribute{
MarkdownDescription: "The action identifier of the created run",
Required: true,
},
},
},
"run_updated_event": schema.SingleNestedAttribute{
MarkdownDescription: "Run updated event trigger",
Optional: true,
Expand All @@ -219,6 +231,16 @@ func ActionSchema() map[string]schema.Attribute {
},
},
},
"any_run_change_event": schema.SingleNestedAttribute{
MarkdownDescription: "Any run change event trigger",
Optional: true,
Attributes: map[string]schema.Attribute{
"action_identifier": schema.StringAttribute{
MarkdownDescription: "The action identifier of the changed run",
Required: true,
},
},
},
"jq_condition": schema.SingleNestedAttribute{
MarkdownDescription: "JQ condition for automation trigger",
Optional: true,
Expand Down

0 comments on commit f2571a4

Please sign in to comment.