Skip to content

Commit b2179b1

Browse files
authored
support github actions (#6)
1 parent ae1cd8b commit b2179b1

File tree

8 files changed

+581
-2
lines changed

8 files changed

+581
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ HOSTNAME=github.com
22
NAMESPACE=port-labs
33
NAME=port-labs
44
BINARY=terraform-provider-${NAME}
5-
VERSION=0.3.1
5+
VERSION=0.4.0
66
OS=$(shell go env GOOS)
77
ARCH=$(shell go env GOARCH)
88
OS_ARCH=${OS}_${ARCH}

docs/resources/action.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "port-labs_action Resource - terraform-provider-port-labs"
4+
subcategory: ""
5+
description: |-
6+
Port action
7+
---
8+
9+
# port-labs_action (Resource)
10+
11+
Port action
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `blueprint_identifier` (String) The identifier of the blueprint
21+
- `identifier` (String) The identifier of the action
22+
- `invocation_method` (String) The methods the action is dispatched in, currently only supports KAFKA
23+
- `title` (String) The display name of the action
24+
- `trigger` (String) The type of the action, one of CREATE, DAY-2, DELETE
25+
26+
### Optional
27+
28+
- `description` (String) The description of the action
29+
- `icon` (String) The icon of the action
30+
- `required_properties` (Set of String) The required properties of the action
31+
- `user_properties` (Block Set) The input properties of the action (see [below for nested schema](#nestedblock--user_properties))
32+
33+
### Read-Only
34+
35+
- `id` (String) The ID of this resource.
36+
37+
<a id="nestedblock--user_properties"></a>
38+
### Nested Schema for `user_properties`
39+
40+
Required:
41+
42+
- `identifier` (String) The identifier of the property
43+
- `title` (String) A nicely written name for the property
44+
- `type` (String) The type of the property
45+
46+
Optional:
47+
48+
- `default` (String) A default value for this property in case an entity is created without explicitly providing a value.
49+
- `description` (String) A description of the property. This value is visible to users when hovering on the info icon in the UI. It provides detailed information about the use of a specific property.
50+
- `format` (String) A specific data format to pair with some of the available types
51+
- `pattern` (String) A regular expression (regex) pattern to specify the set of allowed values for the property
52+
53+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "port-labs_action" "restart_microservice" {
2+
title = "Restart microservice"
3+
icon = "Terraform"
4+
identifier = "restart-micrservice"
5+
blueprint_identifier = port-labs_blueprint.microservice.identifier
6+
trigger = "DAY-2"
7+
invocation_method = "KAFKA"
8+
user_properties {
9+
identifier = "webhook_url"
10+
type = "string"
11+
title = "Webhook URL"
12+
description = "Webhook URL to send the request to"
13+
format = "url"
14+
default = "https://example.com"
15+
pattern = "^https://.*"
16+
}
17+
}

port/cli/action.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
)
8+
9+
func (c *PortClient) ReadAction(ctx context.Context, blueprintID, id string) (*Action, error) {
10+
pb := &PortBody{}
11+
url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}"
12+
resp, err := c.Client.R().
13+
SetContext(ctx).
14+
SetHeader("Accept", "application/json").
15+
SetResult(pb).
16+
SetPathParam("blueprint_identifier", blueprintID).
17+
SetPathParam("action_identifier", id).
18+
Get(url)
19+
if err != nil {
20+
return nil, err
21+
}
22+
if !pb.OK {
23+
return nil, fmt.Errorf("failed to read action, got: %s", resp.Body())
24+
}
25+
return &pb.Action, nil
26+
}
27+
28+
func (c *PortClient) CreateAction(ctx context.Context, blueprintID string, action *Action) (*Action, error) {
29+
url := "v1/blueprints/{blueprint_identifier}/actions"
30+
resp, err := c.Client.R().
31+
SetBody(action).
32+
SetPathParam("blueprint_identifier", blueprintID).
33+
SetContext(ctx).
34+
Post(url)
35+
if err != nil {
36+
return nil, err
37+
}
38+
var pb PortBody
39+
err = json.Unmarshal(resp.Body(), &pb)
40+
if err != nil {
41+
return nil, err
42+
}
43+
if !pb.OK {
44+
return nil, fmt.Errorf("failed to create action, got: %s", resp.Body())
45+
}
46+
return &pb.Action, nil
47+
}
48+
49+
func (c *PortClient) UpdateAction(ctx context.Context, blueprintID, actionID string, action *Action) (*Action, error) {
50+
url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}"
51+
resp, err := c.Client.R().
52+
SetBody(action).
53+
SetContext(ctx).
54+
SetPathParam("blueprint_identifier", blueprintID).
55+
SetPathParam("action_identifier", actionID).
56+
Put(url)
57+
if err != nil {
58+
return nil, err
59+
}
60+
var pb PortBody
61+
err = json.Unmarshal(resp.Body(), &pb)
62+
if err != nil {
63+
return nil, err
64+
}
65+
if !pb.OK {
66+
return nil, fmt.Errorf("failed to create action, got: %s", resp.Body())
67+
}
68+
return &pb.Action, nil
69+
}
70+
71+
func (c *PortClient) DeleteAction(ctx context.Context, blueprintID, actionID string) error {
72+
url := "v1/blueprints/{blueprint_identifier}/actions/{action_identifier}"
73+
resp, err := c.Client.R().
74+
SetContext(ctx).
75+
SetHeader("Accept", "application/json").
76+
SetPathParam("blueprint_identifier", blueprintID).
77+
SetPathParam("action_identifier", actionID).
78+
Delete(url)
79+
if err != nil {
80+
return err
81+
}
82+
responseBody := make(map[string]interface{})
83+
err = json.Unmarshal(resp.Body(), &responseBody)
84+
if err != nil {
85+
return err
86+
}
87+
if !(responseBody["ok"].(bool)) {
88+
return fmt.Errorf("failed to delete action. got:\n%s", string(resp.Body()))
89+
}
90+
return nil
91+
}

port/cli/models.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@ type (
3434
Default string `json:"default,omitempty"`
3535
Format string `json:"format,omitempty"`
3636
Description string `json:"description,omitempty"`
37+
Pattern string `json:"pattern,omitempty"`
3738
}
3839

3940
BlueprintSchema struct {
4041
Properties map[string]BlueprintProperty `json:"properties"`
42+
Required []string `json:"required,omitempty"`
4143
}
4244

45+
ActionUserInputs = BlueprintSchema
46+
4347
Blueprint struct {
4448
Meta
4549
Identifier string `json:"identifier,omitempty"`
4650
Title string `json:"title"`
4751
Icon string `json:"icon"`
4852
Schema BlueprintSchema `json:"schema"`
49-
// TODO: relations
53+
}
54+
55+
Action struct {
56+
ID string `json:"id,omitempty"`
57+
Identifier string `json:"identifier,omitempty"`
58+
Description string `json:"description,omitempty"`
59+
Title string `json:"title,omitempty"`
60+
Icon string `json:"icon,omitempty"`
61+
UserInputs ActionUserInputs `json:"userInputs"`
62+
Trigger string `json:"trigger"`
63+
InvocationMethod string `json:"invocationMethod"`
5064
}
5165

5266
Relation struct {
@@ -62,4 +76,5 @@ type PortBody struct {
6276
OK bool `json:"ok"`
6377
Entity Entity `json:"entity"`
6478
Blueprint Blueprint `json:"blueprint"`
79+
Action Action `json:"action"`
6580
}

port/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func Provider() *schema.Provider {
3737
ResourcesMap: map[string]*schema.Resource{
3838
"port-labs_entity": newEntityResource(),
3939
"port-labs_blueprint": newBlueprintResource(),
40+
"port-labs_action": newActionResource(),
4041
},
4142
DataSourcesMap: map[string]*schema.Resource{},
4243
ConfigureContextFunc: providerConfigure,

0 commit comments

Comments
 (0)