From 9548614daeea0d53ee1dffd0fa3b541dd06a6b8d Mon Sep 17 00:00:00 2001 From: talsabagport Date: Wed, 10 Jan 2024 20:12:37 +0200 Subject: [PATCH 01/13] Change to new action --- internal/cli/action.go | 20 +- internal/cli/actionPermissions.go | 10 +- internal/cli/models.go | 75 +++- internal/consts/provider.go | 22 +- internal/utils/utils.go | 13 + .../refreshActionPermissionsToState.go | 7 +- port/action-permissions/resource.go | 38 +- port/action-permissions/resource_test.go | 52 +-- port/action-permissions/schema.go | 14 +- port/action/actionStateToPortBody.go | 271 ++++++++---- port/action/array.go | 2 +- port/action/boolean.go | 2 +- port/action/model.go | 131 ++++-- port/action/number.go | 2 +- port/action/object.go | 2 +- port/action/refreshActionState.go | 237 ++++++++--- port/action/resource.go | 59 ++- port/action/schema.go | 395 ++++++++++++++---- port/action/string.go | 2 +- 19 files changed, 955 insertions(+), 399 deletions(-) diff --git a/internal/cli/action.go b/internal/cli/action.go index 69ab5e45..9cb6bbd1 100644 --- a/internal/cli/action.go +++ b/internal/cli/action.go @@ -6,14 +6,13 @@ import ( "fmt" ) -func (c *PortClient) ReadAction(ctx context.Context, blueprintID, id string) (*Action, int, error) { +func (c *PortClient) ReadAction(ctx context.Context, id string) (*Action, int, error) { pb := &PortBody{} - url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}" + url := "v1/actions/{action_identifier}" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). SetResult(pb). - SetPathParam("blueprint_identifier", blueprintID). SetPathParam("action_identifier", id). Get(url) if err != nil { @@ -25,11 +24,10 @@ func (c *PortClient) ReadAction(ctx context.Context, blueprintID, id string) (*A return &pb.Action, resp.StatusCode(), nil } -func (c *PortClient) CreateAction(ctx context.Context, blueprintID string, action *Action) (*Action, error) { - url := "v1/blueprints/{blueprint_identifier}/actions" +func (c *PortClient) CreateAction(ctx context.Context, action *Action) (*Action, error) { + url := "v1/actions" resp, err := c.Client.R(). SetBody(action). - SetPathParam("blueprint_identifier", blueprintID). SetContext(ctx). Post(url) if err != nil { @@ -46,12 +44,11 @@ func (c *PortClient) CreateAction(ctx context.Context, blueprintID string, actio return &pb.Action, nil } -func (c *PortClient) UpdateAction(ctx context.Context, blueprintID, actionID string, action *Action) (*Action, error) { - url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}" +func (c *PortClient) UpdateAction(ctx context.Context, actionID string, action *Action) (*Action, error) { + url := "v1/actions/{action_identifier}" resp, err := c.Client.R(). SetBody(action). SetContext(ctx). - SetPathParam("blueprint_identifier", blueprintID). SetPathParam("action_identifier", actionID). Put(url) if err != nil { @@ -68,12 +65,11 @@ func (c *PortClient) UpdateAction(ctx context.Context, blueprintID, actionID str return &pb.Action, nil } -func (c *PortClient) DeleteAction(ctx context.Context, blueprintID string, actionID string) error { - url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}" +func (c *PortClient) DeleteAction(ctx context.Context, actionID string) error { + url := "v1/actions/{action_identifier}" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). - SetPathParam("blueprint_identifier", blueprintID). SetPathParam("action_identifier", actionID). Delete(url) if err != nil { diff --git a/internal/cli/actionPermissions.go b/internal/cli/actionPermissions.go index 4d34a1e1..d249d581 100644 --- a/internal/cli/actionPermissions.go +++ b/internal/cli/actionPermissions.go @@ -6,14 +6,13 @@ import ( "fmt" ) -func (c *PortClient) GetActionPermissions(ctx context.Context, blueprintID string, actionID string) (*ActionPermissions, int, error) { +func (c *PortClient) GetActionPermissions(ctx context.Context, actionID string) (*ActionPermissions, int, error) { pb := &PortBody{} - url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}/permissions" + url := "v1/actions/{action_identifier}/permissions" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). SetResult(pb). - SetPathParam("blueprint_identifier", blueprintID). SetPathParam("action_identifier", actionID). Get(url) if err != nil { @@ -26,13 +25,12 @@ func (c *PortClient) GetActionPermissions(ctx context.Context, blueprintID strin } -func (c *PortClient) UpdateActionPermissions(ctx context.Context, blueprintID string, actionID string, permissions *ActionPermissions) (*ActionPermissions, error) { - url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}/permissions" +func (c *PortClient) UpdateActionPermissions(ctx context.Context, actionID string, permissions *ActionPermissions) (*ActionPermissions, error) { + url := "v1/actions/{action_identifier}/permissions" resp, err := c.Client.R(). SetBody(permissions). SetContext(ctx). - SetPathParam("blueprint_identifier", blueprintID). SetPathParam("action_identifier", actionID). Patch(url) if err != nil { diff --git a/internal/cli/models.go b/internal/cli/models.go index 4876060e..a7e74e6e 100644 --- a/internal/cli/models.go +++ b/internal/cli/models.go @@ -125,22 +125,32 @@ type ( } InvocationMethod struct { - Type string `json:"type,omitempty"` - Url *string `json:"url,omitempty"` - Agent *bool `json:"agent,omitempty"` - Synchronized *bool `json:"synchronized,omitempty"` - Method *string `json:"method,omitempty"` - Org *string `json:"org,omitempty"` - Repo *string `json:"repo,omitempty"` - Webhook *string `json:"webhook,omitempty"` - Workflow *string `json:"workflow,omitempty"` - OmitPayload *bool `json:"omitPayload,omitempty"` - OmitUserInputs *bool `json:"omitUserInputs,omitempty"` - ReportWorkflowStatus *bool `json:"reportWorkflowStatus,omitempty"` - Branch *string `json:"branch,omitempty"` - ProjectName *string `json:"projectName,omitempty"` - GroupName *string `json:"groupName,omitempty"` - DefaultRef *string `json:"defaultRef,omitempty"` + Type string `json:"type"` + Payload any `json:"payload,omitempty"` + Url *string `json:"url,omitempty"` + Agent any `json:"agent,omitempty"` + Synchronized any `json:"synchronized,omitempty"` + Method *string `json:"method,omitempty"` + Headers map[string]string `json:"headers,omitempty"` + Body any `json:"body,omitempty"` + Org *string `json:"org,omitempty"` + Repo *string `json:"repo,omitempty"` + Workflow *string `json:"workflow,omitempty"` + WorkflowInputs map[string]any `json:"workflow_inputs,omitempty"` + ReportWorkflowStatus any `json:"reportWorkflowStatus,omitempty"` + Branch *string `json:"branch,omitempty"` + ProjectName *string `json:"projectName,omitempty"` + GroupName *string `json:"groupName,omitempty"` + DefaultRef *string `json:"defaultRef,omitempty"` + PipelineVariables map[string]any `json:"pipelineVariables,omitempty"` + Webhook *string `json:"webhook,omitempty"` + Identifier *string `json:"identifier,omitempty"` + Title *string `json:"title,omitempty"` + BlueprintIdentifier *string `json:"blueprintIdentifier,omitempty"` + Team any `json:"team,omitempty"` + Icon *string `json:"icon,omitempty"` + Properties map[string]any `json:"properties,omitempty"` + Relations map[string]any `json:"relations,omitempty"` } ApprovalNotification struct { @@ -165,6 +175,27 @@ type ( Order []string `json:"order,omitempty"` } + TriggerEvent struct { + Type string `json:"type"` + BlueprintIdentifier *string `json:"blueprintIdentifier,omitempty"` + PropertyIdentifier *string `json:"propertyIdentifier,omitempty"` + } + + TriggerCondition struct { + Type string `json:"type"` + Expressions []string `json:"expressions"` + Combinator *string `json:"combinator,omitempty"` + } + + Trigger struct { + Type string `json:"type"` + BlueprintIdentifier *string `json:"blueprintIdentifier,omitempty"` + Operation *string `json:"operation,omitempty"` + UserInputs ActionUserInputs `json:"userInputs,omitempty"` + Event *TriggerEvent `json:"event,omitempty"` + Condition *TriggerCondition `json:"condition,omitempty"` + } + Blueprint struct { Meta Identifier string `json:"identifier,omitempty"` @@ -181,15 +212,15 @@ type ( Action struct { ID string `json:"id,omitempty"` - Identifier string `json:"identifier,omitempty"` - Description *string `json:"description,omitempty"` - Title string `json:"title,omitempty"` + Identifier string `json:"identifier"` + Title *string `json:"title,omitempty"` Icon *string `json:"icon,omitempty"` - UserInputs ActionUserInputs `json:"userInputs"` - Trigger string `json:"trigger"` - RequiredApproval *bool `json:"requiredApproval,omitempty"` + Description *string `json:"description,omitempty"` + Trigger *Trigger `json:"trigger"` InvocationMethod *InvocationMethod `json:"invocationMethod,omitempty"` + RequiredApproval *bool `json:"requiredApproval,omitempty"` ApprovalNotification *ApprovalNotification `json:"approvalNotification,omitempty"` + Publish *bool `json:"publish,omitempty"` } ActionExecutePermissions struct { diff --git a/internal/consts/provider.go b/internal/consts/provider.go index c472f1eb..9b539bed 100644 --- a/internal/consts/provider.go +++ b/internal/consts/provider.go @@ -1,11 +1,19 @@ package consts const ( - ProviderName = "port" - DefaultBaseUrl = "https://api.getport.io" - Webhook = "WEBHOOK" - Kafka = "KAFKA" - AzureDevops = "AZURE-DEVOPS" - Github = "GITHUB" - Gitlab = "GITLAB" + ProviderName = "port" + DefaultBaseUrl = "https://api.getport.io" + Kafka = "KAFKA" + Webhook = "WEBHOOK" + Github = "GITHUB" + Gitlab = "GITLAB" + AzureDevops = "AZURE_DEVOPS" + UpsertEntity = "UPSERT_ENTITY" + SelfService = "self-service" + Automation = "automation" + EntityCreated = "ENTITY_CREATED" + EntityUpdated = "ENTITY_UPDATED" + EntityDeleted = "ENTITY_DELETED" + TimerPropertyExpired = "TIMER_PROPERTY_EXPIRED" + AnyEntityChange = "ANY_ENTITY_CHANGE" ) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 6b01876f..603b4036 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -85,6 +85,19 @@ func GoObjectToTerraformString(v interface{}) (types.String, error) { return types.StringValue(value), nil } +func TerraformStringToGoObject(s types.String) (interface{}, error) { + if s.IsNull() { + return nil, nil + } + + var obj interface{} + if err := json.Unmarshal([]byte(s.ValueString()), &obj); err != nil { + return nil, err + } + + return obj, nil +} + func InterfaceToStringArray(o interface{}) []string { items := o.([]interface{}) res := make([]string, len(items)) diff --git a/port/action-permissions/refreshActionPermissionsToState.go b/port/action-permissions/refreshActionPermissionsToState.go index cef62252..791c27d7 100644 --- a/port/action-permissions/refreshActionPermissionsToState.go +++ b/port/action-permissions/refreshActionPermissionsToState.go @@ -3,16 +3,15 @@ package action_permissions import ( "context" "encoding/json" - "fmt" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/port-labs/terraform-provider-port-labs/internal/cli" "github.com/port-labs/terraform-provider-port-labs/internal/flex" ) -func refreshActionPermissionsState(ctx context.Context, state *ActionPermissionsModel, a *cli.ActionPermissions, blueprintId string, actionId string) error { - state.ID = types.StringValue(fmt.Sprintf("%s:%s", blueprintId, actionId)) +func refreshActionPermissionsState(ctx context.Context, state *ActionPermissionsModel, a *cli.ActionPermissions, actionId string) error { + state.ID = types.StringValue(actionId) state.ActionIdentifier = types.StringValue(actionId) - state.BlueprintIdentifier = types.StringValue(blueprintId) + state.BlueprintIdentifier = types.StringNull() state.Permissions = &PermissionsModel{} state.Permissions.Execute = &ExecuteModel{} diff --git a/port/action-permissions/resource.go b/port/action-permissions/resource.go index 5d30804c..098fcd5f 100644 --- a/port/action-permissions/resource.go +++ b/port/action-permissions/resource.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/port-labs/terraform-provider-port-labs/internal/cli" - "strings" ) var _ resource.Resource = &ActionPermissionsResource{} @@ -34,15 +33,7 @@ func (r *ActionPermissionsResource) Configure(ctx context.Context, req resource. } func (r *ActionPermissionsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - idParts := strings.Split(req.ID, ":") - - if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { - resp.Diagnostics.AddError("invalid import ID", "import ID must be in the format :") - return - } - - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("blueprint_identifier"), idParts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("action_identifier"), idParts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("action_identifier"), req.ID)...) } func (r *ActionPermissionsResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { @@ -56,8 +47,11 @@ func (r *ActionPermissionsResource) Read(ctx context.Context, req resource.ReadR blueprintIdentifier := state.BlueprintIdentifier.ValueString() actionIdentifier := state.ActionIdentifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) + } - a, statusCode, err := r.portClient.GetActionPermissions(ctx, blueprintIdentifier, actionIdentifier) + a, statusCode, err := r.portClient.GetActionPermissions(ctx, actionIdentifier) if err != nil { resp.Diagnostics.AddError("failed to read action permissions", err.Error()) return @@ -68,7 +62,7 @@ func (r *ActionPermissionsResource) Read(ctx context.Context, req resource.ReadR return } - err = refreshActionPermissionsState(ctx, state, a, blueprintIdentifier, actionIdentifier) + err = refreshActionPermissionsState(ctx, state, a, actionIdentifier) if err != nil { resp.Diagnostics.AddError("failed to refresh action permissions state", err.Error()) return @@ -89,6 +83,9 @@ func (r *ActionPermissionsResource) Update(ctx context.Context, req resource.Upd blueprintIdentifier := state.BlueprintIdentifier.ValueString() actionIdentifier := state.ActionIdentifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) + } permissions, err := actionPermissionsToPortBody(state.Permissions) if err != nil { @@ -96,22 +93,22 @@ func (r *ActionPermissionsResource) Update(ctx context.Context, req resource.Upd return } - a, err := r.portClient.UpdateActionPermissions(ctx, blueprintIdentifier, actionIdentifier, permissions) + a, err := r.portClient.UpdateActionPermissions(ctx, actionIdentifier, permissions) if err != nil { resp.Diagnostics.AddError("failed to update action permissions", err.Error()) return } - err = refreshActionPermissionsState(ctx, state, a, blueprintIdentifier, actionIdentifier) + err = refreshActionPermissionsState(ctx, state, a, actionIdentifier) if err != nil { resp.Diagnostics.AddError("failed to refresh action permissions state", err.Error()) return } - state.ID = types.StringValue(fmt.Sprintf("%s:%s", blueprintIdentifier, actionIdentifier)) + state.ID = types.StringValue(actionIdentifier) state.ActionIdentifier = types.StringValue(actionIdentifier) - state.BlueprintIdentifier = types.StringValue(blueprintIdentifier) + state.BlueprintIdentifier = types.StringNull() resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } @@ -137,6 +134,9 @@ func (r *ActionPermissionsResource) Create(ctx context.Context, req resource.Cre blueprintIdentifier := state.BlueprintIdentifier.ValueString() actionIdentifier := state.ActionIdentifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) + } permissions, err := actionPermissionsToPortBody(state.Permissions) if err != nil { @@ -144,16 +144,16 @@ func (r *ActionPermissionsResource) Create(ctx context.Context, req resource.Cre return } - _, err = r.portClient.UpdateActionPermissions(ctx, blueprintIdentifier, actionIdentifier, permissions) + _, err = r.portClient.UpdateActionPermissions(ctx, actionIdentifier, permissions) if err != nil { resp.Diagnostics.AddError("failed to update action permissions", err.Error()) return } - state.ID = types.StringValue(fmt.Sprintf("%s:%s", blueprintIdentifier, actionIdentifier)) + state.ID = types.StringValue(actionIdentifier) state.ActionIdentifier = types.StringValue(actionIdentifier) - state.BlueprintIdentifier = types.StringValue(blueprintIdentifier) + state.BlueprintIdentifier = types.StringNull() resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) diff --git a/port/action-permissions/resource_test.go b/port/action-permissions/resource_test.go index d6f38e44..5f30e579 100644 --- a/port/action-permissions/resource_test.go +++ b/port/action-permissions/resource_test.go @@ -39,8 +39,7 @@ func TestAccPortActionPermissionsBasic(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -64,8 +63,7 @@ func TestAccPortActionPermissionsBasic(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -86,8 +84,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { teamName := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -112,14 +109,13 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { } resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ "Member", ], - "users": ["devops-port@port-test.io"], + "users": ["test-member-user@test.com"], "teams": [port_team.team.name], "owned_by_team": false }, @@ -140,8 +136,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -155,12 +150,11 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "1"), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.0", "devops-port@port-test.io"), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.0", "test-member-user@test.com"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.teams.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.teams.0", teamName), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.owned_by_team", "false"), @@ -179,8 +173,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -228,8 +221,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { var testAccActionPermissionsConfigUpdate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -254,8 +246,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -270,8 +261,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -291,8 +281,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -340,8 +329,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { var testAccActionPermissionsConfigUpdate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -393,8 +381,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -409,8 +396,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -431,8 +417,7 @@ func TestAccPortActionPermissionsImportState(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier + action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" permissions = { "execute": { "roles": [ @@ -484,8 +469,7 @@ func TestAccPortActionPermissionsImportState(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), diff --git a/port/action-permissions/schema.go b/port/action-permissions/schema.go index 94983fba..ac09d919 100644 --- a/port/action-permissions/schema.go +++ b/port/action-permissions/schema.go @@ -2,8 +2,10 @@ package action_permissions import ( "context" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -12,14 +14,16 @@ func ActionPermissionsSchema() map[string]schema.Attribute { "id": schema.StringAttribute{ Computed: true, }, - "blueprint_identifier": schema.StringAttribute{ - Description: "The ID of the blueprint", - Required: true, - }, "action_identifier": schema.StringAttribute{ Description: "The ID of the action", Required: true, }, + "blueprint_identifier": schema.StringAttribute{ + Description: "The ID of the blueprint", + Optional: true, + DeprecationMessage: "Action is not attached to blueprint anymore. This value is ignored", + Validators: []validator.String{stringvalidator.OneOf("")}, + }, "permissions": schema.SingleNestedAttribute{ MarkdownDescription: "The permissions for the action", Optional: true, @@ -100,7 +104,6 @@ Docs for the Action Permissions resource can be found [here](https://docs.getpor ` + "```hcl" + ` resource "port_action_permissions" "restart_microservice_permissions" { action_identifier = port_action.restart_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { "execute": { "roles": [ @@ -130,7 +133,6 @@ To pass a JSON string to Terraform, you can use the [jsonencode](https://develop ` + "```hcl" + ` resource "port_action_permissions" "restart_microservice_permissions" { action_identifier = port_action.restart_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { "execute": { "roles": [ diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index 156ddda9..d7314f44 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -2,6 +2,7 @@ package action import ( "context" + "github.com/port-labs/terraform-provider-port-labs/internal/flex" "github.com/port-labs/terraform-provider-port-labs/internal/cli" "github.com/port-labs/terraform-provider-port-labs/internal/consts" @@ -35,11 +36,14 @@ func actionDataSetToPortBody(dataSet *DatasetModel) *cli.Dataset { return cliDateSet } -func actionStateToPortBody(ctx context.Context, data *ActionModel, bp *cli.Blueprint) (*cli.Action, error) { +func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, error) { action := &cli.Action{ Identifier: data.Identifier.ValueString(), - Title: data.Title.ValueString(), - Trigger: data.Trigger.ValueString(), + } + + if !data.Title.IsNull() { + title := data.Title.ValueString() + action.Title = &title } if !data.Icon.IsNull() { @@ -52,6 +56,14 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel, bp *cli.Bluep action.Description = &description } + var err error + action.Trigger, err = triggerToBody(ctx, data) + + action.InvocationMethod, err = invocationMethodToBody(ctx, data) + if err != nil { + return nil, err + } + if !data.RequiredApproval.IsNull() { requiredApproval := data.RequiredApproval.ValueBool() action.RequiredApproval = &requiredApproval @@ -62,7 +74,6 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel, bp *cli.Bluep Type: "email", } } - if data.ApprovalWebhookNotification != nil { action.ApprovalNotification = &cli.ApprovalNotification{ Type: "webhook", @@ -75,30 +86,95 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel, bp *cli.Bluep } } - action.InvocationMethod = invocationMethodToBody(data) + if !data.Publish.IsNull() { + publish := data.Publish.ValueBool() + action.Publish = &publish + } - if data.UserProperties != nil { - err := actionPropertiesToBody(ctx, action, data) - if err != nil { - return nil, err + return action, nil +} + +func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) { + if data.SelfServiceTrigger != nil { + selfServiceTrigger := &cli.Trigger{ + Type: consts.SelfService, + BlueprintIdentifier: data.SelfServiceTrigger.BlueprintIdentifier.ValueStringPointer(), + Operation: data.SelfServiceTrigger.Operation.ValueStringPointer(), } - } else { - action.UserInputs.Properties = make(map[string]cli.ActionProperty) + + if data.SelfServiceTrigger.UserProperties != nil { + err := actionPropertiesToBody(ctx, selfServiceTrigger, data.SelfServiceTrigger) + if err != nil { + return nil, err + } + } else { + selfServiceTrigger.UserInputs.Properties = make(map[string]cli.ActionProperty) + } + + if !data.SelfServiceTrigger.OrderProperties.IsNull() { + order, err := utils.TerraformListToGoArray(ctx, data.SelfServiceTrigger.OrderProperties, "string") + if err != nil { + return nil, err + } + orderString := utils.InterfaceToStringArray(order) + selfServiceTrigger.UserInputs.Order = orderString + } + + return selfServiceTrigger, nil } - if !data.OrderProperties.IsNull() { - order, err := utils.TerraformListToGoArray(ctx, data.OrderProperties, "string") - if err != nil { - return nil, err + if data.AutomationTrigger != nil { + automationTrigger := &cli.Trigger{ + Type: consts.Automation, + Condition: &cli.TriggerCondition{ + Expressions: flex.TerraformStringListToGoArray(data.AutomationTrigger.JqCondition.Expressions), + Combinator: data.AutomationTrigger.JqCondition.Combinator.ValueStringPointer(), + }, + } + + if data.AutomationTrigger.EntityCreatedEvent != nil { + automationTrigger.Event = &cli.TriggerEvent{ + Type: consts.EntityCreated, + BlueprintIdentifier: data.AutomationTrigger.EntityCreatedEvent.BlueprintIdentifier.ValueStringPointer(), + } + } + + if data.AutomationTrigger.EntityUpdatedEvent != nil { + automationTrigger.Event = &cli.TriggerEvent{ + Type: consts.EntityUpdated, + BlueprintIdentifier: data.AutomationTrigger.EntityUpdatedEvent.BlueprintIdentifier.ValueStringPointer(), + } + } + + if data.AutomationTrigger.EntityDeletedEvent != nil { + automationTrigger.Event = &cli.TriggerEvent{ + Type: consts.EntityDeleted, + BlueprintIdentifier: data.AutomationTrigger.EntityDeletedEvent.BlueprintIdentifier.ValueStringPointer(), + } + } + + if data.AutomationTrigger.AnyEntityChangeEvent != nil { + automationTrigger.Event = &cli.TriggerEvent{ + Type: consts.AnyEntityChange, + BlueprintIdentifier: data.AutomationTrigger.AnyEntityChangeEvent.BlueprintIdentifier.ValueStringPointer(), + } + } + + if data.AutomationTrigger.TimerPropertyExpiredEvent != nil { + automationTrigger.Event = &cli.TriggerEvent{ + Type: consts.TimerPropertyExpired, + BlueprintIdentifier: data.AutomationTrigger.TimerPropertyExpiredEvent.BlueprintIdentifier.ValueStringPointer(), + PropertyIdentifier: data.AutomationTrigger.TimerPropertyExpiredEvent.PropertyIdentifier.ValueStringPointer(), + } } - orderString := utils.InterfaceToStringArray(order) - action.UserInputs.Order = orderString + + return automationTrigger, nil } - return action, nil + return nil, nil } -func actionPropertiesToBody(ctx context.Context, action *cli.Action, data *ActionModel) error { +func actionPropertiesToBody(ctx context.Context, action *cli.Trigger, data *SelfServiceTriggerModel) error { required := []string{} props := map[string]cli.ActionProperty{} var err error @@ -137,104 +213,121 @@ func actionPropertiesToBody(ctx context.Context, action *cli.Action, data *Actio return nil } -func invocationMethodToBody(data *ActionModel) *cli.InvocationMethod { - if data.AzureMethod != nil { - org := data.AzureMethod.Org.ValueString() - webhook := data.AzureMethod.Webhook.ValueString() - return &cli.InvocationMethod{ - Type: consts.AzureDevops, - Org: &org, - Webhook: &webhook, + +func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.InvocationMethod, error) { + if data.KafkaMethod != nil { + payload, err := utils.TerraformStringToGoObject(data.KafkaMethod.Payload) + if err != nil { + return nil, err } + + return &cli.InvocationMethod{Type: consts.Kafka, Payload: payload}, nil } - if data.GithubMethod != nil { - org := data.GithubMethod.Org.ValueString() - repo := data.GithubMethod.Repo.ValueString() - workflow := data.GithubMethod.Workflow.ValueString() - githubInvocation := &cli.InvocationMethod{ - Type: consts.Github, - Org: &org, - Repo: &repo, - Workflow: &workflow, + if data.WebhookMethod != nil { + agent, err := utils.TerraformStringToGoObject(data.WebhookMethod.Agent) + if err != nil { + return nil, err } - - if !data.GithubMethod.OmitPayload.IsNull() { - omitPayload := data.GithubMethod.OmitPayload.ValueBool() - githubInvocation.OmitPayload = &omitPayload + synchronized, err := utils.TerraformStringToGoObject(data.WebhookMethod.Synchronized) + if err != nil { + return nil, err } - - if !data.GithubMethod.OmitUserInputs.IsNull() { - omitUserInputs := data.GithubMethod.OmitUserInputs.ValueBool() - githubInvocation.OmitUserInputs = &omitUserInputs + headers := make(map[string]string) + for key, value := range data.WebhookMethod.Headers.Elements() { + tv, _ := value.ToTerraformValue(ctx) + var keyValue string + err = tv.As(&keyValue) + if err != nil { + return nil, err + } + headers[key] = keyValue } - - if !data.GithubMethod.ReportWorkflowStatus.IsNull() { - reportWorkflowStatus := data.GithubMethod.ReportWorkflowStatus.ValueBool() - githubInvocation.ReportWorkflowStatus = &reportWorkflowStatus + body, err := utils.TerraformStringToGoObject(data.WebhookMethod.Body) + if err != nil { + return nil, err } - return githubInvocation - } - if !data.KafkaMethod.IsNull() { - return &cli.InvocationMethod{ - Type: consts.Kafka, + webhookInvocation := &cli.InvocationMethod{ + Type: consts.Webhook, + Url: data.WebhookMethod.Url.ValueStringPointer(), + Agent: agent, + Synchronized: synchronized, + Method: data.WebhookMethod.Method.ValueStringPointer(), + Headers: headers, + Body: body, } + + return webhookInvocation, nil } - if data.WebhookMethod != nil { - url := data.WebhookMethod.Url.ValueString() - webhookInvocation := &cli.InvocationMethod{ - Type: consts.Webhook, - Url: &url, - } - if !data.WebhookMethod.Agent.IsNull() { - agent := data.WebhookMethod.Agent.ValueBool() - webhookInvocation.Agent = &agent + if data.GithubMethod != nil { + reportWorkflowStatus, err := utils.TerraformStringToGoObject(data.GithubMethod.ReportWorkflowStatus) + if err != nil { + return nil, err } - if !data.WebhookMethod.Synchronized.IsNull() { - synchronized := data.WebhookMethod.Synchronized.ValueBool() - webhookInvocation.Synchronized = &synchronized + workflowInputs, err := utils.TerraformStringToGoObject(data.GithubMethod.WorkflowInputs) + if err != nil { + return nil, err } - if !data.WebhookMethod.Method.IsNull() { - method := data.WebhookMethod.Method.ValueString() - webhookInvocation.Method = &method + + githubInvocation := &cli.InvocationMethod{ + Type: consts.Github, + Org: data.GithubMethod.Org.ValueStringPointer(), + Repo: data.GithubMethod.Repo.ValueStringPointer(), + Workflow: data.GithubMethod.Workflow.ValueStringPointer(), + WorkflowInputs: workflowInputs.(map[string]interface{}), + ReportWorkflowStatus: reportWorkflowStatus, } - return webhookInvocation + return githubInvocation, nil } if data.GitlabMethod != nil { - projectName := data.GitlabMethod.ProjectName.ValueString() - groupName := data.GitlabMethod.GroupName.ValueString() - gitlabInvocation := &cli.InvocationMethod{ - Type: consts.Gitlab, - ProjectName: &projectName, - GroupName: &groupName, + pipelineVariables, err := utils.TerraformStringToGoObject(data.GitlabMethod.PipelineVariables) + if err != nil { + return nil, err } - if !data.GitlabMethod.OmitPayload.IsNull() { - omitPayload := data.GitlabMethod.OmitPayload.ValueBool() - gitlabInvocation.OmitPayload = &omitPayload + gitlabInvocation := &cli.InvocationMethod{ + Type: consts.Gitlab, + ProjectName: data.GitlabMethod.ProjectName.ValueStringPointer(), + GroupName: data.GitlabMethod.GroupName.ValueStringPointer(), + DefaultRef: data.GitlabMethod.DefaultRef.ValueStringPointer(), + PipelineVariables: pipelineVariables.(map[string]interface{}), } - if !data.GitlabMethod.OmitUserInputs.IsNull() { - omitUserInputs := data.GitlabMethod.OmitUserInputs.ValueBool() - gitlabInvocation.OmitUserInputs = &omitUserInputs + return gitlabInvocation, nil + } + + if data.AzureMethod != nil { + payload, err := utils.TerraformStringToGoObject(data.AzureMethod.Payload) + if err != nil { + return nil, err } - if !data.GitlabMethod.DefaultRef.IsNull() { - defaultRef := data.GitlabMethod.DefaultRef.ValueString() - gitlabInvocation.DefaultRef = &defaultRef + azureInvocation := &cli.InvocationMethod{ + Type: consts.AzureDevops, + Org: data.AzureMethod.Org.ValueStringPointer(), + Webhook: data.AzureMethod.Webhook.ValueStringPointer(), + Payload: payload, } - if !data.GitlabMethod.Agent.IsNull() { - agent := data.GitlabMethod.Agent.ValueBool() - gitlabInvocation.Agent = &agent + return azureInvocation, nil + } + + if data.UpsertEntityMethod != nil { + upsertEntityInvocation := &cli.InvocationMethod{ + Type: consts.UpsertEntity, + Identifier: data.UpsertEntityMethod.Identifier.ValueStringPointer(), + Title: data.UpsertEntityMethod.Title.ValueStringPointer(), + BlueprintIdentifier: data.UpsertEntityMethod.BlueprintIdentifier.ValueStringPointer(), + Team: flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Teams), + Icon: data.UpsertEntityMethod.Icon.ValueStringPointer(), } - return gitlabInvocation + return upsertEntityInvocation, nil } - return nil + return nil, nil } diff --git a/port/action/array.go b/port/action/array.go index 24dafd10..66b3f749 100644 --- a/port/action/array.go +++ b/port/action/array.go @@ -117,7 +117,7 @@ func handleArrayItemsToBody(ctx context.Context, property *cli.ActionProperty, p return nil } -func arrayPropResourceToBody(ctx context.Context, d *ActionModel, props map[string]cli.ActionProperty, required *[]string) error { +func arrayPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, props map[string]cli.ActionProperty, required *[]string) error { for propIdentifier, prop := range d.UserProperties.ArrayProps { props[propIdentifier] = cli.ActionProperty{ Type: "array", diff --git a/port/action/boolean.go b/port/action/boolean.go index 1b5b7263..0043be62 100644 --- a/port/action/boolean.go +++ b/port/action/boolean.go @@ -7,7 +7,7 @@ import ( "github.com/port-labs/terraform-provider-port-labs/internal/utils" ) -func booleanPropResourceToBody(ctx context.Context, d *ActionModel, props map[string]cli.ActionProperty, required *[]string) error { +func booleanPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, props map[string]cli.ActionProperty, required *[]string) error { for propIdentifier, prop := range d.UserProperties.BooleanProps { props[propIdentifier] = cli.ActionProperty{ Type: "boolean", diff --git a/port/action/model.go b/port/action/model.go index ca017c73..3b680dd3 100644 --- a/port/action/model.go +++ b/port/action/model.go @@ -4,13 +4,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -type WebhookMethodModel struct { - Url types.String `tfsdk:"url"` - Agent types.Bool `tfsdk:"agent"` - Synchronized types.Bool `tfsdk:"synchronized"` - Method types.String `tfsdk:"method"` -} - type Value struct { JqQuery types.String `tfsdk:"jq_query"` } @@ -25,29 +18,6 @@ type DatasetModel struct { Rules []Rule `tfsdk:"rules"` } -type GithubMethodModel struct { - Org types.String `tfsdk:"org"` - Repo types.String `tfsdk:"repo"` - Workflow types.String `tfsdk:"workflow"` - OmitPayload types.Bool `tfsdk:"omit_payload"` - OmitUserInputs types.Bool `tfsdk:"omit_user_inputs"` - ReportWorkflowStatus types.Bool `tfsdk:"report_workflow_status"` -} - -type AzureMethodModel struct { - Org types.String `tfsdk:"org"` - Webhook types.String `tfsdk:"webhook"` -} - -type GitlabMethodModel struct { - ProjectName types.String `tfsdk:"project_name"` - GroupName types.String `tfsdk:"group_name"` - OmitPayload types.Bool `tfsdk:"omit_payload"` - OmitUserInputs types.Bool `tfsdk:"omit_user_inputs"` - DefaultRef types.String `tfsdk:"default_ref"` - Agent types.Bool `tfsdk:"agent"` -} - type StringPropModel struct { Title types.String `tfsdk:"title"` Icon types.String `tfsdk:"icon"` @@ -166,6 +136,93 @@ type UserPropertiesModel struct { ObjectProps map[string]ObjectPropModel `tfsdk:"object_props"` } +type SelfServiceTriggerModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` + Operation types.String `tfsdk:"operation"` + UserProperties *UserPropertiesModel `tfsdk:"user_properties"` + RequiredJqQuery types.String `tfsdk:"required_jq_query"` + OrderProperties types.List `tfsdk:"order_properties"` +} + +type EntityCreatedEventModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` +} + +type EntityUpdatedEventModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` +} + +type EntityDeletedEventModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` +} + +type AnyEntityChangeEventModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` +} + +type TimerPropertyExpiredEventModel struct { + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` + PropertyIdentifier types.String `tfsdk:"property_identifier"` +} + +type JqConditionModel struct { + Expressions []types.String `tfsdk:"expressions"` + Combinator types.String `tfsdk:"combinator"` +} + +type AutomationTriggerModel struct { + EntityCreatedEvent *EntityCreatedEventModel `tfsdk:"entity_created_event"` + EntityUpdatedEvent *EntityUpdatedEventModel `tfsdk:"entity_updated_event"` + EntityDeletedEvent *EntityDeletedEventModel `tfsdk:"entity_deleted_event"` + AnyEntityChangeEvent *AnyEntityChangeEventModel `tfsdk:"any_entity_change_event"` + TimerPropertyExpiredEvent *TimerPropertyExpiredEventModel `tfsdk:"timer_property_expired_event"` + JqCondition *JqConditionModel `tfsdk:"jq_condition"` +} + +type KafkaMethodModel struct { + Payload types.String `tfsdk:"payload"` +} + +type WebhookMethodModel struct { + Url types.String `tfsdk:"url"` + Agent types.String `tfsdk:"agent"` + Synchronized types.String `tfsdk:"synchronized"` + Method types.String `tfsdk:"method"` + Headers types.Map `tfsdk:"headers"` + Body types.String `tfsdk:"body"` +} + +type GithubMethodModel struct { + Org types.String `tfsdk:"org"` + Repo types.String `tfsdk:"repo"` + Workflow types.String `tfsdk:"workflow"` + WorkflowInputs types.String `tfsdk:"workflow_inputs"` + ReportWorkflowStatus types.String `tfsdk:"report_workflow_status"` +} + +type GitlabMethodModel struct { + ProjectName types.String `tfsdk:"project_name"` + GroupName types.String `tfsdk:"group_name"` + DefaultRef types.String `tfsdk:"default_ref"` + PipelineVariables types.String `tfsdk:"pipeline_variables"` +} + +type AzureMethodModel struct { + Org types.String `tfsdk:"org"` + Webhook types.String `tfsdk:"webhook"` + Payload types.String `tfsdk:"payload"` +} + +type UpsertEntityMethodModel struct { + Identifier types.String `tfsdk:"identifier"` + Title types.String `tfsdk:"title"` + BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` + Teams []types.String `tfsdk:"teams"` + Icon types.String `tfsdk:"icon"` + Properties types.String `tfsdk:"properties"` + Relations types.String `tfsdk:"relations"` +} + type ApprovalWebhookNotificationModel struct { Url types.String `tfsdk:"url"` Format types.String `tfsdk:"format"` @@ -178,16 +235,16 @@ type ActionModel struct { Title types.String `tfsdk:"title"` Icon types.String `tfsdk:"icon"` Description types.String `tfsdk:"description"` - RequiredApproval types.Bool `tfsdk:"required_approval"` - Trigger types.String `tfsdk:"trigger"` - KafkaMethod types.Object `tfsdk:"kafka_method"` + SelfServiceTrigger *SelfServiceTriggerModel `tfsdk:"self_service_trigger"` + AutomationTrigger *AutomationTriggerModel `tfsdk:"automation_trigger"` + KafkaMethod *KafkaMethodModel `tfsdk:"kafka_method"` WebhookMethod *WebhookMethodModel `tfsdk:"webhook_method"` GithubMethod *GithubMethodModel `tfsdk:"github_method"` - AzureMethod *AzureMethodModel `tfsdk:"azure_method"` GitlabMethod *GitlabMethodModel `tfsdk:"gitlab_method"` - UserProperties *UserPropertiesModel `tfsdk:"user_properties"` + AzureMethod *AzureMethodModel `tfsdk:"azure_method"` + UpsertEntityMethod *UpsertEntityMethodModel `tfsdk:"upsert_entity_method"` + RequiredApproval types.Bool `tfsdk:"required_approval"` ApprovalWebhookNotification *ApprovalWebhookNotificationModel `tfsdk:"approval_webhook_notification"` ApprovalEmailNotification types.Object `tfsdk:"approval_email_notification"` - OrderProperties types.List `tfsdk:"order_properties"` - RequiredJqQuery types.String `tfsdk:"required_jq_query"` + Publish types.Bool `tfsdk:"publish"` } diff --git a/port/action/number.go b/port/action/number.go index a5dfa73a..39a894a6 100644 --- a/port/action/number.go +++ b/port/action/number.go @@ -12,7 +12,7 @@ import ( "github.com/port-labs/terraform-provider-port-labs/internal/utils" ) -func numberPropResourceToBody(ctx context.Context, state *ActionModel, props map[string]cli.ActionProperty, required *[]string) error { +func numberPropResourceToBody(ctx context.Context, state *SelfServiceTriggerModel, props map[string]cli.ActionProperty, required *[]string) error { for propIdentifier, prop := range state.UserProperties.NumberProps { props[propIdentifier] = cli.ActionProperty{ Type: "number", diff --git a/port/action/object.go b/port/action/object.go index 49ac66a1..739ff488 100644 --- a/port/action/object.go +++ b/port/action/object.go @@ -9,7 +9,7 @@ import ( "github.com/port-labs/terraform-provider-port-labs/internal/utils" ) -func objectPropResourceToBody(ctx context.Context, d *ActionModel, props map[string]cli.ActionProperty, required *[]string) error { +func objectPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, props map[string]cli.ActionProperty, required *[]string) error { for propIdentifier, prop := range d.UserProperties.ObjectProps { props[propIdentifier] = cli.ActionProperty{ Type: "object", diff --git a/port/action/refreshActionState.go b/port/action/refreshActionState.go index 525b9734..0f4719d0 100644 --- a/port/action/refreshActionState.go +++ b/port/action/refreshActionState.go @@ -13,48 +13,120 @@ import ( "github.com/port-labs/terraform-provider-port-labs/internal/utils" ) -func writeInvocationMethodToResource(a *cli.Action, state *ActionModel) { +func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state *ActionModel) error { if a.InvocationMethod.Type == consts.Kafka { - state.KafkaMethod, _ = types.ObjectValue(nil, nil) + payload, err := utils.GoObjectToTerraformString(a.InvocationMethod.Payload) + if err != nil { + return err + } + + state.KafkaMethod = &KafkaMethodModel{ + Payload: payload, + } } if a.InvocationMethod.Type == consts.Webhook { + agent, err := utils.GoObjectToTerraformString(a.InvocationMethod.Agent) + if err != nil { + return err + } + synchronized, err := utils.GoObjectToTerraformString(a.InvocationMethod.Synchronized) + if err != nil { + return err + } + headers, _ := types.MapValueFrom(ctx, types.StringType, a.InvocationMethod.Headers) + body, err := utils.GoObjectToTerraformString(a.InvocationMethod.Body) + if err != nil { + return err + } + state.WebhookMethod = &WebhookMethodModel{ Url: types.StringValue(*a.InvocationMethod.Url), - Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent), - Synchronized: flex.GoBoolToFramework(a.InvocationMethod.Synchronized), + Agent: agent, + Synchronized: synchronized, Method: flex.GoStringToFramework(a.InvocationMethod.Method), + Headers: headers, + Body: body, } } if a.InvocationMethod.Type == consts.Github { + workflowInputs, err := utils.GoObjectToTerraformString(a.InvocationMethod.WorkflowInputs) + if err != nil { + return err + } + reportWorkflowStatus, err := utils.GoObjectToTerraformString(a.InvocationMethod.ReportWorkflowStatus) + if err != nil { + return err + } + state.GithubMethod = &GithubMethodModel{ - Repo: types.StringValue(*a.InvocationMethod.Repo), Org: types.StringValue(*a.InvocationMethod.Org), - OmitPayload: flex.GoBoolToFramework(a.InvocationMethod.OmitPayload), - OmitUserInputs: flex.GoBoolToFramework(a.InvocationMethod.OmitUserInputs), - Workflow: flex.GoStringToFramework(a.InvocationMethod.Workflow), - ReportWorkflowStatus: flex.GoBoolToFramework(a.InvocationMethod.ReportWorkflowStatus), + Repo: types.StringValue(*a.InvocationMethod.Repo), + Workflow: types.StringValue(*a.InvocationMethod.Workflow), + WorkflowInputs: workflowInputs, + ReportWorkflowStatus: reportWorkflowStatus, + } + } + + if a.InvocationMethod.Type == consts.Gitlab { + pipelineVariables, err := utils.GoObjectToTerraformString(a.InvocationMethod.PipelineVariables) + if err != nil { + return err + } + + state.GitlabMethod = &GitlabMethodModel{ + ProjectName: types.StringValue(*a.InvocationMethod.ProjectName), + GroupName: types.StringValue(*a.InvocationMethod.GroupName), + DefaultRef: types.StringValue(*a.InvocationMethod.DefaultRef), + PipelineVariables: pipelineVariables, } } if a.InvocationMethod.Type == consts.AzureDevops { + payload, err := utils.GoObjectToTerraformString(a.InvocationMethod.Payload) + if err != nil { + return err + } + state.AzureMethod = &AzureMethodModel{ Org: types.StringValue(*a.InvocationMethod.Org), Webhook: types.StringValue(*a.InvocationMethod.Webhook), + Payload: payload, } } - if a.InvocationMethod.Type == consts.Gitlab { - state.GitlabMethod = &GitlabMethodModel{ - ProjectName: types.StringValue(*a.InvocationMethod.ProjectName), - GroupName: types.StringValue(*a.InvocationMethod.GroupName), - OmitPayload: flex.GoBoolToFramework(a.InvocationMethod.OmitPayload), - OmitUserInputs: flex.GoBoolToFramework(a.InvocationMethod.OmitUserInputs), - DefaultRef: types.StringValue(*a.InvocationMethod.DefaultRef), - Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent), + if a.InvocationMethod.Type == consts.UpsertEntity { + var teams []types.String + switch team := a.InvocationMethod.Team.(type) { + case string: + teams = append(teams, types.StringValue(team)) + case []string: + for _, t := range team { + teams = append(teams, types.StringValue(t)) + } + } + properties, err := utils.GoObjectToTerraformString(a.InvocationMethod.Properties) + if err != nil { + return err + } + relations, err := utils.GoObjectToTerraformString(a.InvocationMethod.Relations) + if err != nil { + return err + } + + state.UpsertEntityMethod = &UpsertEntityMethodModel{ + Identifier: types.StringValue(*a.InvocationMethod.Identifier), + Title: flex.GoStringToFramework(a.InvocationMethod.Title), + BlueprintIdentifier: types.StringValue(*a.InvocationMethod.BlueprintIdentifier), + Teams: teams, + Icon: flex.GoStringToFramework(a.InvocationMethod.Icon), + Properties: properties, + Relations: relations, } } + + return nil } func writeDatasetToResource(v cli.ActionProperty) *DatasetModel { @@ -103,7 +175,7 @@ func writeVisibleToResource(v cli.ActionProperty) (types.Bool, types.String) { return types.BoolNull(), types.StringNull() } -func writeRequiredToResource(v cli.ActionUserInputs) (types.String, []string) { +func buildRequired(v cli.ActionUserInputs) (types.String, []string) { // If required is nil, return an empty string and nil if v.Required == nil { return types.StringNull(), nil @@ -130,11 +202,11 @@ func writeRequiredToResource(v cli.ActionUserInputs) (types.String, []string) { return types.StringNull(), nil } -func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionModel) error { - if len(a.UserInputs.Properties) > 0 { +func buildUserProperties(ctx context.Context, a *cli.Action) (*UserPropertiesModel, error) { + if len(a.Trigger.UserInputs.Properties) > 0 { properties := &UserPropertiesModel{} - requiredJq, required := writeRequiredToResource(a.UserInputs) - for k, v := range a.UserInputs.Properties { + requiredJq, required := buildRequired(a.Trigger.UserInputs) + for k, v := range a.Trigger.UserInputs.Properties { switch v.Type { case "string": if properties.StringProps == nil { @@ -148,7 +220,7 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode err := setCommonProperties(ctx, v, stringProp) if err != nil { - return err + return nil, err } properties.StringProps[k] = *stringProp @@ -166,7 +238,7 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode err := setCommonProperties(ctx, v, numberProp) if err != nil { - return err + return nil, err } properties.NumberProps[k] = *numberProp @@ -178,7 +250,7 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode arrayProp, err := addArrayPropertiesToResource(&v) if err != nil { - return err + return nil, err } if requiredJq.IsNull() && lo.Contains(required, k) { @@ -187,7 +259,7 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode err = setCommonProperties(ctx, v, arrayProp) if err != nil { - return err + return nil, err } properties.ArrayProps[k] = *arrayProp @@ -201,7 +273,7 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode err := setCommonProperties(ctx, v, booleanProp) if err != nil { - return err + return nil, err } if requiredJq.IsNull() && lo.Contains(required, k) { @@ -223,32 +295,110 @@ func writeInputsToResource(ctx context.Context, a *cli.Action, state *ActionMode err := setCommonProperties(ctx, v, objectProp) if err != nil { - return err + return nil, err } properties.ObjectProps[k] = *objectProp } } - state.UserProperties = properties - if len(a.UserInputs.Order) > 0 { - state.OrderProperties = flex.GoArrayStringToTerraformList(ctx, a.UserInputs.Order) + + return properties, nil + } + + return nil, nil +} + +func writeTriggerToResource(ctx context.Context, a *cli.Action, state *ActionModel) error { + if a.Trigger.Type == consts.SelfService { + userProperties, err := buildUserProperties(ctx, a) + if err != nil { + return err + } + requiredJqQuery, _ := buildRequired(a.Trigger.UserInputs) + orderProperties := types.ListNull(types.StringType) + if len(a.Trigger.UserInputs.Order) > 0 { + orderProperties = flex.GoArrayStringToTerraformList(ctx, a.Trigger.UserInputs.Order) + } + + state.SelfServiceTrigger = &SelfServiceTriggerModel{ + BlueprintIdentifier: flex.GoStringToFramework(a.Trigger.BlueprintIdentifier), + Operation: types.StringValue(*a.Trigger.Operation), + UserProperties: userProperties, + RequiredJqQuery: requiredJqQuery, + OrderProperties: orderProperties, + } + } + + if a.Trigger.Type == consts.Automation { + automationTrigger := &AutomationTriggerModel{} + + var expressions []types.String + for _, e := range a.Trigger.Condition.Expressions { + expressions = append(expressions, types.StringValue(e)) + } + + automationTrigger.JqCondition = &JqConditionModel{ + Expressions: expressions, + Combinator: flex.GoStringToFramework(a.Trigger.Condition.Combinator), + } + + if a.Trigger.Event.Type == consts.EntityCreated { + automationTrigger.EntityCreatedEvent = &EntityCreatedEventModel{ + BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), + } + } + + if a.Trigger.Event.Type == consts.EntityUpdated { + automationTrigger.EntityUpdatedEvent = &EntityUpdatedEventModel{ + BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), + } + } + + if a.Trigger.Event.Type == consts.EntityDeleted { + automationTrigger.EntityDeletedEvent = &EntityDeletedEventModel{ + BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), + } + } + + if a.Trigger.Event.Type == consts.AnyEntityChange { + automationTrigger.AnyEntityChangeEvent = &AnyEntityChangeEventModel{ + BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), + } + } + + if a.Trigger.Event.Type == consts.TimerPropertyExpired { + automationTrigger.TimerPropertyExpiredEvent = &TimerPropertyExpiredEventModel{ + BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), + PropertyIdentifier: types.StringValue(*a.Trigger.Event.PropertyIdentifier), + } } + + state.AutomationTrigger = automationTrigger } + return nil } -func refreshActionState(ctx context.Context, state *ActionModel, a *cli.Action, blueprintIdentifier string) error { - state.ID = types.StringValue(fmt.Sprintf("%s:%s", blueprintIdentifier, a.Identifier)) +func refreshActionState(ctx context.Context, state *ActionModel, a *cli.Action) error { + state.ID = types.StringValue(a.Identifier) state.Identifier = types.StringValue(a.Identifier) - state.Blueprint = types.StringValue(blueprintIdentifier) - state.Title = types.StringValue(a.Title) - state.Trigger = types.StringValue(a.Trigger) - + state.Blueprint = types.StringNull() + state.Title = flex.GoStringToFramework(a.Title) state.Icon = flex.GoStringToFramework(a.Icon) state.Description = flex.GoStringToFramework(a.Description) - state.RequiredApproval = flex.GoBoolToFramework(a.RequiredApproval) + err := writeTriggerToResource(ctx, a, state) + if err != nil { + return err + } + + err = writeInvocationMethodToResource(ctx, a, state) + if err != nil { + return err + } + + state.RequiredApproval = flex.GoBoolToFramework(a.RequiredApproval) if a.ApprovalNotification != nil { if a.ApprovalNotification.Type == "email" { state.ApprovalEmailNotification, _ = types.ObjectValue(nil, nil) @@ -263,17 +413,8 @@ func refreshActionState(ctx context.Context, state *ActionModel, a *cli.Action, } } + state.Publish = flex.GoBoolToFramework(a.Publish) - requiredJq, _ := writeRequiredToResource(a.UserInputs) - - state.RequiredJqQuery = requiredJq - - writeInvocationMethodToResource(a, state) - - err := writeInputsToResource(ctx, a, state) - if err != nil { - return err - } return nil } diff --git a/port/action/resource.go b/port/action/resource.go index 31585256..da12a3c5 100644 --- a/port/action/resource.go +++ b/port/action/resource.go @@ -3,7 +3,6 @@ package action import ( "context" "fmt" - "strings" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -35,16 +34,7 @@ func (r *ActionResource) Configure(ctx context.Context, req resource.ConfigureRe } func (r *ActionResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - idParts := strings.Split(req.ID, ":") - - if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { - resp.Diagnostics.AddError("invalid import ID", "import ID must be in the format :") - return - } - - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("blueprint"), idParts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("identifier"), idParts[1])...) - + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("identifier"), req.ID)...) } func (r *ActionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { @@ -57,7 +47,12 @@ func (r *ActionResource) Read(ctx context.Context, req resource.ReadRequest, res } blueprintIdentifier := state.Blueprint.ValueString() - a, statusCode, err := r.portClient.ReadAction(ctx, blueprintIdentifier, state.Identifier.ValueString()) + actionIdentifier := state.Identifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) + } + + a, statusCode, err := r.portClient.ReadAction(ctx, actionIdentifier) if err != nil { if statusCode == 404 { resp.State.RemoveResource(ctx) @@ -67,7 +62,7 @@ func (r *ActionResource) Read(ctx context.Context, req resource.ReadRequest, res return } - err = refreshActionState(ctx, state, a, blueprintIdentifier) + err = refreshActionState(ctx, state, a) if err != nil { resp.Diagnostics.AddError("failed writing action fields to resource", err.Error()) return @@ -84,7 +79,13 @@ func (r *ActionResource) Delete(ctx context.Context, req resource.DeleteRequest, return } - err := r.portClient.DeleteAction(ctx, state.Blueprint.ValueString(), state.Identifier.ValueString()) + blueprintIdentifier := state.Blueprint.ValueString() + actionIdentifier := state.Identifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) + } + + err := r.portClient.DeleteAction(ctx, actionIdentifier) if err != nil { resp.Diagnostics.AddError("failed to delete action", err.Error()) return @@ -101,25 +102,19 @@ func (r *ActionResource) Create(ctx context.Context, req resource.CreateRequest, return } - bp, _, err := r.portClient.ReadBlueprint(ctx, state.Blueprint.ValueString()) - if err != nil { - resp.Diagnostics.AddError("failed to read blueprint", err.Error()) - return - } - - action, err := actionStateToPortBody(ctx, state, bp) + action, err := actionStateToPortBody(ctx, state) if err != nil { resp.Diagnostics.AddError("failed to convert action resource to body", err.Error()) return } - a, err := r.portClient.CreateAction(ctx, bp.Identifier, action) + a, err := r.portClient.CreateAction(ctx, action) if err != nil { resp.Diagnostics.AddError("failed to create action", err.Error()) return } - state.ID = types.StringValue(fmt.Sprintf("%s:%s", bp.Identifier, a.Identifier)) + state.ID = types.StringValue(a.Identifier) state.Identifier = types.StringValue(a.Identifier) resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) @@ -136,30 +131,30 @@ func (r *ActionResource) Update(ctx context.Context, req resource.UpdateRequest, return } - bp, _, err := r.portClient.ReadBlueprint(ctx, state.Blueprint.ValueString()) + action, err := actionStateToPortBody(ctx, state) if err != nil { - resp.Diagnostics.AddError("failed to read blueprint", err.Error()) + resp.Diagnostics.AddError("failed to convert entity resource to body", err.Error()) return } - action, err := actionStateToPortBody(ctx, state, bp) - if err != nil { - resp.Diagnostics.AddError("failed to convert entity resource to body", err.Error()) - return + blueprintIdentifier := previousState.Blueprint.ValueString() + actionIdentifier := previousState.Identifier.ValueString() + if blueprintIdentifier != "" { + actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) } var a *cli.Action if previousState.Identifier.IsNull() { - a, err = r.portClient.CreateAction(ctx, bp.Identifier, action) + a, err = r.portClient.CreateAction(ctx, action) } else { - a, err = r.portClient.UpdateAction(ctx, bp.Identifier, previousState.Identifier.ValueString(), action) + a, err = r.portClient.UpdateAction(ctx, actionIdentifier, action) } if err != nil { resp.Diagnostics.AddError("failed to create action", err.Error()) return } - state.ID = types.StringValue(fmt.Sprintf("%s:%s", bp.Identifier, a.Identifier)) + state.ID = types.StringValue(a.Identifier) state.Identifier = types.StringValue(a.Identifier) resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) diff --git a/port/action/schema.go b/port/action/schema.go index 21514429..1dbce92e 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -6,15 +6,16 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/port-labs/terraform-provider-port-labs/internal/utils" + "regexp" ) func MetadataProperties() map[string]schema.Attribute { @@ -86,6 +87,17 @@ func MetadataProperties() map[string]schema.Attribute { } } +func StringBooleanOrJQTemplateValidator() []validator.String { + return []validator.String{ + stringvalidator.Any( + stringvalidator.OneOf("true", "false"), + stringvalidator.RegexMatches( + regexp.MustCompile(`^[\n\r\s]*{{.*}}[\n\r\s]*$`), + "must be a valid jq template: {{JQ_EXPRESSION}}", + )), + } +} + func ActionSchema() map[string]schema.Attribute { return map[string]schema.Attribute{ "id": schema.StringAttribute{ @@ -97,11 +109,13 @@ func ActionSchema() map[string]schema.Attribute { }, "blueprint": schema.StringAttribute{ MarkdownDescription: "The blueprint identifier the action relates to", - Required: true, + Optional: true, + DeprecationMessage: "Action is not attached to blueprint anymore. This value is ignored", + Validators: []validator.String{stringvalidator.OneOf("")}, }, "title": schema.StringAttribute{ MarkdownDescription: "Title", - Required: true, + Optional: true, }, "icon": schema.StringAttribute{ MarkdownDescription: "Icon", @@ -111,64 +125,230 @@ func ActionSchema() map[string]schema.Attribute { MarkdownDescription: "Description", Optional: true, }, - "required_approval": schema.BoolAttribute{ - MarkdownDescription: "Require approval before invoking the action", - Optional: true, - }, - "approval_webhook_notification": schema.SingleNestedAttribute{ - MarkdownDescription: "The webhook notification of the approval", + "self_service_trigger": schema.SingleNestedAttribute{ + MarkdownDescription: "Self service trigger for the action", Optional: true, Attributes: map[string]schema.Attribute{ - "url": schema.StringAttribute{ - MarkdownDescription: "The URL to invoke the webhook", + "blueprint_identifier": schema.StringAttribute{ + Description: "The ID of the blueprint", + Optional: true, + }, + "operation": schema.StringAttribute{ + MarkdownDescription: "The operation type of the action", Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("CREATE", "DAY-2", "DELETE"), + }, + }, + "user_properties": schema.SingleNestedAttribute{ + MarkdownDescription: "User properties", + Optional: true, + Attributes: map[string]schema.Attribute{ + "string_props": StringPropertySchema(), + "number_props": NumberPropertySchema(), + "boolean_props": BooleanPropertySchema(), + "object_props": ObjectPropertySchema(), + "array_props": ArrayPropertySchema(), + }, + }, + "required_jq_query": schema.StringAttribute{ + MarkdownDescription: "The required jq query of the property", + Optional: true, + }, + "order_properties": schema.ListAttribute{ + MarkdownDescription: "Order properties", + Optional: true, + ElementType: types.StringType, }, }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf(path.MatchRoot("automation_trigger")), + }, }, - "approval_email_notification": schema.ObjectAttribute{ - MarkdownDescription: "The email notification of the approval", + "automation_trigger": schema.SingleNestedAttribute{ + MarkdownDescription: "Automation trigger for the action", Optional: true, - AttributeTypes: map[string]attr.Type{}, - }, - "trigger": schema.StringAttribute{ - MarkdownDescription: "The trigger type of the action", - Required: true, - Validators: []validator.String{ - stringvalidator.OneOf("CREATE", "DAY-2", "DELETE"), + Attributes: map[string]schema.Attribute{ + "entity_created_event": schema.SingleNestedAttribute{ + MarkdownDescription: "Entity created event trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "The blueprint identifier of the created entity", + Required: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_updated_event"), + path.MatchRelative().AtParent().AtName("entity_deleted_event"), + path.MatchRelative().AtParent().AtName("any_entity_change_event"), + path.MatchRelative().AtParent().AtName("timer_property_expired_event"), + ), + }, + }, + "entity_updated_event": schema.SingleNestedAttribute{ + MarkdownDescription: "Entity updated event trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "The blueprint identifier of the updated entity", + Required: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_created_event"), + path.MatchRelative().AtParent().AtName("entity_deleted_event"), + path.MatchRelative().AtParent().AtName("any_entity_change_event"), + path.MatchRelative().AtParent().AtName("timer_property_expired_event"), + ), + }, + }, + "entity_deleted_event": schema.SingleNestedAttribute{ + MarkdownDescription: "Entity deleted event trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "The blueprint identifier of the deleted entity", + Required: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_created_event"), + path.MatchRelative().AtParent().AtName("entity_updated_event"), + path.MatchRelative().AtParent().AtName("any_entity_change_event"), + path.MatchRelative().AtParent().AtName("timer_property_expired_event"), + ), + }, + }, + "any_entity_change_event": schema.SingleNestedAttribute{ + MarkdownDescription: "Any entity change event trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "The blueprint identifier of the changed entity", + Required: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_created_event"), + path.MatchRelative().AtParent().AtName("entity_updated_event"), + path.MatchRelative().AtParent().AtName("entity_deleted_event"), + path.MatchRelative().AtParent().AtName("timer_property_expired_event"), + ), + }, + }, + "timer_property_expired_event": schema.SingleNestedAttribute{ + MarkdownDescription: "Timer property expired event trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "The blueprint identifier of the expired timer property", + Required: true, + }, + "property_identifier": schema.StringAttribute{ + MarkdownDescription: "The property identifier of the expired timer property", + Required: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_created_event"), + path.MatchRelative().AtParent().AtName("entity_updated_event"), + path.MatchRelative().AtParent().AtName("entity_deleted_event"), + path.MatchRelative().AtParent().AtName("any_entity_change_event"), + ), + }, + }, + "jq_condition": schema.SingleNestedAttribute{ + MarkdownDescription: "JQ condition for automation trigger", + Optional: true, + Attributes: map[string]schema.Attribute{ + "expressions": schema.ListAttribute{ + MarkdownDescription: "The jq expressions of the condition", + ElementType: types.StringType, + Required: true, + }, + "combinator": schema.StringAttribute{ + MarkdownDescription: "The combinator of the condition", + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("and", "or"), + }, + }, + }, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf(path.MatchRoot("self_service_trigger")), }, }, - "kafka_method": schema.ObjectAttribute{ - MarkdownDescription: "The invocation method of the action", + "kafka_method": schema.SingleNestedAttribute{ + MarkdownDescription: "Kafka invocation method", Optional: true, - AttributeTypes: map[string]attr.Type{}, + Attributes: map[string]schema.Attribute{ + "payload": schema.StringAttribute{ + MarkdownDescription: "The Kafka message payload (array or object encoded to a string)", + Optional: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("webhook_method"), + path.MatchRoot("github_method"), + path.MatchRoot("gitlab_method"), + path.MatchRoot("azure_method"), + path.MatchRoot("upsert_entity_method"), + ), + }, }, "webhook_method": schema.SingleNestedAttribute{ - MarkdownDescription: "The invocation method of the action", + MarkdownDescription: "Webhook invocation method", Optional: true, Attributes: map[string]schema.Attribute{ "url": schema.StringAttribute{ MarkdownDescription: "Required when selecting type WEBHOOK. The URL to invoke the action", Required: true, }, - "agent": schema.BoolAttribute{ + "agent": schema.StringAttribute{ MarkdownDescription: "Use the agent to invoke the action", Optional: true, + Validators: StringBooleanOrJQTemplateValidator(), }, - "synchronized": schema.BoolAttribute{ + "synchronized": schema.StringAttribute{ MarkdownDescription: "Synchronize the action", Optional: true, + Validators: StringBooleanOrJQTemplateValidator(), }, "method": schema.StringAttribute{ MarkdownDescription: "The HTTP method to invoke the action", Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("POST", "PUT", "PATCH", "DELETE"), - }, }, + "headers": schema.MapAttribute{ + MarkdownDescription: "The HTTP method to invoke the action", + ElementType: types.StringType, + Optional: true, + }, + "body": schema.StringAttribute{ + MarkdownDescription: "The Webhook body (array or object encoded to a string)", + Optional: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), + path.MatchRoot("github_method"), + path.MatchRoot("gitlab_method"), + path.MatchRoot("azure_method"), + path.MatchRoot("upsert_entity_method"), + ), }, }, "github_method": schema.SingleNestedAttribute{ - MarkdownDescription: "The invocation method of the action", + MarkdownDescription: "GitHub invocation method", Optional: true, Attributes: map[string]schema.Attribute{ "org": schema.StringAttribute{ @@ -183,26 +363,28 @@ func ActionSchema() map[string]schema.Attribute { MarkdownDescription: "The GitHub workflow that the action belongs to", Required: true, }, - "omit_payload": schema.BoolAttribute{ - MarkdownDescription: "Omit the payload when invoking the action", + "workflow_inputs": schema.StringAttribute{ + MarkdownDescription: "The GitHub workflow inputs (key-value object encoded to a string)", Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), }, - "omit_user_inputs": schema.BoolAttribute{ - MarkdownDescription: "Omit the user inputs when invoking the action", - Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), - }, - "report_workflow_status": schema.BoolAttribute{ + "report_workflow_status": schema.StringAttribute{ MarkdownDescription: "Report the workflow status when invoking the action", Optional: true, + Validators: StringBooleanOrJQTemplateValidator(), }, }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), + path.MatchRoot("webhook_method"), + path.MatchRoot("gitlab_method"), + path.MatchRoot("azure_method"), + path.MatchRoot("upsert_entity_method"), + ), + }, }, "gitlab_method": schema.SingleNestedAttribute{ - MarkdownDescription: "The invocation method of the action", + MarkdownDescription: "Gitlab invocation method", Optional: true, Attributes: map[string]schema.Attribute{ "project_name": schema.StringAttribute{ @@ -213,32 +395,27 @@ func ActionSchema() map[string]schema.Attribute { MarkdownDescription: "Required when selecting type GITLAB. The GitLab group name that the workflow belongs to", Required: true, }, - "omit_payload": schema.BoolAttribute{ - MarkdownDescription: "Omit the payload when invoking the action", - Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), - }, - "omit_user_inputs": schema.BoolAttribute{ - MarkdownDescription: "Omit the user inputs when invoking the action", - Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), - }, "default_ref": schema.StringAttribute{ MarkdownDescription: "The default ref of the action", Optional: true, }, - "agent": schema.BoolAttribute{ - MarkdownDescription: "Use the agent to invoke the action", + "pipeline_variables": schema.StringAttribute{ + MarkdownDescription: "The Gitlab pipeline variables (key-value object encoded to a string)", Optional: true, - Computed: true, - Default: booldefault.StaticBool(true), }, }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), + path.MatchRoot("webhook_method"), + path.MatchRoot("github_method"), + path.MatchRoot("azure_method"), + path.MatchRoot("upsert_entity_method"), + ), + }, }, "azure_method": schema.SingleNestedAttribute{ - MarkdownDescription: "The invocation method of the action", + MarkdownDescription: "Azure DevOps invocation method", Optional: true, Attributes: map[string]schema.Attribute{ "org": schema.StringAttribute{ @@ -249,30 +426,92 @@ func ActionSchema() map[string]schema.Attribute { MarkdownDescription: "Required when selecting type AZURE. The Azure webhook that the workflow belongs to", Required: true, }, + "payload": schema.StringAttribute{ + MarkdownDescription: "The Azure Devops workflow payload (array or object encoded to a string)", + Optional: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), + path.MatchRoot("webhook_method"), + path.MatchRoot("github_method"), + path.MatchRoot("gitlab_method"), + path.MatchRoot("upsert_entity_method"), + ), }, }, - "order_properties": schema.ListAttribute{ - MarkdownDescription: "Order properties", + "upsert_entity_method": schema.SingleNestedAttribute{ + MarkdownDescription: "Upsert Entity invocation method", + Optional: true, + Attributes: map[string]schema.Attribute{ + "identifier": schema.StringAttribute{ + MarkdownDescription: "Required when selecting type Upsert Entity. The entity identifier for the upsert", + Required: true, + }, + "title": schema.StringAttribute{ + MarkdownDescription: "The title of the entity", + Optional: true, + }, + "blueprint_identifier": schema.StringAttribute{ + MarkdownDescription: "Required when selecting type Upsert Entity. The blueprint identifier of the entity for the upsert", + Required: true, + }, + "teams": schema.ListAttribute{ + MarkdownDescription: "The teams the entity belongs to", + ElementType: types.StringType, + Optional: true, + }, + "icon": schema.StringAttribute{ + MarkdownDescription: "The icon of the entity", + Optional: true, + }, + "properties": schema.StringAttribute{ + MarkdownDescription: "The properties of the entity (key-value object encoded to a string)", + Optional: true, + }, + "relations": schema.StringAttribute{ + MarkdownDescription: "The relations of the entity (key-value object encoded to a string)", + Optional: true, + }, + }, + Validators: []validator.Object{ + objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), + path.MatchRoot("webhook_method"), + path.MatchRoot("github_method"), + path.MatchRoot("gitlab_method"), + path.MatchRoot("azure_method"), + ), + }, + }, + "required_approval": schema.BoolAttribute{ + MarkdownDescription: "Require approval before invoking the action", Optional: true, - ElementType: types.StringType, }, - "user_properties": schema.SingleNestedAttribute{ - MarkdownDescription: "User properties", + "approval_webhook_notification": schema.SingleNestedAttribute{ + MarkdownDescription: "The webhook notification of the approval", Optional: true, Attributes: map[string]schema.Attribute{ - "string_props": StringPropertySchema(), - "number_props": NumberPropertySchema(), - "boolean_props": BooleanPropertySchema(), - "object_props": ObjectPropertySchema(), - "array_props": ArrayPropertySchema(), + "url": schema.StringAttribute{ + MarkdownDescription: "The URL to invoke the webhook", + Required: true, + }, + }, + }, + "approval_email_notification": schema.ObjectAttribute{ + MarkdownDescription: "The email notification of the approval", + Optional: true, + AttributeTypes: map[string]attr.Type{}, + Validators: []validator.Object{ + objectvalidator.ConflictsWith(path.MatchRoot("approval_webhook_notification")), }, }, - "required_jq_query": schema.StringAttribute{ - MarkdownDescription: "The required jq query of the property", + "publish": schema.BoolAttribute{ + MarkdownDescription: "Publish action", Optional: true, }, } - } func StringPropertySchema() schema.Attribute { @@ -655,35 +894,35 @@ func validateUserInputRequiredNotSetToFalse(state *ActionModel, resp *resource.V // supported anymore const errorString = "required is set to false, this is not supported anymore, if you don't want to make the stringProp required, remove the required stringProp" - if state.UserProperties == nil { + if state.SelfServiceTrigger == nil || state.SelfServiceTrigger.UserProperties == nil { return } - for _, stringProp := range state.UserProperties.StringProps { + for _, stringProp := range state.SelfServiceTrigger.UserProperties.StringProps { if !stringProp.Required.IsNull() && !stringProp.Required.ValueBool() && stringProp.Required == types.BoolValue(false) { resp.Diagnostics.AddError(errorString, fmt.Sprint(`Error in User Property: `, stringProp.Title, ` in action: `, state.Identifier)) } } - for _, numberProp := range state.UserProperties.NumberProps { + for _, numberProp := range state.SelfServiceTrigger.UserProperties.NumberProps { if !numberProp.Required.IsNull() && !numberProp.Required.ValueBool() && numberProp.Required == types.BoolValue(false) { resp.Diagnostics.AddError(errorString, fmt.Sprint(`Error in User Property: `, numberProp.Title, ` in action: `, state.Identifier)) } } - for _, boolProp := range state.UserProperties.BooleanProps { + for _, boolProp := range state.SelfServiceTrigger.UserProperties.BooleanProps { if !boolProp.Required.IsNull() && !boolProp.Required.ValueBool() && boolProp.Required == types.BoolValue(false) { resp.Diagnostics.AddError(errorString, fmt.Sprint(`Error in User Property: `, boolProp.Title, ` in action: `, state.Identifier)) } } - for _, objectProp := range state.UserProperties.ObjectProps { + for _, objectProp := range state.SelfServiceTrigger.UserProperties.ObjectProps { if !objectProp.Required.IsNull() && !objectProp.Required.ValueBool() && objectProp.Required == types.BoolValue(false) { resp.Diagnostics.AddError(errorString, fmt.Sprint(`Error in User Property: `, objectProp.Title, ` in action: `, state.Identifier)) } } - for _, arrayProp := range state.UserProperties.ArrayProps { + for _, arrayProp := range state.SelfServiceTrigger.UserProperties.ArrayProps { if !arrayProp.Required.IsNull() && !arrayProp.Required.ValueBool() && arrayProp.Required == types.BoolValue(false) { resp.Diagnostics.AddError(errorString, fmt.Sprint(`Error in User Property: `, arrayProp.Title, ` in action: `, state.Identifier)) } diff --git a/port/action/string.go b/port/action/string.go index 8e967e13..bec52261 100644 --- a/port/action/string.go +++ b/port/action/string.go @@ -12,7 +12,7 @@ import ( "github.com/port-labs/terraform-provider-port-labs/internal/utils" ) -func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[string]cli.ActionProperty, required *[]string) error { +func stringPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, props map[string]cli.ActionProperty, required *[]string) error { for propIdentifier, prop := range d.UserProperties.StringProps { property := cli.ActionProperty{ Type: "string", From 303e970517bda554cf1cdf20ed4537cfcb6c2f8f Mon Sep 17 00:00:00 2001 From: talsabagport Date: Wed, 10 Jan 2024 20:24:11 +0200 Subject: [PATCH 02/13] Change to new action --- port/action/actionStateToPortBody.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index d7314f44..0ae95aa3 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -37,6 +37,7 @@ func actionDataSetToPortBody(dataSet *DatasetModel) *cli.Dataset { } func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, error) { + var err error action := &cli.Action{ Identifier: data.Identifier.ValueString(), } @@ -56,8 +57,10 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, action.Description = &description } - var err error action.Trigger, err = triggerToBody(ctx, data) + if err != nil { + return nil, err + } action.InvocationMethod, err = invocationMethodToBody(ctx, data) if err != nil { From 7ee42f7769cdeed5b37c877c81d2a59a9c6b79c6 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Thu, 11 Jan 2024 18:12:17 +0200 Subject: [PATCH 03/13] fix issues --- internal/cli/models.go | 4 +- internal/consts/provider.go | 1 + internal/utils/utils.go | 9 +++ port/action/actionStateToPortBody.go | 44 +++++++++---- port/action/refreshActionState.go | 21 +++--- port/action/schema.go | 97 ++++------------------------ 6 files changed, 69 insertions(+), 107 deletions(-) diff --git a/internal/cli/models.go b/internal/cli/models.go index ba555221..81dcda99 100644 --- a/internal/cli/models.go +++ b/internal/cli/models.go @@ -145,7 +145,7 @@ type ( Org *string `json:"org,omitempty"` Repo *string `json:"repo,omitempty"` Workflow *string `json:"workflow,omitempty"` - WorkflowInputs map[string]any `json:"workflow_inputs,omitempty"` + WorkflowInputs map[string]any `json:"workflowInputs,omitempty"` ReportWorkflowStatus any `json:"reportWorkflowStatus,omitempty"` Branch *string `json:"branch,omitempty"` ProjectName *string `json:"projectName,omitempty"` @@ -200,7 +200,7 @@ type ( Type string `json:"type"` BlueprintIdentifier *string `json:"blueprintIdentifier,omitempty"` Operation *string `json:"operation,omitempty"` - UserInputs ActionUserInputs `json:"userInputs,omitempty"` + UserInputs *ActionUserInputs `json:"userInputs,omitempty"` Event *TriggerEvent `json:"event,omitempty"` Condition *TriggerCondition `json:"condition,omitempty"` } diff --git a/internal/consts/provider.go b/internal/consts/provider.go index 9b539bed..828c4c0c 100644 --- a/internal/consts/provider.go +++ b/internal/consts/provider.go @@ -16,4 +16,5 @@ const ( EntityDeleted = "ENTITY_DELETED" TimerPropertyExpired = "TIMER_PROPERTY_EXPIRED" AnyEntityChange = "ANY_ENTITY_CHANGE" + JqCondition = "JQ" ) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 603b4036..e311547d 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "math/big" + "reflect" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -76,6 +77,14 @@ func GoObjectToTerraformString(v interface{}) (types.String, error) { if v == nil { return types.StringNull(), nil } + + switch reflect.TypeOf(v).Kind() { + case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice: + if reflect.ValueOf(v).IsNil() { + return types.StringNull(), nil + } + } + js, err := json.Marshal(v) if err != nil { return types.StringNull(), err diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index 0ae95aa3..e49a5d7a 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -103,6 +103,9 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) Type: consts.SelfService, BlueprintIdentifier: data.SelfServiceTrigger.BlueprintIdentifier.ValueStringPointer(), Operation: data.SelfServiceTrigger.Operation.ValueStringPointer(), + UserInputs: &cli.ActionUserInputs{ + Properties: make(map[string]cli.ActionProperty), + }, } if data.SelfServiceTrigger.UserProperties != nil { @@ -110,8 +113,6 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) if err != nil { return nil, err } - } else { - selfServiceTrigger.UserInputs.Properties = make(map[string]cli.ActionProperty) } if !data.SelfServiceTrigger.OrderProperties.IsNull() { @@ -129,10 +130,14 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) if data.AutomationTrigger != nil { automationTrigger := &cli.Trigger{ Type: consts.Automation, - Condition: &cli.TriggerCondition{ + } + + if data.AutomationTrigger.JqCondition != nil { + automationTrigger.Condition = &cli.TriggerCondition{ + Type: consts.JqCondition, Expressions: flex.TerraformStringListToGoArray(data.AutomationTrigger.JqCondition.Expressions), Combinator: data.AutomationTrigger.JqCondition.Combinator.ValueStringPointer(), - }, + } } if data.AutomationTrigger.EntityCreatedEvent != nil { @@ -177,7 +182,7 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) return nil, nil } -func actionPropertiesToBody(ctx context.Context, action *cli.Trigger, data *SelfServiceTriggerModel) error { +func actionPropertiesToBody(ctx context.Context, actionTrigger *cli.Trigger, data *SelfServiceTriggerModel) error { required := []string{} props := map[string]cli.ActionProperty{} var err error @@ -202,16 +207,16 @@ func actionPropertiesToBody(ctx context.Context, action *cli.Trigger, data *Self return err } - action.UserInputs.Properties = props + actionTrigger.UserInputs.Properties = props // if requiredJqQuery is set, required shouldn't be set and vice versa if !data.RequiredJqQuery.IsNull() { RequiredJqQueryMap := map[string]string{ "jqQuery": data.RequiredJqQuery.ValueString(), } - action.UserInputs.Required = RequiredJqQueryMap + actionTrigger.UserInputs.Required = RequiredJqQueryMap } else { - action.UserInputs.Required = required + actionTrigger.UserInputs.Required = required } return nil @@ -269,17 +274,18 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca if err != nil { return nil, err } - workflowInputs, err := utils.TerraformStringToGoObject(data.GithubMethod.WorkflowInputs) + wi, err := utils.TerraformStringToGoObject(data.GithubMethod.WorkflowInputs) if err != nil { return nil, err } + workflowInputs, _ := wi.(map[string]interface{}) githubInvocation := &cli.InvocationMethod{ Type: consts.Github, Org: data.GithubMethod.Org.ValueStringPointer(), Repo: data.GithubMethod.Repo.ValueStringPointer(), Workflow: data.GithubMethod.Workflow.ValueStringPointer(), - WorkflowInputs: workflowInputs.(map[string]interface{}), + WorkflowInputs: workflowInputs, ReportWorkflowStatus: reportWorkflowStatus, } @@ -287,17 +293,18 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca } if data.GitlabMethod != nil { - pipelineVariables, err := utils.TerraformStringToGoObject(data.GitlabMethod.PipelineVariables) + pv, err := utils.TerraformStringToGoObject(data.GitlabMethod.PipelineVariables) if err != nil { return nil, err } + pipelineVariables, _ := pv.(map[string]interface{}) gitlabInvocation := &cli.InvocationMethod{ Type: consts.Gitlab, ProjectName: data.GitlabMethod.ProjectName.ValueStringPointer(), GroupName: data.GitlabMethod.GroupName.ValueStringPointer(), DefaultRef: data.GitlabMethod.DefaultRef.ValueStringPointer(), - PipelineVariables: pipelineVariables.(map[string]interface{}), + PipelineVariables: pipelineVariables, } return gitlabInvocation, nil @@ -320,6 +327,17 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca } if data.UpsertEntityMethod != nil { + p, err := utils.TerraformStringToGoObject(data.UpsertEntityMethod.Properties) + if err != nil { + return nil, err + } + properties, _ := p.(map[string]interface{}) + r, err := utils.TerraformStringToGoObject(data.UpsertEntityMethod.Relations) + if err != nil { + return nil, err + } + relations, _ := r.(map[string]interface{}) + upsertEntityInvocation := &cli.InvocationMethod{ Type: consts.UpsertEntity, Identifier: data.UpsertEntityMethod.Identifier.ValueStringPointer(), @@ -327,6 +345,8 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca BlueprintIdentifier: data.UpsertEntityMethod.BlueprintIdentifier.ValueStringPointer(), Team: flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Teams), Icon: data.UpsertEntityMethod.Icon.ValueStringPointer(), + Properties: properties, + Relations: relations, } return upsertEntityInvocation, nil diff --git a/port/action/refreshActionState.go b/port/action/refreshActionState.go index 0f4719d0..dda9d81a 100644 --- a/port/action/refreshActionState.go +++ b/port/action/refreshActionState.go @@ -101,9 +101,9 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state * switch team := a.InvocationMethod.Team.(type) { case string: teams = append(teams, types.StringValue(team)) - case []string: + case []interface{}: for _, t := range team { - teams = append(teams, types.StringValue(t)) + teams = append(teams, types.StringValue(t.(string))) } } properties, err := utils.GoObjectToTerraformString(a.InvocationMethod.Properties) @@ -175,7 +175,7 @@ func writeVisibleToResource(v cli.ActionProperty) (types.Bool, types.String) { return types.BoolNull(), types.StringNull() } -func buildRequired(v cli.ActionUserInputs) (types.String, []string) { +func buildRequired(v *cli.ActionUserInputs) (types.String, []string) { // If required is nil, return an empty string and nil if v.Required == nil { return types.StringNull(), nil @@ -334,13 +334,14 @@ func writeTriggerToResource(ctx context.Context, a *cli.Action, state *ActionMod automationTrigger := &AutomationTriggerModel{} var expressions []types.String - for _, e := range a.Trigger.Condition.Expressions { - expressions = append(expressions, types.StringValue(e)) - } - - automationTrigger.JqCondition = &JqConditionModel{ - Expressions: expressions, - Combinator: flex.GoStringToFramework(a.Trigger.Condition.Combinator), + if a.Trigger.Condition != nil { + for _, e := range a.Trigger.Condition.Expressions { + expressions = append(expressions, types.StringValue(e)) + } + automationTrigger.JqCondition = &JqConditionModel{ + Expressions: expressions, + Combinator: flex.GoStringToFramework(a.Trigger.Condition.Combinator), + } } if a.Trigger.Event.Type == consts.EntityCreated { diff --git a/port/action/schema.go b/port/action/schema.go index 1dbce92e..c0fa9a43 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -12,6 +12,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/port-labs/terraform-provider-port-labs/internal/utils" @@ -32,7 +34,7 @@ func MetadataProperties() map[string]schema.Attribute { MarkdownDescription: "Whether the property is required, by default not required, this property can't be set at the same time if `required_jq_query` is set, and only supports true as value", Optional: true, Validators: []validator.Bool{ - boolvalidator.ConflictsWith(path.MatchRoot("required_jq_query")), + boolvalidator.ConflictsWith(path.MatchRoot("self_service_trigger").AtName("required_jq_query")), }, }, "description": schema.StringAttribute{ @@ -162,7 +164,10 @@ func ActionSchema() map[string]schema.Attribute { }, }, Validators: []validator.Object{ - objectvalidator.ExactlyOneOf(path.MatchRoot("automation_trigger")), + objectvalidator.ExactlyOneOf( + path.MatchRoot("self_service_trigger"), + path.MatchRoot("automation_trigger"), + ), }, }, "automation_trigger": schema.SingleNestedAttribute{ @@ -180,6 +185,7 @@ func ActionSchema() map[string]schema.Attribute { }, Validators: []validator.Object{ objectvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("entity_created_event"), path.MatchRelative().AtParent().AtName("entity_updated_event"), path.MatchRelative().AtParent().AtName("entity_deleted_event"), path.MatchRelative().AtParent().AtName("any_entity_change_event"), @@ -196,14 +202,6 @@ func ActionSchema() map[string]schema.Attribute { Required: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRelative().AtParent().AtName("entity_created_event"), - path.MatchRelative().AtParent().AtName("entity_deleted_event"), - path.MatchRelative().AtParent().AtName("any_entity_change_event"), - path.MatchRelative().AtParent().AtName("timer_property_expired_event"), - ), - }, }, "entity_deleted_event": schema.SingleNestedAttribute{ MarkdownDescription: "Entity deleted event trigger", @@ -214,14 +212,6 @@ func ActionSchema() map[string]schema.Attribute { Required: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRelative().AtParent().AtName("entity_created_event"), - path.MatchRelative().AtParent().AtName("entity_updated_event"), - path.MatchRelative().AtParent().AtName("any_entity_change_event"), - path.MatchRelative().AtParent().AtName("timer_property_expired_event"), - ), - }, }, "any_entity_change_event": schema.SingleNestedAttribute{ MarkdownDescription: "Any entity change event trigger", @@ -232,14 +222,6 @@ func ActionSchema() map[string]schema.Attribute { Required: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRelative().AtParent().AtName("entity_created_event"), - path.MatchRelative().AtParent().AtName("entity_updated_event"), - path.MatchRelative().AtParent().AtName("entity_deleted_event"), - path.MatchRelative().AtParent().AtName("timer_property_expired_event"), - ), - }, }, "timer_property_expired_event": schema.SingleNestedAttribute{ MarkdownDescription: "Timer property expired event trigger", @@ -254,14 +236,6 @@ func ActionSchema() map[string]schema.Attribute { Required: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRelative().AtParent().AtName("entity_created_event"), - path.MatchRelative().AtParent().AtName("entity_updated_event"), - path.MatchRelative().AtParent().AtName("entity_deleted_event"), - path.MatchRelative().AtParent().AtName("any_entity_change_event"), - ), - }, }, "jq_condition": schema.SingleNestedAttribute{ MarkdownDescription: "JQ condition for automation trigger", @@ -274,7 +248,9 @@ func ActionSchema() map[string]schema.Attribute { }, "combinator": schema.StringAttribute{ MarkdownDescription: "The combinator of the condition", - Required: true, + Optional: true, + Computed: true, + Default: stringdefault.StaticString("and"), Validators: []validator.String{ stringvalidator.OneOf("and", "or"), }, @@ -282,9 +258,6 @@ func ActionSchema() map[string]schema.Attribute { }, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf(path.MatchRoot("self_service_trigger")), - }, }, "kafka_method": schema.SingleNestedAttribute{ MarkdownDescription: "Kafka invocation method", @@ -297,6 +270,7 @@ func ActionSchema() map[string]schema.Attribute { }, Validators: []validator.Object{ objectvalidator.ExactlyOneOf( + path.MatchRoot("kafka_method"), path.MatchRoot("webhook_method"), path.MatchRoot("github_method"), path.MatchRoot("gitlab_method"), @@ -337,15 +311,6 @@ func ActionSchema() map[string]schema.Attribute { Optional: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRoot("kafka_method"), - path.MatchRoot("github_method"), - path.MatchRoot("gitlab_method"), - path.MatchRoot("azure_method"), - path.MatchRoot("upsert_entity_method"), - ), - }, }, "github_method": schema.SingleNestedAttribute{ MarkdownDescription: "GitHub invocation method", @@ -373,15 +338,6 @@ func ActionSchema() map[string]schema.Attribute { Validators: StringBooleanOrJQTemplateValidator(), }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRoot("kafka_method"), - path.MatchRoot("webhook_method"), - path.MatchRoot("gitlab_method"), - path.MatchRoot("azure_method"), - path.MatchRoot("upsert_entity_method"), - ), - }, }, "gitlab_method": schema.SingleNestedAttribute{ MarkdownDescription: "Gitlab invocation method", @@ -404,15 +360,6 @@ func ActionSchema() map[string]schema.Attribute { Optional: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRoot("kafka_method"), - path.MatchRoot("webhook_method"), - path.MatchRoot("github_method"), - path.MatchRoot("azure_method"), - path.MatchRoot("upsert_entity_method"), - ), - }, }, "azure_method": schema.SingleNestedAttribute{ MarkdownDescription: "Azure DevOps invocation method", @@ -431,15 +378,6 @@ func ActionSchema() map[string]schema.Attribute { Optional: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRoot("kafka_method"), - path.MatchRoot("webhook_method"), - path.MatchRoot("github_method"), - path.MatchRoot("gitlab_method"), - path.MatchRoot("upsert_entity_method"), - ), - }, }, "upsert_entity_method": schema.SingleNestedAttribute{ MarkdownDescription: "Upsert Entity invocation method", @@ -475,15 +413,6 @@ func ActionSchema() map[string]schema.Attribute { Optional: true, }, }, - Validators: []validator.Object{ - objectvalidator.ExactlyOneOf( - path.MatchRoot("kafka_method"), - path.MatchRoot("webhook_method"), - path.MatchRoot("github_method"), - path.MatchRoot("gitlab_method"), - path.MatchRoot("azure_method"), - ), - }, }, "required_approval": schema.BoolAttribute{ MarkdownDescription: "Require approval before invoking the action", @@ -510,6 +439,8 @@ func ActionSchema() map[string]schema.Attribute { "publish": schema.BoolAttribute{ MarkdownDescription: "Publish action", Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), }, } } From cbf4235feaf4239851ee9badc0fc78f1849ec122 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Thu, 11 Jan 2024 18:36:29 +0200 Subject: [PATCH 04/13] fix tests --- port/action/resource_test.go | 1068 ++++++++++++++++++---------------- 1 file changed, 554 insertions(+), 514 deletions(-) diff --git a/port/action/resource_test.go b/port/action/resource_test.go index ac690e98..b0f3fdc5 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -35,8 +35,10 @@ func TestAccPortActionBasic(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -49,8 +51,8 @@ func TestAccPortActionBasic(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), ), }, }, @@ -65,48 +67,49 @@ func TestAccPortAction(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - kafka_method = {} - user_properties = { - "string_props" = { - "myStringIdentifier" = { - "title" = "My String Identifier" - "required" = true - + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier" = { + "title" = "My String Identifier" + "required" = true + + } } - } - "number_props" = { - "myNumberIdentifier" = { - "title" = "My Number Identifier" - "required" = true - maximum = 100 - minimum = 0 + "number_props" = { + "myNumberIdentifier" = { + "title" = "My Number Identifier" + "required" = true + maximum = 100 + minimum = 0 + } } - } - "boolean_props" = { - "myBooleanIdentifier" = { - "title" = "My Boolean Identifier" - "required" = true + "boolean_props" = { + "myBooleanIdentifier" = { + "title" = "My Boolean Identifier" + "required" = true + } } - } - "object_props" = { - "myObjectIdentifier" = { - "title" = "My Object Identifier" - "required" = true + "object_props" = { + "myObjectIdentifier" = { + "title" = "My Object Identifier" + "required" = true + } } - } - "array_props" = { - "myArrayIdentifier" = { - "title" = "My Array Identifier" - "required" = true - string_items = { - format = "email" + "array_props" = { + "myArrayIdentifier" = { + "title" = "My Array Identifier" + "required" = true + string_items = { + format = "email" + } } } } } - + kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -119,21 +122,21 @@ func TestAccPortAction(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "My String Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.required", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.title", "My Number Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.required", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.maximum", "100"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.minimum", "0"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.boolean_props.myBooleanIdentifier.title", "My Boolean Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.boolean_props.myBooleanIdentifier.required", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.object_props.myObjectIdentifier.title", "My Object Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.object_props.myObjectIdentifier.required", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myArrayIdentifier.title", "My Array Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myArrayIdentifier.required", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myArrayIdentifier.string_items.format", "email"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "My String Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.title", "My Number Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.maximum", "100"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.minimum", "0"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.title", "My Boolean Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.object_props.myObjectIdentifier.title", "My Object Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.object_props.myObjectIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myArrayIdentifier.title", "My Array Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myArrayIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myArrayIdentifier.string_items.format", "email"), ), }, }, @@ -148,8 +151,10 @@ func TestAccPortActionWebhookInvocation(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } webhook_method = { url = "https://example.com" agent = true @@ -166,8 +171,8 @@ func TestAccPortActionWebhookInvocation(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://example.com"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.agent", "true"), ), @@ -183,8 +188,10 @@ func TestAccPortActionWebhookSyncInvocation(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } webhook_method = { url = "https://example.com" synchronized = true @@ -203,8 +210,8 @@ func TestAccPortActionWebhookSyncInvocation(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://example.com"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.synchronized", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.method", "POST"), @@ -223,8 +230,10 @@ func TestAccPortActionGitlabInvocation(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } gitlab_method = { project_name = "terraform-provider-port" group_name = "port" @@ -245,14 +254,11 @@ func TestAccPortActionGitlabInvocation(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.project_name", "terraform-provider-port"), resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.group_name", "port"), - resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.omit_payload", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.omit_user_inputs", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.default_ref", "main"), - resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.agent", "true"), ), }, }, @@ -266,8 +272,10 @@ func TestAccPortActionAzureInvocation(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } azure_method = { org = "port", webhook = "https://getport.io" @@ -284,8 +292,8 @@ func TestAccPortActionAzureInvocation(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "azure_method.org", "port"), resource.TestCheckResourceAttr("port_action.create_microservice", "azure_method.webhook", "https://getport.io"), ), @@ -302,8 +310,10 @@ func TestAccPortActionGithubInvocation(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } github_method = { org = "port", repo = "terraform-provider-port", @@ -324,13 +334,11 @@ func TestAccPortActionGithubInvocation(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.org", "port"), resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.repo", "terraform-provider-port"), resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.workflow", "main.yml"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.omit_payload", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.omit_user_inputs", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.report_workflow_status", "false"), ), }, @@ -346,19 +354,21 @@ func TestAccPortActionImport(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "myStringIdentifier" = { - "title" = "My String Identifier" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier" = { + "title" = "My String Identifier" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -372,18 +382,18 @@ func TestAccPortActionImport(t *testing.T) { 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", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "My String Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "My String Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.required", "true"), ), }, { ResourceName: "port_action.create_microservice", ImportState: true, ImportStateVerify: true, - ImportStateId: fmt.Sprintf("%s:%s", blueprintIdentifier, actionIdentifier), + ImportStateId: actionIdentifier, }, }, }) @@ -397,19 +407,21 @@ func TestAccPortActionUpdate(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "myStringIdentifier" = { - "title" = "My String Identifier" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier" = { + "title" = "My String Identifier" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) var testAccActionConfigUpdate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` @@ -417,18 +429,20 @@ func TestAccPortActionUpdate(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "myStringIdentifier2" = { - "title" = "My String Identifier" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier2" = { + "title" = "My String Identifier" + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -442,11 +456,11 @@ func TestAccPortActionUpdate(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "My String Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "My String Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.required", "true"), ), }, { @@ -455,11 +469,11 @@ func TestAccPortActionUpdate(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier2.title", "My String Identifier"), - resource.TestCheckNoResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier2.required"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier2.title", "My String Identifier"), + resource.TestCheckNoResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier2.required"), ), }, }, @@ -472,9 +486,42 @@ func TestAccPortActionAdvancedFormConfigurations(t *testing.T) { var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` resource "port_action" "action1" { title = "Action 1" - blueprint = port_blueprint.microservice.id identifier = "%s" - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + string_props = { + myStringIdentifier = { + title = "myStringIdentifier" + default = "default" + } + myStringIdentifier2 = { + title = "myStringIdentifier2" + default = "default" + depends_on = ["myStringIdentifier"] + } + myStringIdentifier3 = { + title = "myStringIdentifier3" + required = true + format = "entity" + blueprint = port_blueprint.microservice.id + dataset = { + "combinator" : "and", + "rules" : [ + { + "property" : "$team", + "operator" : "containsAny", + "value" : { + "jq_query" : "Test" + } + } + ] + } + } + } + } + } description = "This is a test action" required_approval = true github_method = { @@ -482,37 +529,6 @@ func TestAccPortActionAdvancedFormConfigurations(t *testing.T) { repo = "Port" workflow = "lint" } - user_properties = { - string_props = { - myStringIdentifier = { - title = "myStringIdentifier" - default = "default" - } - myStringIdentifier2 = { - title = "myStringIdentifier2" - default = "default" - depends_on = ["myStringIdentifier"] - } - myStringIdentifier3 = { - title = "myStringIdentifier3" - required = true - format = "entity" - blueprint = port_blueprint.microservice.id - dataset = { - "combinator" : "and", - "rules" : [ - { - "property" : "$team", - "operator" : "containsAny", - "value" : { - "jq_query" : "Test" - } - } - ] - } - } - } - } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -525,25 +541,25 @@ func TestAccPortActionAdvancedFormConfigurations(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action.action1", "title", "Action 1"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "description", "This is a test action"), resource.TestCheckResourceAttr("port_action.action1", "required_approval", "true"), resource.TestCheckResourceAttr("port_action.action1", "github_method.org", "port-labs"), resource.TestCheckResourceAttr("port_action.action1", "github_method.repo", "Port"), resource.TestCheckResourceAttr("port_action.action1", "github_method.workflow", "lint"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier.default", "default"), - resource.TestCheckNoResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier.required"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.title", "myStringIdentifier2"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.default", "default"), - resource.TestCheckNoResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.required"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.depends_on.0", "myStringIdentifier"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.title", "myStringIdentifier3"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.required", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.dataset.combinator", "and"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.dataset.rules.0.property", "$team"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.dataset.rules.0.operator", "containsAny"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier3.dataset.rules.0.value.jq_query", "Test"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier.default", "default"), + resource.TestCheckNoResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier.required"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier2.title", "myStringIdentifier2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier2.default", "default"), + resource.TestCheckNoResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier2.required"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier2.depends_on.0", "myStringIdentifier"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.title", "myStringIdentifier3"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.dataset.combinator", "and"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.dataset.rules.0.property", "$team"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.dataset.rules.0.operator", "containsAny"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier3.dataset.rules.0.value.jq_query", "Test"), ), }, }, @@ -556,43 +572,45 @@ func TestAccPortActionJqDefault(t *testing.T) { var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` resource "port_action" "create_microservice" { title = "Action 1" - blueprint = port_blueprint.microservice.id identifier = "%s" - trigger = "DAY-2" - description = "This is a test action" - kafka_method = {} - user_properties = { - string_props = { - myStringIdentifier = { - title = "myStringIdentifier" - default_jq_query = "'Test'" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + string_props = { + myStringIdentifier = { + title = "myStringIdentifier" + default_jq_query = "'Test'" + } } - } - number_props = { - myNumberIdentifier = { - title = "myNumberIdentifier" - default_jq_query = "1" + number_props = { + myNumberIdentifier = { + title = "myNumberIdentifier" + default_jq_query = "1" + } } - } - boolean_props = { - myBooleanIdentifier = { - title = "myBooleanIdentifier" - default_jq_query = "true" + boolean_props = { + myBooleanIdentifier = { + title = "myBooleanIdentifier" + default_jq_query = "true" + } } - } - object_props = { - myObjectIdentifier = { - title = "myObjectIdentifier" - default_jq_query = "{ \"test\": \"test\" }" + object_props = { + myObjectIdentifier = { + title = "myObjectIdentifier" + default_jq_query = "{ \"test\": \"test\" }" + } } - } - array_props = { - myArrayIdentifier = { - title = "myArrayIdentifier" - default_jq_query = "[ \"test\" ]" + array_props = { + myArrayIdentifier = { + title = "myArrayIdentifier" + default_jq_query = "[ \"test\" ]" + } } } } + description = "This is a test action" + kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -605,18 +623,18 @@ func TestAccPortActionJqDefault(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action.create_microservice", "title", "Action 1"), resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "description", "This is a test action"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.default_jq_query", "'Test'"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.default_jq_query", "1"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.boolean_props.myBooleanIdentifier.title", "myBooleanIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.boolean_props.myBooleanIdentifier.default_jq_query", "true"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.object_props.myObjectIdentifier.title", "myObjectIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.object_props.myObjectIdentifier.default_jq_query", "{ \"test\": \"test\" }"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myArrayIdentifier.title", "myArrayIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myArrayIdentifier.default_jq_query", "[ \"test\" ]"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.default_jq_query", "'Test'"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.default_jq_query", "1"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.title", "myBooleanIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.default_jq_query", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.object_props.myObjectIdentifier.title", "myObjectIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.object_props.myObjectIdentifier.default_jq_query", "{ \"test\": \"test\" }"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myArrayIdentifier.title", "myArrayIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myArrayIdentifier.default_jq_query", "[ \"test\" ]"), ), }, }, @@ -630,40 +648,42 @@ func TestAccPortActionEnumJqQuery(t *testing.T) { var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` resource "port_action" "create_microservice" { title = "Action 1" - blueprint = port_blueprint.microservice.id identifier = "%s" - trigger = "DAY-2" - description = "This is a test action" - kafka_method = {} - user_properties = { - string_props = { - myStringIdentifier = { - title = "myStringIdentifier" - enum_jq_query = "[\"test1\", \"test2\"]" - } - } - number_props = { - myNumberIdentifier = { - title = "myNumberIdentifier" - enum_jq_query = "[1, 2]" - } - } - array_props = { - myStringArrayIdentifier = { - title = "myStringArrayIdentifier" - string_items = { - enum_jq_query = "'example' | [ . ]" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + string_props = { + myStringIdentifier = { + title = "myStringIdentifier" + enum_jq_query = "[\"test1\", \"test2\"]" } } - myNumberArrayIdentifier = { - title = "myNumberArrayIdentifier" - number_items = { + number_props = { + myNumberIdentifier = { + title = "myNumberIdentifier" enum_jq_query = "[1, 2]" } } - + array_props = { + myStringArrayIdentifier = { + title = "myStringArrayIdentifier" + string_items = { + enum_jq_query = "'example' | [ . ]" + } + } + myNumberArrayIdentifier = { + title = "myNumberArrayIdentifier" + number_items = { + enum_jq_query = "[1, 2]" + } + } + + } } } + description = "This is a test action" + kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -676,16 +696,16 @@ func TestAccPortActionEnumJqQuery(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action.create_microservice", "title", "Action 1"), resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "description", "This is a test action"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.enum_jq_query", "[\"test1\", \"test2\"]"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.enum_jq_query", "[1, 2]"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myStringArrayIdentifier.title", "myStringArrayIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myStringArrayIdentifier.string_items.enum_jq_query", "'example' | [ . ]"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myNumberArrayIdentifier.title", "myNumberArrayIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.array_props.myNumberArrayIdentifier.number_items.enum_jq_query", "[1, 2]"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.enum_jq_query", "[\"test1\", \"test2\"]"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum_jq_query", "[1, 2]"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myStringArrayIdentifier.title", "myStringArrayIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myStringArrayIdentifier.string_items.enum_jq_query", "'example' | [ . ]"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myNumberArrayIdentifier.title", "myNumberArrayIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.array_props.myNumberArrayIdentifier.number_items.enum_jq_query", "[1, 2]"), ), }, }, @@ -698,33 +718,35 @@ func TestAccPortActionEnum(t *testing.T) { var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` resource "port_action" "create_microservice" { title = "Action 1" - blueprint = port_blueprint.microservice.id identifier = "%s" - trigger = "DAY-2" - description = "This is a test action" - kafka_method = {} - user_properties = { - string_props = { - myStringIdentifier = { - title = "myStringIdentifier" - enum = ["test1", "test2"] + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + string_props = { + myStringIdentifier = { + title = "myStringIdentifier" + enum = ["test1", "test2"] + } } - } - number_props = { - myNumberIdentifier = { - title = "myNumberIdentifier" - enum = [1, 2] + number_props = { + myNumberIdentifier = { + title = "myNumberIdentifier" + enum = [1, 2] + } } - } - array_props = { - myStringArrayIdentifier = { - title = "myStringArrayIdentifier" - string_items = { - enum = ["example"] + array_props = { + myStringArrayIdentifier = { + title = "myStringArrayIdentifier" + string_items = { + enum = ["example"] + } } } } } + description = "This is a test action" + kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -737,14 +759,14 @@ func TestAccPortActionEnum(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action.create_microservice", "title", "Action 1"), resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "description", "This is a test action"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.enum.0", "test1"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.enum.1", "test2"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.enum.0", "1"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.number_props.myNumberIdentifier.enum.1", "2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "myStringIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.enum.0", "test1"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.enum.1", "test2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.title", "myNumberIdentifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum.0", "1"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum.1", "2"), ), }, }, @@ -758,20 +780,22 @@ func TestAccPortActionOrderProperties(t *testing.T) { title = "Action 1" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - kafka_method = {} - order_properties = ["myStringIdentifier2", "myStringIdentifier1"] - user_properties = { - string_props = { - myStringIdentifier1 = { - title = "myStringIdentifier1" - } - myStringIdentifier2 = { - title = "myStringIdentifier2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + order_properties = ["myStringIdentifier2", "myStringIdentifier1"] + user_properties = { + string_props = { + myStringIdentifier1 = { + title = "myStringIdentifier1" + } + myStringIdentifier2 = { + title = "myStringIdentifier2" + } } } } + kafka_method = {} }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -784,11 +808,11 @@ func TestAccPortActionOrderProperties(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action.action1", "title", "Action 1"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier1.title", "myStringIdentifier1"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.myStringIdentifier2.title", "myStringIdentifier2"), - resource.TestCheckResourceAttr("port_action.action1", "order_properties.0", "myStringIdentifier2"), - resource.TestCheckResourceAttr("port_action.action1", "order_properties.1", "myStringIdentifier1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier1.title", "myStringIdentifier1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.myStringIdentifier2.title", "myStringIdentifier2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.order_properties.0", "myStringIdentifier2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.order_properties.1", "myStringIdentifier1"), ), }, }, @@ -803,27 +827,29 @@ func TestAccPortActionEncryption(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "encryptedStringProp" = { - "title" = "Encrypted string" - "required" = true - "encryption" = "aes256-gcm" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "encryptedStringProp" = { + "title" = "Encrypted string" + "required" = true + "encryption" = "aes256-gcm" + } } - } - "object_props" = { - "encryptedObjectProp" = { - "title" = "Encrypted object" - "required" = true - "encryption" = "aes256-gcm" + "object_props" = { + "encryptedObjectProp" = { + "title" = "Encrypted object" + "required" = true + "encryption" = "aes256-gcm" + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -837,15 +863,15 @@ func TestAccPortActionEncryption(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.title", "Encrypted string"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.required", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.encryption", "aes256-gcm"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.title", "Encrypted object"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.required", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.encryption", "aes256-gcm"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.encryptedStringProp.title", "Encrypted string"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.encryptedStringProp.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.encryptedStringProp.encryption", "aes256-gcm"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.encryptedObjectProp.title", "Encrypted object"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.encryptedObjectProp.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.encryptedObjectProp.encryption", "aes256-gcm"), ), }, }, @@ -861,19 +887,21 @@ func TestAccPortActionUpdateIdentifier(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "myStringIdentifier" = { - "title" = "My String Identifier" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier" = { + "title" = "My String Identifier" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) var testAccActionConfigUpdate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` @@ -881,19 +909,21 @@ func TestAccPortActionUpdateIdentifier(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "myStringIdentifier" = { - "title" = "My String Identifier" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "myStringIdentifier" = { + "title" = "My String Identifier" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionUpdatedIdentifier) resource.Test(t, resource.TestCase{ @@ -907,11 +937,11 @@ func TestAccPortActionUpdateIdentifier(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "My String Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "My String Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.required", "true"), ), }, { @@ -920,11 +950,11 @@ func TestAccPortActionUpdateIdentifier(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionUpdatedIdentifier), resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.create_microservice", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.title", "My String Identifier"), - resource.TestCheckResourceAttr("port_action.create_microservice", "user_properties.string_props.myStringIdentifier.required", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.title", "My String Identifier"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.string_props.myStringIdentifier.required", "true"), ), }, }, @@ -939,98 +969,100 @@ func TestAccPortActionVisibility(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "visibleStringProp" = { - "title" = "visible string" - "required" = true - "visible" = true - } - "invisibleStringProp" = { - "title" = "invisible string" - "required" = true - "visible" = false - } - "jqQueryStringProp" = { - "title" = "jq based visibilty string" - "required" = true - "visible_jq_query" = "1==1" - } - } - "number_props" = { - "visibleNumberProp" = { - "title" = "visible number" - "required" = true - "visible" = true - } - "invisibleNumberProp" = { - "title" = "invisible number" - "required" = true - "visible" = false - } - "jqQueryNumberProp" = { - "title" = "jq based visibilty number" - "required" = true - "visible_jq_query" = "1==1" - } - } - "boolean_props" = { - "visibleBooleanProp" = { - "title" = "visible boolean" - "required" = true - "visible" = true - } - "invisibleBooleanProp" = { - "title" = "invisible boolean" - "required" = true - "visible" = false - } - "jqQueryBooleanProp" = { - "title" = "jq based visibilty boolean" - "required" = true - "visible_jq_query" = "1==1" - } - } - "array_props" = { - "visibleArrayProp" = { - "title" = "visible array" - "required" = true - "visible" = true - } - "invisibleArrayProp" = { - "title" = "invisible array" - "required" = true - "visible" = false + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "visibleStringProp" = { + "title" = "visible string" + "required" = true + "visible" = true + } + "invisibleStringProp" = { + "title" = "invisible string" + "required" = true + "visible" = false + } + "jqQueryStringProp" = { + "title" = "jq based visibilty string" + "required" = true + "visible_jq_query" = "1==1" + } } - "jqQueryArrayProp" = { - "title" = "jq based visibilty array" - "required" = true - "visible_jq_query" = "1==1" + "number_props" = { + "visibleNumberProp" = { + "title" = "visible number" + "required" = true + "visible" = true + } + "invisibleNumberProp" = { + "title" = "invisible number" + "required" = true + "visible" = false + } + "jqQueryNumberProp" = { + "title" = "jq based visibilty number" + "required" = true + "visible_jq_query" = "1==1" + } } - } - "object_props" = { - "visibleObjectProp" = { - "title" = "visible array" - "required" = true - "visible" = true + "boolean_props" = { + "visibleBooleanProp" = { + "title" = "visible boolean" + "required" = true + "visible" = true + } + "invisibleBooleanProp" = { + "title" = "invisible boolean" + "required" = true + "visible" = false + } + "jqQueryBooleanProp" = { + "title" = "jq based visibilty boolean" + "required" = true + "visible_jq_query" = "1==1" + } } - "invisibleObjectProp" = { - "title" = "invisible array" - "required" = true - "visible" = false + "array_props" = { + "visibleArrayProp" = { + "title" = "visible array" + "required" = true + "visible" = true + } + "invisibleArrayProp" = { + "title" = "invisible array" + "required" = true + "visible" = false + } + "jqQueryArrayProp" = { + "title" = "jq based visibilty array" + "required" = true + "visible_jq_query" = "1==1" + } } - "jqQueryObjectProp" = { - "title" = "jq based visibilty array" - "required" = true - "visible_jq_query" = "1==1" + "object_props" = { + "visibleObjectProp" = { + "title" = "visible array" + "required" = true + "visible" = true + } + "invisibleObjectProp" = { + "title" = "invisible array" + "required" = true + "visible" = false + } + "jqQueryObjectProp" = { + "title" = "jq based visibilty array" + "required" = true + "visible_jq_query" = "1==1" + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -1044,25 +1076,25 @@ func TestAccPortActionVisibility(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.visibleStringProp.visible", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.invisibleStringProp.visible", "false"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.jqQueryStringProp.visible_jq_query", "1==1"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.number_props.visibleNumberProp.visible", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.number_props.invisibleNumberProp.visible", "false"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.number_props.jqQueryNumberProp.visible_jq_query", "1==1"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.boolean_props.visibleBooleanProp.visible", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.boolean_props.invisibleBooleanProp.visible", "false"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.boolean_props.jqQueryBooleanProp.visible_jq_query", "1==1"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.array_props.visibleArrayProp.visible", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.array_props.invisibleArrayProp.visible", "false"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.array_props.jqQueryArrayProp.visible_jq_query", "1==1"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.visibleObjectProp.visible", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.invisibleObjectProp.visible", "false"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.jqQueryObjectProp.visible_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.visibleStringProp.visible", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.invisibleStringProp.visible", "false"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.jqQueryStringProp.visible_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.number_props.visibleNumberProp.visible", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.number_props.invisibleNumberProp.visible", "false"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.number_props.jqQueryNumberProp.visible_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.boolean_props.visibleBooleanProp.visible", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.boolean_props.invisibleBooleanProp.visible", "false"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.boolean_props.jqQueryBooleanProp.visible_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.array_props.visibleArrayProp.visible", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.array_props.invisibleArrayProp.visible", "false"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.array_props.jqQueryArrayProp.visible_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.visibleObjectProp.visible", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.invisibleObjectProp.visible", "false"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.object_props.jqQueryObjectProp.visible_jq_query", "1==1"), ), }, }, @@ -1077,23 +1109,25 @@ func TestAccPortActionRequiredConflictsWithRequiredJQ(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "equalsOne" = { - "title" = "equalsOne" - "required" = true - } - "notEqualsOne" = { - "title" = "notEqualsOne" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "equalsOne" = { + "title" = "equalsOne" + "required" = true + } + "notEqualsOne" = { + "title" = "notEqualsOne" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) var testAccActionConfigUpdate = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(` @@ -1101,24 +1135,26 @@ func TestAccPortActionRequiredConflictsWithRequiredJQ(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "equalsOne" = { - "title" = "equalsOne" - "required" = true - } - "notEqualsOne" = { - "title" = "notEqualsOne" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "equalsOne" = { + "title" = "equalsOne" + "required" = true + } + "notEqualsOne" = { + "title" = "notEqualsOne" + "required" = true + } } } + required_jq_query = "1==1" + } + webhook_method = { + url = "https://getport.io" } - required_jq_query = "1==1" }`, actionIdentifier) var testAccActionConfigUpdate2 = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(` @@ -1126,22 +1162,24 @@ func TestAccPortActionRequiredConflictsWithRequiredJQ(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "equalsOne" = { - "title" = "equalsOne" - } - "notEqualsOne" = { - "title" = "notEqualsOne" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "equalsOne" = { + "title" = "equalsOne" + } + "notEqualsOne" = { + "title" = "notEqualsOne" + } } } + required_jq_query = "1==1" + } + webhook_method = { + url = "https://getport.io" } - required_jq_query = "1==1" }`, actionIdentifier) // expect a failure when applying the update @@ -1157,13 +1195,13 @@ func TestAccPortActionRequiredConflictsWithRequiredJQ(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.equalsOne.title", "equalsOne"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.equalsOne.required", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.notEqualsOne.title", "notEqualsOne"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.notEqualsOne.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.equalsOne.title", "equalsOne"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.equalsOne.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notEqualsOne.title", "notEqualsOne"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notEqualsOne.required", "true"), ), }, { @@ -1176,14 +1214,14 @@ func TestAccPortActionRequiredConflictsWithRequiredJQ(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.equalsOne.title", "equalsOne"), - resource.TestCheckNoResourceAttr("port_action.action1", "user_properties.string_props.equalsOne.required"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.notEqualsOne.title", "notEqualsOne"), - resource.TestCheckNoResourceAttr("port_action.action1", "user_properties.string_props.notEqualsOne.required"), - resource.TestCheckResourceAttr("port_action.action1", "required_jq_query", "1==1"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.equalsOne.title", "equalsOne"), + resource.TestCheckNoResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.equalsOne.required"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notEqualsOne.title", "notEqualsOne"), + resource.TestCheckNoResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notEqualsOne.required"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.required_jq_query", "1==1"), ), }, }, @@ -1198,22 +1236,24 @@ func TestAccPortActionRequiredFalseAndNull(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" - webhook_method = { - url = "https://getport.io" - } - user_properties = { - "string_props" = { - "notRequiredExist" = { - "title" = "notEqualsOne" - } - "requiredTrue" = { - "title" = "notEqualsOne" - "required" = true + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + "string_props" = { + "notRequiredExist" = { + "title" = "notEqualsOne" + } + "requiredTrue" = { + "title" = "notEqualsOne" + "required" = true + } } } } + webhook_method = { + url = "https://getport.io" + } }`, actionIdentifier) resource.Test(t, resource.TestCase{ @@ -1228,13 +1268,13 @@ func TestAccPortActionRequiredFalseAndNull(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), - resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.blueprint_identifier", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.notRequiredExist.title", "notEqualsOne"), - resource.TestCheckNoResourceAttr("port_action.action1", "user_properties.string_props.notRequiredExist.required"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.requiredTrue.title", "notEqualsOne"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.requiredTrue.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notRequiredExist.title", "notEqualsOne"), + resource.TestCheckNoResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.notRequiredExist.required"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.requiredTrue.title", "notEqualsOne"), + resource.TestCheckResourceAttr("port_action.action1", "self_service_trigger.user_properties.string_props.requiredTrue.required", "true"), ), }, }, From 5f4ecdbfbdbf40a8454953e5c2dee15bc1681f7a Mon Sep 17 00:00:00 2001 From: talsabagport Date: Sun, 14 Jan 2024 18:32:23 +0200 Subject: [PATCH 05/13] fix and add tests --- port/action-permissions/resource_test.go | 38 +-- port/action/actionStateToPortBody.go | 6 +- port/action/refreshActionState.go | 3 +- port/action/resource_test.go | 302 +++++++++++++++++++++-- 4 files changed, 309 insertions(+), 40 deletions(-) diff --git a/port/action-permissions/resource_test.go b/port/action-permissions/resource_test.go index 5f30e579..abf1238e 100644 --- a/port/action-permissions/resource_test.go +++ b/port/action-permissions/resource_test.go @@ -29,8 +29,10 @@ func testAccCreateBlueprintAndActionConfig(blueprintIdentifier string, actionIde title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.identifier - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } kafka_method = {} }`, blueprintIdentifier, actionIdentifier) } @@ -39,7 +41,7 @@ func TestAccPortActionPermissionsBasic(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -63,7 +65,7 @@ func TestAccPortActionPermissionsBasic(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -84,7 +86,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { teamName := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -109,7 +111,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { } resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -136,7 +138,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -150,7 +152,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "1"), @@ -173,7 +175,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -221,7 +223,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { var testAccActionPermissionsConfigUpdate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -246,7 +248,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -261,7 +263,7 @@ func TestAccPortActionPermissionsWithPolicy(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -281,7 +283,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -329,7 +331,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { var testAccActionPermissionsConfigUpdate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -381,7 +383,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -396,7 +398,7 @@ func TestAccPortActionPermissionsWithPolicyUpdate(t *testing.T) { { Config: testAccActionPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), @@ -417,7 +419,7 @@ func TestAccPortActionPermissionsImportState(t *testing.T) { actionIdentifier := utils.GenID() var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { - action_identifier = "${port_blueprint.microservice.identifier}_${port_action.create_microservice.identifier}" + action_identifier = port_action.create_microservice.identifier permissions = { "execute": { "roles": [ @@ -469,7 +471,7 @@ func TestAccPortActionPermissionsImportState(t *testing.T) { { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier)), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index e49a5d7a..069837a9 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -327,6 +327,10 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca } if data.UpsertEntityMethod != nil { + var team interface{} + if data.UpsertEntityMethod.Teams != nil { + team = flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Teams) + } p, err := utils.TerraformStringToGoObject(data.UpsertEntityMethod.Properties) if err != nil { return nil, err @@ -343,7 +347,7 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca Identifier: data.UpsertEntityMethod.Identifier.ValueStringPointer(), Title: data.UpsertEntityMethod.Title.ValueStringPointer(), BlueprintIdentifier: data.UpsertEntityMethod.BlueprintIdentifier.ValueStringPointer(), - Team: flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Teams), + Team: team, Icon: data.UpsertEntityMethod.Icon.ValueStringPointer(), Properties: properties, Relations: relations, diff --git a/port/action/refreshActionState.go b/port/action/refreshActionState.go index dda9d81a..93f1c4e2 100644 --- a/port/action/refreshActionState.go +++ b/port/action/refreshActionState.go @@ -78,7 +78,7 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state * state.GitlabMethod = &GitlabMethodModel{ ProjectName: types.StringValue(*a.InvocationMethod.ProjectName), GroupName: types.StringValue(*a.InvocationMethod.GroupName), - DefaultRef: types.StringValue(*a.InvocationMethod.DefaultRef), + DefaultRef: flex.GoStringToFramework(a.InvocationMethod.DefaultRef), PipelineVariables: pipelineVariables, } } @@ -102,6 +102,7 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state * case string: teams = append(teams, types.StringValue(team)) case []interface{}: + teams = make([]types.String, 0) for _, t := range team { teams = append(teams, types.StringValue(t.(string))) } diff --git a/port/action/resource_test.go b/port/action/resource_test.go index b0f3fdc5..454b484f 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -18,9 +18,10 @@ func testAccCreateBlueprintConfig(identifier string) string { identifier = "%s" properties = { string_props = { - "text" = { - type = "string" - title = "text" + "timer" = { + type = "string" + title = "timer" + format = "timer" } } } @@ -143,6 +144,44 @@ func TestAccPortAction(t *testing.T) { }) } +func TestAccPortActionKafkaInvocation(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } + kafka_method = { + payload = jsonencode({ + "runId": "{{run.id}}" + }) + } + }`, 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", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "kafka_method.payload", "{\"runId\":\"{{run.id}}\"}"), + ), + }, + }, + }) +} + func TestAccPortActionWebhookInvocation(t *testing.T) { identifier := utils.GenID() actionIdentifier := utils.GenID() @@ -158,6 +197,10 @@ func TestAccPortActionWebhookInvocation(t *testing.T) { webhook_method = { url = "https://example.com" agent = true + synchronized = false + method = "PUT" + headers = {"X-HEADER-TEST": "{{action.identifier}}"} + body = jsonencode({"runId": "{{run.id}}"}) } }`, actionIdentifier) @@ -175,6 +218,10 @@ func TestAccPortActionWebhookInvocation(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://example.com"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.agent", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.synchronized", "false"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.method", "PUT"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.headers.X-HEADER-TEST", "{{action.identifier}}"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.body", "{\"runId\":\"{{run.id}}\"}"), ), }, }, @@ -197,6 +244,8 @@ func TestAccPortActionWebhookSyncInvocation(t *testing.T) { synchronized = true agent = true method = "POST" + headers = {"X-HEADER-TEST": "{{action.identifier}}"} + body = jsonencode({"runId": "{{run.id}}"}) } }`, actionIdentifier) @@ -216,6 +265,52 @@ func TestAccPortActionWebhookSyncInvocation(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.synchronized", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.method", "POST"), resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.agent", "true"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.headers.X-HEADER-TEST", "{{action.identifier}}"), + resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.body", "{\"runId\":\"{{run.id}}\"}"), + ), + }, + }, + }) +} + +func TestAccPortActionGithubInvocation(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } + github_method = { + org = "port", + repo = "terraform-provider-port", + workflow = "main.yml" + workflow_inputs = jsonencode({"test-array-param": [1, true, "a", {"a": []}, null, [2]]}) + report_workflow_status = false + } + }`, 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", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.org", "port"), + resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.repo", "terraform-provider-port"), + resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.workflow", "main.yml"), + resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.workflow_inputs", "{\"test-array-param\":[1,true,\"a\",{\"a\":[]},null,[2]]}"), + resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.report_workflow_status", "false"), ), }, }, @@ -237,10 +332,8 @@ func TestAccPortActionGitlabInvocation(t *testing.T) { gitlab_method = { project_name = "terraform-provider-port" group_name = "port" - omit_payload = true - omit_user_inputs = true - default_ref = "main" - agent = true + default_ref = "test" + pipeline_variables = jsonencode({"test-array-param": [1, true, "a", {"a": []}, null, [2]]}) } }`, actionIdentifier) @@ -258,7 +351,8 @@ func TestAccPortActionGitlabInvocation(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.project_name", "terraform-provider-port"), resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.group_name", "port"), - resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.default_ref", "main"), + resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.default_ref", "test"), + resource.TestCheckResourceAttr("port_action.create_microservice", "gitlab_method.pipeline_variables", "{\"test-array-param\":[1,true,\"a\",{\"a\":[]},null,[2]]}"), ), }, }, @@ -279,6 +373,7 @@ func TestAccPortActionAzureInvocation(t *testing.T) { azure_method = { org = "port", webhook = "https://getport.io" + payload = jsonencode({"runId": "{{run.id}}"}) } }`, actionIdentifier) @@ -296,13 +391,14 @@ func TestAccPortActionAzureInvocation(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "azure_method.org", "port"), resource.TestCheckResourceAttr("port_action.create_microservice", "azure_method.webhook", "https://getport.io"), + resource.TestCheckResourceAttr("port_action.create_microservice", "azure_method.payload", "{\"runId\":\"{{run.id}}\"}"), ), }, }, }) } -func TestAccPortActionGithubInvocation(t *testing.T) { +func TestAccPortActionUpsertEntityInvocation(t *testing.T) { identifier := utils.GenID() actionIdentifier := utils.GenID() var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` @@ -314,13 +410,14 @@ func TestAccPortActionGithubInvocation(t *testing.T) { operation = "DAY-2" blueprint_identifier = port_blueprint.microservice.identifier } - github_method = { - org = "port", - repo = "terraform-provider-port", - workflow = "main.yml" - omit_payload = true - omit_user_inputs = true - report_workflow_status = false + upsert_entity_method = { + identifier = "test-entity" + title = "Test Entity" + blueprint_identifier = port_blueprint.microservice.identifier + teams = [] + icon = "Terraform" + properties = jsonencode({"text": "test"}) + relations = jsonencode({"test-rel": "target-bp"}) } }`, actionIdentifier) @@ -336,10 +433,13 @@ func TestAccPortActionGithubInvocation(t *testing.T) { resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"), resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.org", "port"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.repo", "terraform-provider-port"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.workflow", "main.yml"), - resource.TestCheckResourceAttr("port_action.create_microservice", "github_method.report_workflow_status", "false"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.identifier", "test-entity"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.title", "Test Entity"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.teams.#", "0"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.icon", "Terraform"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.properties", "{\"text\":\"test\"}"), + resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.relations", "{\"test-rel\":\"target-bp\"}"), ), }, }, @@ -1280,3 +1380,165 @@ func TestAccPortActionRequiredFalseAndNull(t *testing.T) { }, }) } + +func TestAccPortAutomationEntityCreated(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + automation_trigger = { + entity_created_event = { + blueprint_identifier = port_blueprint.microservice.identifier + } + } + kafka_method = {} + }`, 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.entity_created_event.blueprint_identifier", identifier), + ), + }, + }, + }) +} + +func TestAccPortAutomationEntityUpdated(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + automation_trigger = { + entity_updated_event = { + blueprint_identifier = port_blueprint.microservice.identifier + } + } + kafka_method = {} + }`, 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.entity_updated_event.blueprint_identifier", identifier), + ), + }, + }, + }) +} + +func TestAccPortAutomationEntityDeleted(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + automation_trigger = { + entity_deleted_event = { + blueprint_identifier = port_blueprint.microservice.identifier + } + } + kafka_method = {} + }`, 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.entity_deleted_event.blueprint_identifier", identifier), + ), + }, + }, + }) +} + +func TestAccPortAutomationAnyEntityChange(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + automation_trigger = { + any_entity_change_event = { + blueprint_identifier = port_blueprint.microservice.identifier + } + } + kafka_method = {} + }`, 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_entity_change_event.blueprint_identifier", identifier), + ), + }, + }, + }) +} + +func TestAccPortAutomationTimerPropertyExpired(t *testing.T) { + identifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` + resource "port_action" "create_microservice" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + automation_trigger = { + timer_property_expired_event = { + blueprint_identifier = port_blueprint.microservice.identifier + property_identifier = "timer" + } + } + kafka_method = {} + }`, 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.timer_property_expired_event.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.timer_property_expired_event.property_identifier", "timer"), + ), + }, + }, + }) +} From 2c87614db9d5c739dd51117720d8d091954ffd22 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Sun, 14 Jan 2024 18:41:08 +0200 Subject: [PATCH 06/13] fix and add tests --- port/action-permissions/resource_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/port/action-permissions/resource_test.go b/port/action-permissions/resource_test.go index abf1238e..91570b42 100644 --- a/port/action-permissions/resource_test.go +++ b/port/action-permissions/resource_test.go @@ -117,7 +117,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { "roles": [ "Member", ], - "users": ["test-member-user@test.com"], + "users": [], "teams": [port_team.team.name], "owned_by_team": false }, @@ -155,8 +155,7 @@ func TestAccPortActionPermissionsUpdate(t *testing.T) { resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.0", "Member"), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "1"), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.0", "test-member-user@test.com"), + resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.teams.#", "1"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.teams.0", teamName), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.owned_by_team", "false"), From 6a3797506665666d40aace2392e48f1cb32fa788 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Sun, 14 Jan 2024 19:16:10 +0200 Subject: [PATCH 07/13] Add docs --- docs/resources/port_action.md | 290 +++++++++++++------- docs/resources/port_action_permissions.md | 128 +++++---- docs/resources/port_aggregation_property.md | 2 + docs/resources/port_blueprint.md | 2 + docs/resources/port_entity.md | 2 + docs/resources/port_scorecard.md | 2 + docs/resources/port_team.md | 2 + docs/resources/port_webhook.md | 2 + 8 files changed, 272 insertions(+), 158 deletions(-) diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md index 798f5283..019c3681 100644 --- a/docs/resources/port_action.md +++ b/docs/resources/port_action.md @@ -17,26 +17,26 @@ Action resource ### Required -- `blueprint` (String) The blueprint identifier the action relates to - `identifier` (String) Identifier -- `title` (String) Title -- `trigger` (String) The trigger type of the action ### Optional - `approval_email_notification` (Object) The email notification of the approval (see [below for nested schema](#nestedatt--approval_email_notification)) - `approval_webhook_notification` (Attributes) The webhook notification of the approval (see [below for nested schema](#nestedatt--approval_webhook_notification)) -- `azure_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--azure_method)) +- `automation_trigger` (Attributes) Automation trigger for the action (see [below for nested schema](#nestedatt--automation_trigger)) +- `azure_method` (Attributes) Azure DevOps invocation method (see [below for nested schema](#nestedatt--azure_method)) +- `blueprint` (String, Deprecated) The blueprint identifier the action relates to - `description` (String) Description -- `github_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--github_method)) -- `gitlab_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--gitlab_method)) +- `github_method` (Attributes) GitHub invocation method (see [below for nested schema](#nestedatt--github_method)) +- `gitlab_method` (Attributes) Gitlab invocation method (see [below for nested schema](#nestedatt--gitlab_method)) - `icon` (String) Icon -- `kafka_method` (Object) The invocation method of the action (see [below for nested schema](#nestedatt--kafka_method)) -- `order_properties` (List of String) Order properties +- `kafka_method` (Attributes) Kafka invocation method (see [below for nested schema](#nestedatt--kafka_method)) +- `publish` (Boolean) Publish action - `required_approval` (Boolean) Require approval before invoking the action -- `required_jq_query` (String) The required jq query of the property -- `user_properties` (Attributes) User properties (see [below for nested schema](#nestedatt--user_properties)) -- `webhook_method` (Attributes) The invocation method of the action (see [below for nested schema](#nestedatt--webhook_method)) +- `self_service_trigger` (Attributes) Self service trigger for the action (see [below for nested schema](#nestedatt--self_service_trigger)) +- `title` (String) Title +- `upsert_entity_method` (Attributes) Upsert Entity invocation method (see [below for nested schema](#nestedatt--upsert_entity_method)) +- `webhook_method` (Attributes) Webhook invocation method (see [below for nested schema](#nestedatt--webhook_method)) ### Read-Only @@ -57,6 +57,72 @@ Required: - `url` (String) The URL to invoke the webhook + +### Nested Schema for `automation_trigger` + +Optional: + +- `any_entity_change_event` (Attributes) Any entity change event trigger (see [below for nested schema](#nestedatt--automation_trigger--any_entity_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)) +- `timer_property_expired_event` (Attributes) Timer property expired event trigger (see [below for nested schema](#nestedatt--automation_trigger--timer_property_expired_event)) + + +### Nested Schema for `automation_trigger.any_entity_change_event` + +Required: + +- `blueprint_identifier` (String) The blueprint identifier of the changed entity + + + +### Nested Schema for `automation_trigger.entity_created_event` + +Required: + +- `blueprint_identifier` (String) The blueprint identifier of the created entity + + + +### Nested Schema for `automation_trigger.entity_deleted_event` + +Required: + +- `blueprint_identifier` (String) The blueprint identifier of the deleted entity + + + +### Nested Schema for `automation_trigger.entity_updated_event` + +Required: + +- `blueprint_identifier` (String) The blueprint identifier of the updated entity + + + +### Nested Schema for `automation_trigger.jq_condition` + +Required: + +- `expressions` (List of String) The jq expressions of the condition + +Optional: + +- `combinator` (String) The combinator of the condition + + + +### Nested Schema for `automation_trigger.timer_property_expired_event` + +Required: + +- `blueprint_identifier` (String) The blueprint identifier of the expired timer property +- `property_identifier` (String) The property identifier of the expired timer property + + + ### Nested Schema for `azure_method` @@ -65,6 +131,10 @@ Required: - `org` (String) Required when selecting type AZURE. The Azure org that the workflow belongs to - `webhook` (String) Required when selecting type AZURE. The Azure webhook that the workflow belongs to +Optional: + +- `payload` (String) The Azure Devops workflow payload (array or object encoded to a string) + ### Nested Schema for `github_method` @@ -77,9 +147,8 @@ Required: Optional: -- `omit_payload` (Boolean) Omit the payload when invoking the action -- `omit_user_inputs` (Boolean) Omit the user inputs when invoking the action -- `report_workflow_status` (Boolean) Report the workflow status when invoking the action +- `report_workflow_status` (String) Report the workflow status when invoking the action +- `workflow_inputs` (String) The GitHub workflow inputs (key-value object encoded to a string) @@ -92,10 +161,8 @@ Required: Optional: -- `agent` (Boolean) Use the agent to invoke the action - `default_ref` (String) The default ref of the action -- `omit_payload` (Boolean) Omit the payload when invoking the action -- `omit_user_inputs` (Boolean) Omit the user inputs when invoking the action +- `pipeline_variables` (String) The Gitlab pipeline variables (key-value object encoded to a string) @@ -103,71 +170,86 @@ Optional: Optional: +- `payload` (String) The Kafka message payload (array or object encoded to a string) + + + +### Nested Schema for `self_service_trigger` + +Required: + +- `operation` (String) The operation type of the action + +Optional: +- `blueprint_identifier` (String) The ID of the blueprint +- `order_properties` (List of String) Order properties +- `required_jq_query` (String) The required jq query of the property +- `user_properties` (Attributes) User properties (see [below for nested schema](#nestedatt--self_service_trigger--user_properties)) - -### Nested Schema for `user_properties` + +### Nested Schema for `self_service_trigger.user_properties` Optional: -- `array_props` (Attributes Map) The array property of the action (see [below for nested schema](#nestedatt--user_properties--array_props)) -- `boolean_props` (Attributes Map) The boolean property of the action (see [below for nested schema](#nestedatt--user_properties--boolean_props)) -- `number_props` (Attributes Map) The number property of the action (see [below for nested schema](#nestedatt--user_properties--number_props)) -- `object_props` (Attributes Map) The object property of the action (see [below for nested schema](#nestedatt--user_properties--object_props)) -- `string_props` (Attributes Map) The string property of the action (see [below for nested schema](#nestedatt--user_properties--string_props)) +- `array_props` (Attributes Map) The array property of the action (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props)) +- `boolean_props` (Attributes Map) The boolean property of the action (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--boolean_props)) +- `number_props` (Attributes Map) The number property of the action (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--number_props)) +- `object_props` (Attributes Map) The object property of the action (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--object_props)) +- `string_props` (Attributes Map) The string property of the action (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--string_props)) - -### Nested Schema for `user_properties.array_props` + +### Nested Schema for `self_service_trigger.user_properties.array_props` Optional: -- `boolean_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--user_properties--array_props--boolean_items)) -- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--user_properties--array_props--dataset)) +- `boolean_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--boolean_items)) +- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--dataset)) - `default_jq_query` (String) The default jq query of the array property - `depends_on` (List of String) The properties that this property depends on - `description` (String) The description of the property - `icon` (String) The icon of the property - `max_items` (Number) The max items of the array property - `min_items` (Number) The min items of the array property -- `number_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--user_properties--array_props--number_items)) -- `object_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--user_properties--array_props--object_items)) +- `number_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--number_items)) +- `object_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--object_items)) - `required` (Boolean) Whether the property is required, by default not required, this property can't be set at the same time if `required_jq_query` is set, and only supports true as value -- `string_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--user_properties--array_props--string_items)) +- `string_items` (Attributes) The items of the array property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--string_items)) - `title` (String) The title of the property - `visible` (Boolean) The visibility of the array property - `visible_jq_query` (String) The visibility condition jq query of the array property - -### Nested Schema for `user_properties.array_props.boolean_items` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query` Optional: - `default` (List of Boolean) The default of the items - -### Nested Schema for `user_properties.array_props.dataset` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query` Required: - `combinator` (String) The combinator of the dataset -- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--user_properties--array_props--dataset--rules)) +- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--visible_jq_query--rules)) - -### Nested Schema for `user_properties.array_props.dataset.rules` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query.rules` Required: - `operator` (String) The operator of the rule -- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--user_properties--array_props--dataset--rules--value)) +- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--visible_jq_query--rules--value)) Optional: - `blueprint` (String) The blueprint identifier of the rule - `property` (String) The property identifier of the rule - -### Nested Schema for `user_properties.array_props.dataset.rules.value` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query.rules.property` Optional: @@ -176,8 +258,8 @@ Optional: - -### Nested Schema for `user_properties.array_props.number_items` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query` Optional: @@ -186,16 +268,16 @@ Optional: - `enum_jq_query` (String) The enum jq query of the number items - -### Nested Schema for `user_properties.array_props.object_items` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query` Optional: - `default` (List of Map of String) The default of the items - -### Nested Schema for `user_properties.array_props.string_items` + +### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query` Optional: @@ -207,12 +289,12 @@ Optional: - -### Nested Schema for `user_properties.boolean_props` + +### Nested Schema for `self_service_trigger.user_properties.boolean_props` Optional: -- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--user_properties--boolean_props--dataset)) +- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--boolean_props--dataset)) - `default` (Boolean) The default of the boolean property - `default_jq_query` (String) The default jq query of the boolean property - `depends_on` (List of String) The properties that this property depends on @@ -223,29 +305,29 @@ Optional: - `visible` (Boolean) The visibility of the boolean property - `visible_jq_query` (String) The visibility condition jq query of the boolean property - -### Nested Schema for `user_properties.boolean_props.dataset` + +### Nested Schema for `self_service_trigger.user_properties.boolean_props.visible_jq_query` Required: - `combinator` (String) The combinator of the dataset -- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--user_properties--boolean_props--dataset--rules)) +- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--boolean_props--visible_jq_query--rules)) - -### Nested Schema for `user_properties.boolean_props.dataset.rules` + +### Nested Schema for `self_service_trigger.user_properties.boolean_props.visible_jq_query.rules` Required: - `operator` (String) The operator of the rule -- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--user_properties--boolean_props--dataset--rules--value)) +- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--boolean_props--visible_jq_query--rules--value)) Optional: - `blueprint` (String) The blueprint identifier of the rule - `property` (String) The property identifier of the rule - -### Nested Schema for `user_properties.boolean_props.dataset.rules.value` + +### Nested Schema for `self_service_trigger.user_properties.boolean_props.visible_jq_query.rules.property` Optional: @@ -255,12 +337,12 @@ Optional: - -### Nested Schema for `user_properties.number_props` + +### Nested Schema for `self_service_trigger.user_properties.number_props` Optional: -- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--user_properties--number_props--dataset)) +- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--number_props--dataset)) - `default` (Number) The default of the number property - `default_jq_query` (String) The default jq query of the number property - `depends_on` (List of String) The properties that this property depends on @@ -275,29 +357,29 @@ Optional: - `visible` (Boolean) The visibility of the number property - `visible_jq_query` (String) The visibility condition jq query of the number property - -### Nested Schema for `user_properties.number_props.dataset` + +### Nested Schema for `self_service_trigger.user_properties.number_props.visible_jq_query` Required: - `combinator` (String) The combinator of the dataset -- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--user_properties--number_props--dataset--rules)) +- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--number_props--visible_jq_query--rules)) - -### Nested Schema for `user_properties.number_props.dataset.rules` + +### Nested Schema for `self_service_trigger.user_properties.number_props.visible_jq_query.rules` Required: - `operator` (String) The operator of the rule -- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--user_properties--number_props--dataset--rules--value)) +- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--number_props--visible_jq_query--rules--value)) Optional: - `blueprint` (String) The blueprint identifier of the rule - `property` (String) The property identifier of the rule - -### Nested Schema for `user_properties.number_props.dataset.rules.value` + +### Nested Schema for `self_service_trigger.user_properties.number_props.visible_jq_query.rules.property` Optional: @@ -307,12 +389,12 @@ Optional: - -### Nested Schema for `user_properties.object_props` + +### Nested Schema for `self_service_trigger.user_properties.object_props` Optional: -- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--user_properties--object_props--dataset)) +- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--object_props--dataset)) - `default` (String) The default of the object property - `default_jq_query` (String) The default jq query of the object property - `depends_on` (List of String) The properties that this property depends on @@ -324,29 +406,29 @@ Optional: - `visible` (Boolean) The visibility of the object property - `visible_jq_query` (String) The visibility condition jq query of the object property - -### Nested Schema for `user_properties.object_props.dataset` + +### Nested Schema for `self_service_trigger.user_properties.object_props.visible_jq_query` Required: - `combinator` (String) The combinator of the dataset -- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--user_properties--object_props--dataset--rules)) +- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--object_props--visible_jq_query--rules)) - -### Nested Schema for `user_properties.object_props.dataset.rules` + +### Nested Schema for `self_service_trigger.user_properties.object_props.visible_jq_query.rules` Required: - `operator` (String) The operator of the rule -- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--user_properties--object_props--dataset--rules--value)) +- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--object_props--visible_jq_query--rules--value)) Optional: - `blueprint` (String) The blueprint identifier of the rule - `property` (String) The property identifier of the rule - -### Nested Schema for `user_properties.object_props.dataset.rules.value` + +### Nested Schema for `self_service_trigger.user_properties.object_props.visible_jq_query.rules.property` Optional: @@ -356,13 +438,13 @@ Optional: - -### Nested Schema for `user_properties.string_props` + +### Nested Schema for `self_service_trigger.user_properties.string_props` Optional: - `blueprint` (String) The blueprint identifier the string property relates to -- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--user_properties--string_props--dataset)) +- `dataset` (Attributes) The dataset of the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--string_props--dataset)) - `default` (String) The default of the string property - `default_jq_query` (String) The default jq query of the string property - `depends_on` (List of String) The properties that this property depends on @@ -380,29 +462,29 @@ Optional: - `visible` (Boolean) The visibility of the string property - `visible_jq_query` (String) The visibility condition jq query of the string property - -### Nested Schema for `user_properties.string_props.dataset` + +### Nested Schema for `self_service_trigger.user_properties.string_props.visible_jq_query` Required: - `combinator` (String) The combinator of the dataset -- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--user_properties--string_props--dataset--rules)) +- `rules` (Attributes List) The rules of the dataset (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--string_props--visible_jq_query--rules)) - -### Nested Schema for `user_properties.string_props.dataset.rules` + +### Nested Schema for `self_service_trigger.user_properties.string_props.visible_jq_query.rules` Required: - `operator` (String) The operator of the rule -- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--user_properties--string_props--dataset--rules--value)) +- `value` (Object) The value of the rule (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--string_props--visible_jq_query--rules--value)) Optional: - `blueprint` (String) The blueprint identifier of the rule - `property` (String) The property identifier of the rule - -### Nested Schema for `user_properties.string_props.dataset.rules.value` + +### Nested Schema for `self_service_trigger.user_properties.string_props.visible_jq_query.rules.property` Optional: @@ -413,6 +495,24 @@ Optional: + + +### Nested Schema for `upsert_entity_method` + +Required: + +- `blueprint_identifier` (String) Required when selecting type Upsert Entity. The blueprint identifier of the entity for the upsert +- `identifier` (String) Required when selecting type Upsert Entity. The entity identifier for the upsert + +Optional: + +- `icon` (String) The icon of the entity +- `properties` (String) The properties of the entity (key-value object encoded to a string) +- `relations` (String) The relations of the entity (key-value object encoded to a string) +- `teams` (List of String) The teams the entity belongs to +- `title` (String) The title of the entity + + ### Nested Schema for `webhook_method` @@ -422,6 +522,10 @@ Required: Optional: -- `agent` (Boolean) Use the agent to invoke the action +- `agent` (String) Use the agent to invoke the action +- `body` (String) The Webhook body (array or object encoded to a string) +- `headers` (Map of String) The HTTP method to invoke the action - `method` (String) The HTTP method to invoke the action -- `synchronized` (Boolean) Synchronize the action +- `synchronized` (String) Synchronize the action + + diff --git a/docs/resources/port_action_permissions.md b/docs/resources/port_action_permissions.md index 6d5c6a39..5f1f2fb9 100644 --- a/docs/resources/port_action_permissions.md +++ b/docs/resources/port_action_permissions.md @@ -9,20 +9,19 @@ description: |- hcl resource "port_action_permissions" "restart_microservice_permissions" { action_identifier = port_action.restart_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { - "execute": { - "roles": [ + "execute" : { + "roles" : [ "Admin" ], - "users": [], - "teams": [], - "owned_by_team": true + "users" : [], + "teams" : [], + "owned_by_team" : true }, - "approve": { - "roles": ["Member", "Admin"], - "users": [], - "teams": [] + "approve" : { + "roles" : ["Member", "Admin"], + "users" : [], + "teams" : [] } } } @@ -35,42 +34,41 @@ description: |- ```hcl resource "portactionpermissions" "restartmicroservicepermissions" { actionidentifier = portaction.restartmicroservice.identifier - blueprintidentifier = portblueprint.microservice.identifier permissions = { - "execute": { - "roles": [ + "execute" : { + "roles" : [ "Admin" ], - "users": [], - "teams": [], - "ownedbyteam": true + "users" : [], + "teams" : [], + "ownedbyteam" : true }, - "approve": { - "roles": ["Member", "Admin"], - "users": [], - "teams": [] + "approve" : { + "roles" : ["Member", "Admin"], + "users" : [], + "teams" : [] # Terraform's "jsonencode" function converts a # Terraform expression result to valid JSON syntax. - "policy": jsonencode( + "policy" : jsonencode( { - queries: { - executingUser: { - rules: [ + queries : { + executingUser : { + rules : [ { - value: "user", - operator: "=", - property: "$blueprint" + value : "user", + operator : "=", + property : "$blueprint" }, { - value: "true", - operator: "=", - property: "$ownedby_team" + value : "true", + operator : "=", + property : "$ownedby_team" } ], - combinator: "and" + combinator : "and" } }, - conditions: [ + conditions : [ "true"] } ) @@ -94,20 +92,19 @@ Docs for the Action Permissions resource can be found [here](https://docs.getpor ```hcl resource "port_action_permissions" "restart_microservice_permissions" { action_identifier = port_action.restart_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { - "execute": { - "roles": [ + "execute" : { + "roles" : [ "Admin" ], - "users": [], - "teams": [], - "owned_by_team": true + "users" : [], + "teams" : [], + "owned_by_team" : true }, - "approve": { - "roles": ["Member", "Admin"], - "users": [], - "teams": [] + "approve" : { + "roles" : ["Member", "Admin"], + "users" : [], + "teams" : [] } } } @@ -125,43 +122,42 @@ To pass a JSON string to Terraform, you can use the [jsonencode](https://develop ```hcl resource "port_action_permissions" "restart_microservice_permissions" { action_identifier = port_action.restart_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { - "execute": { - "roles": [ + "execute" : { + "roles" : [ "Admin" ], - "users": [], - "teams": [], - "owned_by_team": true + "users" : [], + "teams" : [], + "owned_by_team" : true }, - "approve": { - "roles": ["Member", "Admin"], - "users": [], - "teams": [] + "approve" : { + "roles" : ["Member", "Admin"], + "users" : [], + "teams" : [] # Terraform's "jsonencode" function converts a # Terraform expression result to valid JSON syntax. - "policy": jsonencode( + "policy" : jsonencode( { - queries: { - executingUser: { - rules: [ + queries : { + executingUser : { + rules : [ { - value: "user", - operator: "=", - property: "$blueprint" + value : "user", + operator : "=", + property : "$blueprint" }, { - value: "true", - operator: "=", - property: "$owned_by_team" + value : "true", + operator : "=", + property : "$owned_by_team" } ], - combinator: "and" + combinator : "and" } }, - conditions: [ + conditions : [ "true"] } ) @@ -183,10 +179,10 @@ resource "port_action_permissions" "restart_microservice_permissions" { ### Required - `action_identifier` (String) The ID of the action -- `blueprint_identifier` (String) The ID of the blueprint ### Optional +- `blueprint_identifier` (String, Deprecated) The ID of the blueprint - `permissions` (Attributes) The permissions for the action (see [below for nested schema](#nestedatt--permissions)) ### Read-Only @@ -222,3 +218,5 @@ Optional: - `roles` (List of String) The roles with execution permission - `teams` (List of String) The teams with execution permission - `users` (List of String) The users with execution permission + + diff --git a/docs/resources/port_aggregation_property.md b/docs/resources/port_aggregation_property.md index 50c21e80..709ef41a 100644 --- a/docs/resources/port_aggregation_property.md +++ b/docs/resources/port_aggregation_property.md @@ -498,3 +498,5 @@ Optional: - `average_of` (String) The time periods to calculate the average of, e.g. hour, day, week, month - `measure_time_by` (String) The property name on which to calculate the the time periods, e.g. $createdAt, $updated_at or any other date property + + diff --git a/docs/resources/port_blueprint.md b/docs/resources/port_blueprint.md index b8230e9a..ceaa918c 100644 --- a/docs/resources/port_blueprint.md +++ b/docs/resources/port_blueprint.md @@ -444,3 +444,5 @@ Required: Optional: - `agent` (Boolean) The agent of the webhook changelog destination + + diff --git a/docs/resources/port_entity.md b/docs/resources/port_entity.md index 5c1535ea..a5524c46 100644 --- a/docs/resources/port_entity.md +++ b/docs/resources/port_entity.md @@ -67,3 +67,5 @@ Optional: - `many_relations` (Map of List of String) The many relation of the entity - `single_relations` (Map of String) The single relation of the entity + + diff --git a/docs/resources/port_scorecard.md b/docs/resources/port_scorecard.md index bd9142be..7f7ff532 100644 --- a/docs/resources/port_scorecard.md +++ b/docs/resources/port_scorecard.md @@ -59,3 +59,5 @@ Required: Optional: - `value` (String) The value of the condition + + diff --git a/docs/resources/port_team.md b/docs/resources/port_team.md index 518df378..59f9484b 100644 --- a/docs/resources/port_team.md +++ b/docs/resources/port_team.md @@ -30,3 +30,5 @@ Team resource - `id` (String) The ID of this resource. - `provider_name` (String) The provider of the team - `updated_at` (String) The last update date of the team + + diff --git a/docs/resources/port_webhook.md b/docs/resources/port_webhook.md index 89654c52..0e5c06ca 100644 --- a/docs/resources/port_webhook.md +++ b/docs/resources/port_webhook.md @@ -75,3 +75,5 @@ Optional: - `signature_algorithm` (String) The signature algorithm of the webhook - `signature_header_name` (String) The signature header name of the webhook - `signature_prefix` (String) The signature prefix of the webhook + + From 3bf4775dbaef2064ab19b886d5e29522ad64282f Mon Sep 17 00:00:00 2001 From: talsabagport Date: Sun, 14 Jan 2024 20:14:16 +0200 Subject: [PATCH 08/13] Add md desc --- port/action/schema.go | 97 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 7 deletions(-) diff --git a/port/action/schema.go b/port/action/schema.go index c0fa9a43..4562a590 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -801,13 +801,6 @@ func ArrayPropertySchema() schema.Attribute { } } -func (r *ActionResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "Action resource", - Attributes: ActionSchema(), - } -} - func (r *ActionResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var state *ActionModel @@ -859,3 +852,93 @@ func validateUserInputRequiredNotSetToFalse(state *ActionModel, resp *resource.V } } } + +func (r *ActionResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: ResourceMarkdownDescription, + Attributes: ActionSchema(), + } +} + +var ResourceMarkdownDescription = ` + +# Action resource + +Docs for the Action resource can be found [here](https://docs.getport.io/create-self-service-experiences/). + +## Example Usage + +` + "```hcl" + ` +resource "port_action" "create_microservice" { + title = "Create Microservice" + identifier = "create-microservice" + icon = "Terraform" + self_service_trigger = { + operation = "CREATE" + blueprint_identifier = port_blueprint.microservice.identifier + user_properties = { + string_props = { + myStringIdentifier = { + title = "My String Identifier" + required = true + } + } + number_props = { + myNumberIdentifier = { + title = "My Number Identifier" + required = true + maximum = 100 + minimum = 0 + } + } + boolean_props = { + myBooleanIdentifier = { + title = "My Boolean Identifier" + required = true + } + } + object_props = { + myObjectIdentifier = { + title = "My Object Identifier" + required = true + } + } + array_props = { + myArrayIdentifier = { + title = "My Array Identifier" + required = true + string_items = { + format = "email" + } + } + } + } + } + kafka_method = { + payload = jsonencode({ + runId: "{{.run.id}}" + }) + } +}` + "\n```" + ` + +## Example Usage with Automation trigger + +Port allows setting an automation trigger to an action, for executing an action based on event occurred to an entity in Port. + +` + "```hcl" + ` +resource "port_action" "delete_temporary_microservice" { + title = "Delete Temporary Microservice" + identifier = "delete-temp-microservice" + icon = "Terraform" + automation_trigger = { + timer_property_expired_event = { + blueprint_identifier = port_blueprint.microservice.identifier + property_identifier = "ttl" + } + } + kafka_method = { + payload = jsonencode({ + runId: "{{.run.id}}" + }) + } +}` + "\n```" From 3648435a0abb0b53579e5d823ebeaaed7e984c7f Mon Sep 17 00:00:00 2001 From: talsabagport Date: Tue, 16 Jan 2024 17:32:15 +0200 Subject: [PATCH 09/13] fix cr comments --- port/action-permissions/resource.go | 1 + port/action/actionStateToPortBody.go | 42 ++++++---------------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/port/action-permissions/resource.go b/port/action-permissions/resource.go index 098fcd5f..80b96d11 100644 --- a/port/action-permissions/resource.go +++ b/port/action-permissions/resource.go @@ -47,6 +47,7 @@ func (r *ActionPermissionsResource) Read(ctx context.Context, req resource.ReadR blueprintIdentifier := state.BlueprintIdentifier.ValueString() actionIdentifier := state.ActionIdentifier.ValueString() + // For the first time a user is migrating from action v1 to v2 if blueprintIdentifier != "" { actionIdentifier = fmt.Sprintf("%s_%s", blueprintIdentifier, actionIdentifier) } diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index 069837a9..945c1c44 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -39,22 +39,12 @@ func actionDataSetToPortBody(dataSet *DatasetModel) *cli.Dataset { func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, error) { var err error action := &cli.Action{ - Identifier: data.Identifier.ValueString(), - } - - if !data.Title.IsNull() { - title := data.Title.ValueString() - action.Title = &title - } - - if !data.Icon.IsNull() { - icon := data.Icon.ValueString() - action.Icon = &icon - } - - if !data.Description.IsNull() { - description := data.Description.ValueString() - action.Description = &description + Identifier: data.Identifier.ValueString(), + Title: data.Title.ValueStringPointer(), + Icon: data.Icon.ValueStringPointer(), + Description: data.Description.ValueStringPointer(), + RequiredApproval: data.RequiredApproval.ValueBoolPointer(), + Publish: data.Publish.ValueBoolPointer(), } action.Trigger, err = triggerToBody(ctx, data) @@ -67,11 +57,6 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, return nil, err } - if !data.RequiredApproval.IsNull() { - requiredApproval := data.RequiredApproval.ValueBool() - action.RequiredApproval = &requiredApproval - } - if !data.ApprovalEmailNotification.IsNull() { action.ApprovalNotification = &cli.ApprovalNotification{ Type: "email", @@ -79,21 +64,12 @@ func actionStateToPortBody(ctx context.Context, data *ActionModel) (*cli.Action, } if data.ApprovalWebhookNotification != nil { action.ApprovalNotification = &cli.ApprovalNotification{ - Type: "webhook", - Url: data.ApprovalWebhookNotification.Url.ValueString(), - } - - if !data.ApprovalWebhookNotification.Format.IsNull() { - format := data.ApprovalWebhookNotification.Format.ValueString() - action.ApprovalNotification.Format = &format + Type: "webhook", + Url: data.ApprovalWebhookNotification.Url.ValueString(), + Format: data.ApprovalWebhookNotification.Format.ValueStringPointer(), } } - if !data.Publish.IsNull() { - publish := data.Publish.ValueBool() - action.Publish = &publish - } - return action, nil } From f3e1bd4ef4139ae65e5d2f36f273b2d079be247d Mon Sep 17 00:00:00 2001 From: talsabagport Date: Tue, 16 Jan 2024 17:52:28 +0200 Subject: [PATCH 10/13] fix docs --- docs/resources/port_action.md | 8 ++++---- port/action/schema.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md index 4745e6a8..a28ed896 100644 --- a/docs/resources/port_action.md +++ b/docs/resources/port_action.md @@ -54,7 +54,7 @@ description: |- } kafka_method = { payload = jsonencode({ - runId: "" + runId: "{{.run.id}}" }) } } @@ -74,7 +74,7 @@ description: |- } kafka_method = { payload = jsonencode({ - runId: "" + runId: "{{.run.id}}" }) } } @@ -136,7 +136,7 @@ resource "port_action" "create_microservice" { } kafka_method = { payload = jsonencode({ - runId: "" + runId: "{{.run.id}}" }) } } @@ -159,7 +159,7 @@ resource "port_action" "delete_temporary_microservice" { } kafka_method = { payload = jsonencode({ - runId: "" + runId: "{{.run.id}}" }) } } diff --git a/port/action/schema.go b/port/action/schema.go index 4562a590..f98c4321 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -916,7 +916,7 @@ resource "port_action" "create_microservice" { } kafka_method = { payload = jsonencode({ - runId: "{{.run.id}}" + runId: "{{"{{.run.id}}"}}" }) } }` + "\n```" + ` @@ -938,7 +938,7 @@ resource "port_action" "delete_temporary_microservice" { } kafka_method = { payload = jsonencode({ - runId: "{{.run.id}}" + runId: "{{"{{.run.id}}"}}" }) } }` + "\n```" From ca5f140ad5e808354a10b3df1566a5b4c8a13f17 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Wed, 17 Jan 2024 11:09:48 +0200 Subject: [PATCH 11/13] fix tests and docs --- docs/resources/port_action.md | 4 ++++ port/action/resource_test.go | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md index a28ed896..d409dbaf 100644 --- a/docs/resources/port_action.md +++ b/docs/resources/port_action.md @@ -211,6 +211,10 @@ Required: - `url` (String) The URL to invoke the webhook +Optional: + +- `format` (String) The format to invoke the webhook + ### Nested Schema for `automation_trigger` diff --git a/port/action/resource_test.go b/port/action/resource_test.go index a208759a..12c16755 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -1551,8 +1551,10 @@ func TestAccPortWebhookApproval(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } kafka_method = {} required_approval = true approval_webhook_notification = { @@ -1570,8 +1572,8 @@ func TestAccPortWebhookApproval(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "required_approval", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "approval_webhook_notification.url", "https://example.com"), resource.TestCheckResourceAttr("port_action.create_microservice", "approval_webhook_notification.format", "json"), @@ -1589,8 +1591,10 @@ func TestAccPortEmailApproval(t *testing.T) { title = "TF Provider Test" identifier = "%s" icon = "Terraform" - blueprint = port_blueprint.microservice.id - trigger = "DAY-2" + self_service_trigger = { + operation = "DAY-2" + blueprint_identifier = port_blueprint.microservice.identifier + } kafka_method = {} required_approval = true approval_email_notification = {} @@ -1605,8 +1609,8 @@ func TestAccPortEmailApproval(t *testing.T) { 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", "blueprint", identifier), - resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.blueprint_identifier", identifier), + resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), resource.TestCheckResourceAttr("port_action.create_microservice", "required_approval", "true"), resource.TestCheckResourceAttr("port_action.create_microservice", "approval_email_notification.%", "0"), ), From 12ffb73c9cdd00d18dc94c4e44b41f5e8f84aa05 Mon Sep 17 00:00:00 2001 From: talsabagport Date: Tue, 30 Apr 2024 19:35:05 +0300 Subject: [PATCH 12/13] fix tests --- docs/resources/port_action.md | 164 +++-------------------- port/action-permissions/resource_test.go | 2 - port/action/schema.go | 36 ++--- 3 files changed, 36 insertions(+), 166 deletions(-) diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md index 7ca6a0b7..419f23b5 100644 --- a/docs/resources/port_action.md +++ b/docs/resources/port_action.md @@ -79,26 +79,6 @@ description: |- }) } } - - Example Usage with Automation trigger - Port allows setting an automation trigger to an action, for executing an action based on event occurred to an entity in Port. - hcl - resource "port_action" "delete_temporary_microservice" { - title = "Delete Temporary Microservice" - identifier = "delete-temp-microservice" - icon = "Terraform" - automation_trigger = { - timer_property_expired_event = { - blueprint_identifier = port_blueprint.microservice.identifier - property_identifier = "ttl" - } - } - kafka_method = { - payload = jsonencode({ - runId: "{{.run.id}}" - }) - } - } --- # port_action (Resource) @@ -124,16 +104,16 @@ resource "port_action" "create_microservice" { required = true format = "entity" blueprint = port_blueprint.parent.identifier - dataset = { - combinator = "and" - rules = [{ - property = "$title" - operator = "contains" - value = { - jq_query = "\"specificValue\"" - } - }] - } + dataset = { + combinator = "and" + rules = [{ + property = "$title" + operator = "contains" + value = { + jq_query = "\"specificValue\"" + } + }] + } } } number_props = { @@ -163,14 +143,14 @@ resource "port_action" "create_microservice" { string_items = { format = "entity" blueprint = port_blueprint.parent.identifier - dataset = jsonencode({ - combinator = "and" - rules = [{ - property = "$title" - operator = "contains" - value = "specificValue" - }] - }) + dataset = jsonencode({ + combinator = "and" + rules = [{ + property = "$title" + operator = "contains" + value = "specificValue" + }] + }) } } } @@ -184,29 +164,6 @@ resource "port_action" "create_microservice" { } ``` -## Example Usage with Automation trigger - -Port allows setting an automation trigger to an action, for executing an action based on event occurred to an entity in Port. - -```hcl -resource "port_action" "delete_temporary_microservice" { - title = "Delete Temporary Microservice" - identifier = "delete-temp-microservice" - icon = "Terraform" - automation_trigger = { - timer_property_expired_event = { - blueprint_identifier = port_blueprint.microservice.identifier - property_identifier = "ttl" - } - } - kafka_method = { - payload = jsonencode({ - runId: "{{.run.id}}" - }) - } -} -``` - @@ -220,7 +177,6 @@ resource "port_action" "delete_temporary_microservice" { - `approval_email_notification` (Object) The email notification of the approval (see [below for nested schema](#nestedatt--approval_email_notification)) - `approval_webhook_notification` (Attributes) The webhook notification of the approval (see [below for nested schema](#nestedatt--approval_webhook_notification)) -- `automation_trigger` (Attributes) Automation trigger for the action (see [below for nested schema](#nestedatt--automation_trigger)) - `azure_method` (Attributes) Azure DevOps invocation method (see [below for nested schema](#nestedatt--azure_method)) - `blueprint` (String, Deprecated) The blueprint identifier the action relates to - `description` (String) Description @@ -232,7 +188,6 @@ resource "port_action" "delete_temporary_microservice" { - `required_approval` (Boolean) Require approval before invoking the action - `self_service_trigger` (Attributes) Self service trigger for the action (see [below for nested schema](#nestedatt--self_service_trigger)) - `title` (String) Title -- `upsert_entity_method` (Attributes) Upsert Entity invocation method (see [below for nested schema](#nestedatt--upsert_entity_method)) - `webhook_method` (Attributes) Webhook invocation method (see [below for nested schema](#nestedatt--webhook_method)) ### Read-Only @@ -258,72 +213,6 @@ Optional: - `format` (String) The format to invoke the webhook - -### Nested Schema for `automation_trigger` - -Optional: - -- `any_entity_change_event` (Attributes) Any entity change event trigger (see [below for nested schema](#nestedatt--automation_trigger--any_entity_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)) -- `timer_property_expired_event` (Attributes) Timer property expired event trigger (see [below for nested schema](#nestedatt--automation_trigger--timer_property_expired_event)) - - -### Nested Schema for `automation_trigger.any_entity_change_event` - -Required: - -- `blueprint_identifier` (String) The blueprint identifier of the changed entity - - - -### Nested Schema for `automation_trigger.entity_created_event` - -Required: - -- `blueprint_identifier` (String) The blueprint identifier of the created entity - - - -### Nested Schema for `automation_trigger.entity_deleted_event` - -Required: - -- `blueprint_identifier` (String) The blueprint identifier of the deleted entity - - - -### Nested Schema for `automation_trigger.entity_updated_event` - -Required: - -- `blueprint_identifier` (String) The blueprint identifier of the updated entity - - - -### Nested Schema for `automation_trigger.jq_condition` - -Required: - -- `expressions` (List of String) The jq expressions of the condition - -Optional: - -- `combinator` (String) The combinator of the condition - - - -### Nested Schema for `automation_trigger.timer_property_expired_event` - -Required: - -- `blueprint_identifier` (String) The blueprint identifier of the expired timer property -- `property_identifier` (String) The property identifier of the expired timer property - - - ### Nested Schema for `azure_method` @@ -570,23 +459,6 @@ Optional: - -### Nested Schema for `upsert_entity_method` - -Required: - -- `blueprint_identifier` (String) Required when selecting type Upsert Entity. The blueprint identifier of the entity for the upsert -- `identifier` (String) Required when selecting type Upsert Entity. The entity identifier for the upsert - -Optional: - -- `icon` (String) The icon of the entity -- `properties` (String) The properties of the entity (key-value object encoded to a string) -- `relations` (String) The relations of the entity (key-value object encoded to a string) -- `teams` (List of String) The teams the entity belongs to -- `title` (String) The title of the entity - - ### Nested Schema for `webhook_method` diff --git a/port/action-permissions/resource_test.go b/port/action-permissions/resource_test.go index 5c5c4ed8..67f92f8f 100644 --- a/port/action-permissions/resource_test.go +++ b/port/action-permissions/resource_test.go @@ -496,7 +496,6 @@ func TestAccPortActionWithEmptyFieldsExpectDefaultsToApply(t *testing.T) { var testAccActionPermissionsConfigCreate = testAccCreateBlueprintAndActionConfig(blueprintIdentifier, actionIdentifier) + ` resource "port_action_permissions" "create_microservice_permissions" { action_identifier = port_action.create_microservice.identifier - blueprint_identifier = port_blueprint.microservice.identifier permissions = { "execute": {} "approve": {} @@ -511,7 +510,6 @@ func TestAccPortActionWithEmptyFieldsExpectDefaultsToApply(t *testing.T) { Config: testAccActionPermissionsConfigCreate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "action_identifier", actionIdentifier), - resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "blueprint_identifier", blueprintIdentifier), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.roles.#", "0"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.users.#", "0"), resource.TestCheckResourceAttr("port_action_permissions.create_microservice_permissions", "permissions.execute.teams.#", "0"), diff --git a/port/action/schema.go b/port/action/schema.go index 4ed37d61..5bca3300 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -1039,16 +1039,16 @@ resource "port_action" "create_microservice" { required = true format = "entity" blueprint = port_blueprint.parent.identifier - dataset = { - combinator = "and" - rules = [{ - property = "$title" - operator = "contains" - value = { - jq_query = "\"specificValue\"" - } - }] - } + dataset = { + combinator = "and" + rules = [{ + property = "$title" + operator = "contains" + value = { + jq_query = "\"specificValue\"" + } + }] + } } } number_props = { @@ -1078,14 +1078,14 @@ resource "port_action" "create_microservice" { string_items = { format = "entity" blueprint = port_blueprint.parent.identifier - dataset = jsonencode({ - combinator = "and" - rules = [{ - property = "$title" - operator = "contains" - value = "specificValue" - }] - }) + dataset = jsonencode({ + combinator = "and" + rules = [{ + property = "$title" + operator = "contains" + value = "specificValue" + }] + }) } } } From cc42738a56e260fd2779d74717fab0ad99742f9d Mon Sep 17 00:00:00 2001 From: talsabagport Date: Wed, 1 May 2024 13:23:09 +0300 Subject: [PATCH 13/13] remove comments --- port/action/actionStateToPortBody.go | 84 ----------- port/action/model.go | 77 +++------- port/action/refreshActionState.go | 81 ---------- port/action/resource_test.go | 212 --------------------------- port/action/schema.go | 155 -------------------- 5 files changed, 24 insertions(+), 585 deletions(-) diff --git a/port/action/actionStateToPortBody.go b/port/action/actionStateToPortBody.go index 282e32d3..5d4228ec 100644 --- a/port/action/actionStateToPortBody.go +++ b/port/action/actionStateToPortBody.go @@ -101,59 +101,6 @@ func triggerToBody(ctx context.Context, data *ActionModel) (*cli.Trigger, error) return selfServiceTrigger, nil } - // TODO: return when frontend for automations is ready - //if data.AutomationTrigger != nil { - // automationTrigger := &cli.Trigger{ - // Type: consts.Automation, - // } - // - // if data.AutomationTrigger.JqCondition != nil { - // automationTrigger.Condition = &cli.TriggerCondition{ - // Type: consts.JqCondition, - // Expressions: flex.TerraformStringListToGoArray(data.AutomationTrigger.JqCondition.Expressions), - // Combinator: data.AutomationTrigger.JqCondition.Combinator.ValueStringPointer(), - // } - // } - // - // if data.AutomationTrigger.EntityCreatedEvent != nil { - // automationTrigger.Event = &cli.TriggerEvent{ - // Type: consts.EntityCreated, - // BlueprintIdentifier: data.AutomationTrigger.EntityCreatedEvent.BlueprintIdentifier.ValueStringPointer(), - // } - // } - // - // if data.AutomationTrigger.EntityUpdatedEvent != nil { - // automationTrigger.Event = &cli.TriggerEvent{ - // Type: consts.EntityUpdated, - // BlueprintIdentifier: data.AutomationTrigger.EntityUpdatedEvent.BlueprintIdentifier.ValueStringPointer(), - // } - // } - // - // if data.AutomationTrigger.EntityDeletedEvent != nil { - // automationTrigger.Event = &cli.TriggerEvent{ - // Type: consts.EntityDeleted, - // BlueprintIdentifier: data.AutomationTrigger.EntityDeletedEvent.BlueprintIdentifier.ValueStringPointer(), - // } - // } - // - // if data.AutomationTrigger.AnyEntityChangeEvent != nil { - // automationTrigger.Event = &cli.TriggerEvent{ - // Type: consts.AnyEntityChange, - // BlueprintIdentifier: data.AutomationTrigger.AnyEntityChangeEvent.BlueprintIdentifier.ValueStringPointer(), - // } - // } - // - // if data.AutomationTrigger.TimerPropertyExpiredEvent != nil { - // automationTrigger.Event = &cli.TriggerEvent{ - // Type: consts.TimerPropertyExpired, - // BlueprintIdentifier: data.AutomationTrigger.TimerPropertyExpiredEvent.BlueprintIdentifier.ValueStringPointer(), - // PropertyIdentifier: data.AutomationTrigger.TimerPropertyExpiredEvent.PropertyIdentifier.ValueStringPointer(), - // } - // } - // - // return automationTrigger, nil - //} - return nil, nil } @@ -301,36 +248,5 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca return azureInvocation, nil } - // TODO: return when frontend for upsert entity is ready - //if data.UpsertEntityMethod != nil { - // var team interface{} - // if data.UpsertEntityMethod.Teams != nil { - // team = flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Teams) - // } - // p, err := utils.TerraformStringToGoObject(data.UpsertEntityMethod.Properties) - // if err != nil { - // return nil, err - // } - // properties, _ := p.(map[string]interface{}) - // r, err := utils.TerraformStringToGoObject(data.UpsertEntityMethod.Relations) - // if err != nil { - // return nil, err - // } - // relations, _ := r.(map[string]interface{}) - // - // upsertEntityInvocation := &cli.InvocationMethod{ - // Type: consts.UpsertEntity, - // Identifier: data.UpsertEntityMethod.Identifier.ValueStringPointer(), - // Title: data.UpsertEntityMethod.Title.ValueStringPointer(), - // BlueprintIdentifier: data.UpsertEntityMethod.BlueprintIdentifier.ValueStringPointer(), - // Team: team, - // Icon: data.UpsertEntityMethod.Icon.ValueStringPointer(), - // Properties: properties, - // Relations: relations, - // } - // - // return upsertEntityInvocation, nil - //} - return nil, nil } diff --git a/port/action/model.go b/port/action/model.go index 7e591847..8ace9dc9 100644 --- a/port/action/model.go +++ b/port/action/model.go @@ -303,16 +303,6 @@ type JqConditionModel struct { Combinator types.String `tfsdk:"combinator"` } -// TODO: return when frontend for automations is ready -//type AutomationTriggerModel struct { -// EntityCreatedEvent *EntityCreatedEventModel `tfsdk:"entity_created_event"` -// EntityUpdatedEvent *EntityUpdatedEventModel `tfsdk:"entity_updated_event"` -// EntityDeletedEvent *EntityDeletedEventModel `tfsdk:"entity_deleted_event"` -// AnyEntityChangeEvent *AnyEntityChangeEventModel `tfsdk:"any_entity_change_event"` -// TimerPropertyExpiredEvent *TimerPropertyExpiredEventModel `tfsdk:"timer_property_expired_event"` -// JqCondition *JqConditionModel `tfsdk:"jq_condition"` -//} - type KafkaMethodModel struct { Payload types.String `tfsdk:"payload"` } @@ -347,39 +337,24 @@ type AzureMethodModel struct { Payload types.String `tfsdk:"payload"` } -// TODO: return when frontend for upsert entity is ready -//type UpsertEntityMethodModel struct { -// Identifier types.String `tfsdk:"identifier"` -// Title types.String `tfsdk:"title"` -// BlueprintIdentifier types.String `tfsdk:"blueprint_identifier"` -// Teams []types.String `tfsdk:"teams"` -// Icon types.String `tfsdk:"icon"` -// Properties types.String `tfsdk:"properties"` -// Relations types.String `tfsdk:"relations"` -//} - type ApprovalWebhookNotificationModel struct { Url types.String `tfsdk:"url"` Format types.String `tfsdk:"format"` } type ActionModel struct { - ID types.String `tfsdk:"id"` - Identifier types.String `tfsdk:"identifier"` - Blueprint types.String `tfsdk:"blueprint"` - Title types.String `tfsdk:"title"` - Icon types.String `tfsdk:"icon"` - Description types.String `tfsdk:"description"` - SelfServiceTrigger *SelfServiceTriggerModel `tfsdk:"self_service_trigger"` - // TODO: return when frontend for automations is ready - //AutomationTrigger *AutomationTriggerModel `tfsdk:"automation_trigger"` - KafkaMethod *KafkaMethodModel `tfsdk:"kafka_method"` - WebhookMethod *WebhookMethodModel `tfsdk:"webhook_method"` - GithubMethod *GithubMethodModel `tfsdk:"github_method"` - GitlabMethod *GitlabMethodModel `tfsdk:"gitlab_method"` - AzureMethod *AzureMethodModel `tfsdk:"azure_method"` - // TODO: return when frontend for upsert entity is ready - //UpsertEntityMethod *UpsertEntityMethodModel `tfsdk:"upsert_entity_method"` + ID types.String `tfsdk:"id"` + Identifier types.String `tfsdk:"identifier"` + Blueprint types.String `tfsdk:"blueprint"` + Title types.String `tfsdk:"title"` + Icon types.String `tfsdk:"icon"` + Description types.String `tfsdk:"description"` + SelfServiceTrigger *SelfServiceTriggerModel `tfsdk:"self_service_trigger"` + KafkaMethod *KafkaMethodModel `tfsdk:"kafka_method"` + WebhookMethod *WebhookMethodModel `tfsdk:"webhook_method"` + GithubMethod *GithubMethodModel `tfsdk:"github_method"` + GitlabMethod *GitlabMethodModel `tfsdk:"gitlab_method"` + AzureMethod *AzureMethodModel `tfsdk:"azure_method"` RequiredApproval types.Bool `tfsdk:"required_approval"` ApprovalWebhookNotification *ApprovalWebhookNotificationModel `tfsdk:"approval_webhook_notification"` ApprovalEmailNotification types.Object `tfsdk:"approval_email_notification"` @@ -388,22 +363,18 @@ type ActionModel struct { // ActionValidationModel is a model used for the validation of ActionModel resources type ActionValidationModel struct { - ID types.String `tfsdk:"id"` - Identifier types.String `tfsdk:"identifier"` - Blueprint types.String `tfsdk:"blueprint"` - Title types.String `tfsdk:"title"` - Icon types.String `tfsdk:"icon"` - Description types.String `tfsdk:"description"` - SelfServiceTrigger types.Object `tfsdk:"self_service_trigger"` - // TODO: return when frontend for automations is ready - //AutomationTrigger types.Object `tfsdk:"automation_trigger"` - KafkaMethod types.Object `tfsdk:"kafka_method"` - WebhookMethod types.Object `tfsdk:"webhook_method"` - GithubMethod types.Object `tfsdk:"github_method"` - GitlabMethod types.Object `tfsdk:"gitlab_method"` - AzureMethod types.Object `tfsdk:"azure_method"` - // TODO: return when frontend for upsert entity is ready - //UpsertEntityMethod types.Object `tfsdk:"upsert_entity_method"` + ID types.String `tfsdk:"id"` + Identifier types.String `tfsdk:"identifier"` + Blueprint types.String `tfsdk:"blueprint"` + Title types.String `tfsdk:"title"` + Icon types.String `tfsdk:"icon"` + Description types.String `tfsdk:"description"` + SelfServiceTrigger types.Object `tfsdk:"self_service_trigger"` + KafkaMethod types.Object `tfsdk:"kafka_method"` + WebhookMethod types.Object `tfsdk:"webhook_method"` + GithubMethod types.Object `tfsdk:"github_method"` + GitlabMethod types.Object `tfsdk:"gitlab_method"` + AzureMethod types.Object `tfsdk:"azure_method"` RequiredApproval types.Bool `tfsdk:"required_approval"` ApprovalWebhookNotification types.Object `tfsdk:"approval_webhook_notification"` ApprovalEmailNotification types.Object `tfsdk:"approval_email_notification"` diff --git a/port/action/refreshActionState.go b/port/action/refreshActionState.go index 32eefc13..c2b50637 100644 --- a/port/action/refreshActionState.go +++ b/port/action/refreshActionState.go @@ -97,38 +97,6 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state * } } - // TODO: return when frontend for upsert entity is ready - //if a.InvocationMethod.Type == consts.UpsertEntity { - // var teams []types.String - // switch team := a.InvocationMethod.Team.(type) { - // case string: - // teams = append(teams, types.StringValue(team)) - // case []interface{}: - // teams = make([]types.String, 0) - // for _, t := range team { - // teams = append(teams, types.StringValue(t.(string))) - // } - // } - // properties, err := utils.GoObjectToTerraformString(a.InvocationMethod.Properties) - // if err != nil { - // return err - // } - // relations, err := utils.GoObjectToTerraformString(a.InvocationMethod.Relations) - // if err != nil { - // return err - // } - // - // state.UpsertEntityMethod = &UpsertEntityMethodModel{ - // Identifier: types.StringValue(*a.InvocationMethod.Identifier), - // Title: flex.GoStringToFramework(a.InvocationMethod.Title), - // BlueprintIdentifier: types.StringValue(*a.InvocationMethod.BlueprintIdentifier), - // Teams: teams, - // Icon: flex.GoStringToFramework(a.InvocationMethod.Icon), - // Properties: properties, - // Relations: relations, - // } - //} - return nil } @@ -329,55 +297,6 @@ func writeTriggerToResource(ctx context.Context, a *cli.Action, state *ActionMod } } - // TODO: return when frontend for automations is ready - //if a.Trigger.Type == consts.Automation { - // automationTrigger := &AutomationTriggerModel{} - // - // var expressions []types.String - // if a.Trigger.Condition != nil { - // for _, e := range a.Trigger.Condition.Expressions { - // expressions = append(expressions, types.StringValue(e)) - // } - // automationTrigger.JqCondition = &JqConditionModel{ - // Expressions: expressions, - // Combinator: flex.GoStringToFramework(a.Trigger.Condition.Combinator), - // } - // } - // - // if a.Trigger.Event.Type == consts.EntityCreated { - // automationTrigger.EntityCreatedEvent = &EntityCreatedEventModel{ - // BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), - // } - // } - // - // if a.Trigger.Event.Type == consts.EntityUpdated { - // automationTrigger.EntityUpdatedEvent = &EntityUpdatedEventModel{ - // BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), - // } - // } - // - // if a.Trigger.Event.Type == consts.EntityDeleted { - // automationTrigger.EntityDeletedEvent = &EntityDeletedEventModel{ - // BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), - // } - // } - // - // if a.Trigger.Event.Type == consts.AnyEntityChange { - // automationTrigger.AnyEntityChangeEvent = &AnyEntityChangeEventModel{ - // BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), - // } - // } - // - // if a.Trigger.Event.Type == consts.TimerPropertyExpired { - // automationTrigger.TimerPropertyExpiredEvent = &TimerPropertyExpiredEventModel{ - // BlueprintIdentifier: types.StringValue(*a.Trigger.Event.BlueprintIdentifier), - // PropertyIdentifier: types.StringValue(*a.Trigger.Event.PropertyIdentifier), - // } - // } - // - // state.AutomationTrigger = automationTrigger - //} - return nil } diff --git a/port/action/resource_test.go b/port/action/resource_test.go index aef895da..20fd2c4e 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -398,55 +398,6 @@ func TestAccPortActionAzureInvocation(t *testing.T) { }) } -// TODO: return when frontend for upsert entity is ready -//func TestAccPortActionUpsertEntityInvocation(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// self_service_trigger = { -// operation = "DAY-2" -// blueprint_identifier = port_blueprint.microservice.identifier -// } -// upsert_entity_method = { -// identifier = "test-entity" -// title = "Test Entity" -// blueprint_identifier = port_blueprint.microservice.identifier -// teams = [] -// icon = "Terraform" -// properties = jsonencode({"text": "test"}) -// relations = jsonencode({"test-rel": "target-bp"}) -// } -// }`, 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", "self_service_trigger.blueprint_identifier", identifier), -// resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.operation", "DAY-2"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.identifier", "test-entity"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.title", "Test Entity"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.blueprint_identifier", identifier), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.teams.#", "0"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.icon", "Terraform"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.properties", "{\"text\":\"test\"}"), -// resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.relations", "{\"test-rel\":\"target-bp\"}"), -// ), -// }, -// }, -// }) -//} - func TestAccPortActionImport(t *testing.T) { blueprintIdentifier := utils.GenID() actionIdentifier := utils.GenID() @@ -1404,169 +1355,6 @@ func TestAccPortActionRequiredFalseAndNull(t *testing.T) { }) } -// TODO: return when frontend for automations is ready -//func TestAccPortAutomationEntityCreated(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// automation_trigger = { -// entity_created_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// } -// } -// kafka_method = {} -// }`, 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.entity_created_event.blueprint_identifier", identifier), -// ), -// }, -// }, -// }) -//} -// -//func TestAccPortAutomationEntityUpdated(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// automation_trigger = { -// entity_updated_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// } -// } -// kafka_method = {} -// }`, 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.entity_updated_event.blueprint_identifier", identifier), -// ), -// }, -// }, -// }) -//} -// -//func TestAccPortAutomationEntityDeleted(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// automation_trigger = { -// entity_deleted_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// } -// } -// kafka_method = {} -// }`, 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.entity_deleted_event.blueprint_identifier", identifier), -// ), -// }, -// }, -// }) -//} -// -//func TestAccPortAutomationAnyEntityChange(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// automation_trigger = { -// any_entity_change_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// } -// } -// kafka_method = {} -// }`, 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_entity_change_event.blueprint_identifier", identifier), -// ), -// }, -// }, -// }) -//} -// -//func TestAccPortAutomationTimerPropertyExpired(t *testing.T) { -// identifier := utils.GenID() -// actionIdentifier := utils.GenID() -// var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(` -// resource "port_action" "create_microservice" { -// title = "TF Provider Test" -// identifier = "%s" -// icon = "Terraform" -// automation_trigger = { -// timer_property_expired_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// property_identifier = "timer" -// } -// } -// kafka_method = {} -// }`, 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.timer_property_expired_event.blueprint_identifier", identifier), -// resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.timer_property_expired_event.property_identifier", "timer"), -// ), -// }, -// }, -// }) -//} - func TestAccPortWebhookApproval(t *testing.T) { identifier := utils.GenID() actionIdentifier := utils.GenID() diff --git a/port/action/schema.go b/port/action/schema.go index 5bca3300..a1eec1ca 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -130,101 +130,9 @@ func ActionSchema() map[string]schema.Attribute { Validators: []validator.Object{ objectvalidator.ExactlyOneOf( path.MatchRoot("self_service_trigger"), - // TODO: return when frontend for automations is ready - //path.MatchRoot("automation_trigger"), ), }, }, - // TODO: return when frontend for automations is ready - //"automation_trigger": schema.SingleNestedAttribute{ - // MarkdownDescription: "Automation trigger for the action", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "entity_created_event": schema.SingleNestedAttribute{ - // MarkdownDescription: "Entity created event trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "The blueprint identifier of the created entity", - // Required: true, - // }, - // }, - // Validators: []validator.Object{ - // objectvalidator.ExactlyOneOf( - // path.MatchRelative().AtParent().AtName("entity_created_event"), - // path.MatchRelative().AtParent().AtName("entity_updated_event"), - // path.MatchRelative().AtParent().AtName("entity_deleted_event"), - // path.MatchRelative().AtParent().AtName("any_entity_change_event"), - // path.MatchRelative().AtParent().AtName("timer_property_expired_event"), - // ), - // }, - // }, - // "entity_updated_event": schema.SingleNestedAttribute{ - // MarkdownDescription: "Entity updated event trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "The blueprint identifier of the updated entity", - // Required: true, - // }, - // }, - // }, - // "entity_deleted_event": schema.SingleNestedAttribute{ - // MarkdownDescription: "Entity deleted event trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "The blueprint identifier of the deleted entity", - // Required: true, - // }, - // }, - // }, - // "any_entity_change_event": schema.SingleNestedAttribute{ - // MarkdownDescription: "Any entity change event trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "The blueprint identifier of the changed entity", - // Required: true, - // }, - // }, - // }, - // "timer_property_expired_event": schema.SingleNestedAttribute{ - // MarkdownDescription: "Timer property expired event trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "The blueprint identifier of the expired timer property", - // Required: true, - // }, - // "property_identifier": schema.StringAttribute{ - // MarkdownDescription: "The property identifier of the expired timer property", - // Required: true, - // }, - // }, - // }, - // "jq_condition": schema.SingleNestedAttribute{ - // MarkdownDescription: "JQ condition for automation trigger", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "expressions": schema.ListAttribute{ - // MarkdownDescription: "The jq expressions of the condition", - // ElementType: types.StringType, - // Required: true, - // }, - // "combinator": schema.StringAttribute{ - // MarkdownDescription: "The combinator of the condition", - // Optional: true, - // Computed: true, - // Default: stringdefault.StaticString("and"), - // Validators: []validator.String{ - // stringvalidator.OneOf("and", "or"), - // }, - // }, - // }, - // }, - // }, - //}, "kafka_method": schema.SingleNestedAttribute{ MarkdownDescription: "Kafka invocation method", Optional: true, @@ -241,8 +149,6 @@ func ActionSchema() map[string]schema.Attribute { path.MatchRoot("github_method"), path.MatchRoot("gitlab_method"), path.MatchRoot("azure_method"), - // TODO: return when frontend for upsert entity is ready - //path.MatchRoot("upsert_entity_method"), ), }, }, @@ -346,42 +252,6 @@ func ActionSchema() map[string]schema.Attribute { }, }, }, - // TODO: return when frontend for upsert entity is ready - //"upsert_entity_method": schema.SingleNestedAttribute{ - // MarkdownDescription: "Upsert Entity invocation method", - // Optional: true, - // Attributes: map[string]schema.Attribute{ - // "identifier": schema.StringAttribute{ - // MarkdownDescription: "Required when selecting type Upsert Entity. The entity identifier for the upsert", - // Required: true, - // }, - // "title": schema.StringAttribute{ - // MarkdownDescription: "The title of the entity", - // Optional: true, - // }, - // "blueprint_identifier": schema.StringAttribute{ - // MarkdownDescription: "Required when selecting type Upsert Entity. The blueprint identifier of the entity for the upsert", - // Required: true, - // }, - // "teams": schema.ListAttribute{ - // MarkdownDescription: "The teams the entity belongs to", - // ElementType: types.StringType, - // Optional: true, - // }, - // "icon": schema.StringAttribute{ - // MarkdownDescription: "The icon of the entity", - // Optional: true, - // }, - // "properties": schema.StringAttribute{ - // MarkdownDescription: "The properties of the entity (key-value object encoded to a string)", - // Optional: true, - // }, - // "relations": schema.StringAttribute{ - // MarkdownDescription: "The relations of the entity (key-value object encoded to a string)", - // Optional: true, - // }, - // }, - //}, "required_approval": schema.BoolAttribute{ MarkdownDescription: "Require approval before invoking the action", Optional: true, @@ -1097,28 +967,3 @@ resource "port_action" "create_microservice" { }) } }` + "\n```" - -// TODO: return when frontend for automations is ready -//+ ` -// -//## Example Usage with Automation trigger -// -//Port allows setting an automation trigger to an action, for executing an action based on event occurred to an entity in Port. -// -//` + "```hcl" + ` -//resource "port_action" "delete_temporary_microservice" { -// title = "Delete Temporary Microservice" -// identifier = "delete-temp-microservice" -// icon = "Terraform" -// automation_trigger = { -// timer_property_expired_event = { -// blueprint_identifier = port_blueprint.microservice.identifier -// property_identifier = "ttl" -// } -// } -// kafka_method = { -// payload = jsonencode({ -// runId: "{{"{{.run.id}}"}}" -// }) -// } -//}` + "\n```"