From f2571a484726d345d9a93e5d26a0bd4131d5a234 Mon Sep 17 00:00:00 2001
From: pazhersh <132351677+pazhersh@users.noreply.github.com>
Date: Mon, 9 Sep 2024 09:40:04 +0300
Subject: [PATCH] Add automation run created and any run change event trigger
support (#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
---
docs/resources/port_action.md | 18 +++++
docs/resources/port_integration.md | 2 -
internal/consts/provider.go | 2 +
port/action/actionStateToPortBody.go | 14 ++++
port/action/model.go | 10 +++
port/action/refreshActionState.go | 12 +++
port/action/resource_test.go | 108 +++++++++++++++++++++++++++
port/action/schema.go | 22 ++++++
8 files changed, 186 insertions(+), 2 deletions(-)
diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md
index f3e6ae2f..b4e5b98f 100644
--- a/docs/resources/port_action.md
+++ b/docs/resources/port_action.md
@@ -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))
@@ -370,6 +372,14 @@ Required:
- `blueprint_identifier` (String) The blueprint identifier of the changed entity
+
+### Nested Schema for `automation_trigger.any_run_change_event`
+
+Required:
+
+- `action_identifier` (String) The action identifier of the changed run
+
+
### Nested Schema for `automation_trigger.entity_created_event`
@@ -406,6 +416,14 @@ Optional:
- `combinator` (String) The combinator of the condition
+
+### Nested Schema for `automation_trigger.run_created_event`
+
+Required:
+
+- `action_identifier` (String) The action identifier of the created run
+
+
### Nested Schema for `automation_trigger.run_updated_event`
diff --git a/docs/resources/port_integration.md b/docs/resources/port_integration.md
index 5f0f6e4b..a682117e 100644
--- a/docs/resources/port_integration.md
+++ b/docs/resources/port_integration.md
@@ -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,
@@ -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,
diff --git a/internal/consts/provider.go b/internal/consts/provider.go
index 58818c04..e35dc8a8 100644
--- a/internal/consts/provider.go
+++ b/internal/consts/provider.go
@@ -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"
)
diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go
index aa5ded25..ce2fa21e 100644
--- a/port/action/actionStateToPortBody.go
+++ b/port/action/actionStateToPortBody.go
@@ -165,6 +165,13 @@ 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,
@@ -172,6 +179,13 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error)
}
}
+ if data.AutomationTrigger.AnyRunChangeEvent != nil {
+ automationTrigger.Event = &cli.TriggerEvent{
+ Type: consts.AnyRunChange,
+ ActionIdentifier: data.AutomationTrigger.AnyRunChangeEvent.ActionIdentifier.ValueStringPointer(),
+ }
+ }
+
return automationTrigger, nil
}
diff --git a/port/action/model.go b/port/action/model.go
index 681619f5..9651ca77 100644
--- a/port/action/model.go
+++ b/port/action/model.go
@@ -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"`
@@ -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"`
}
diff --git a/port/action/refreshActionState.go b/port/action/refreshActionState.go
index 32510fb2..28737d67 100644
--- a/port/action/refreshActionState.go
+++ b/port/action/refreshActionState.go
@@ -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
}
diff --git a/port/action/resource_test.go b/port/action/resource_test.go
index ec238cce..18646c8d 100644
--- a/port/action/resource_test.go
+++ b/port/action/resource_test.go
@@ -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()
@@ -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,
+ },
},
})
}
diff --git a/port/action/schema.go b/port/action/schema.go
index 32b44101..3e8edf22 100644
--- a/port/action/schema.go
+++ b/port/action/schema.go
@@ -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"),
),
},
},
@@ -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,
@@ -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,