-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
782 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "port_integration Resource - terraform-provider-port-labs" | ||
subcategory: "" | ||
description: |- | ||
Integration resource | ||
Docs about integration and be found here https://docs.getport.io/integrations-index/. | ||
```hcl | ||
resource "portintegration" "mycustomintegration" { | ||
installationid = "my-custom-integration-id" | ||
title = "My Custom Integration" | ||
version = "1.33.7" | ||
config = jsonencode({ | ||
createMissingRelatedEntitiesboolean = true | ||
deleteDependentEntities = true, | ||
resources = [{ | ||
kind = "my-custom-kind" | ||
selector = { | ||
query = ".title" | ||
} | ||
port = { | ||
entity = { | ||
mappings = [{ | ||
identifier = "'my-identifier'" | ||
title = ".title" | ||
blueprint = "'my-blueprint'" | ||
properties = { | ||
my_property = 123 | ||
} | ||
relations = {} | ||
}] | ||
} | ||
} | ||
}] | ||
}) | ||
} | ||
``` | ||
NOTICE: | ||
The following config properties (selector.query|entity.mappings.*) are jq expressions, which means that you need to input either a valid jq expression (E.g .title), or if you want a string value, a qouted escaped string val (E.g 'my-string'). | ||
--- | ||
|
||
# port_integration (Resource) | ||
|
||
# Integration resource | ||
|
||
Docs about integration and be found [here](https://docs.getport.io/integrations-index/). | ||
|
||
|
||
```hcl | ||
resource "port_integration" "my_custom_integration" { | ||
installation_id = "my-custom-integration-id" | ||
title = "My Custom Integration" | ||
version = "1.33.7" | ||
config = jsonencode({ | ||
createMissingRelatedEntitiesboolean = true | ||
deleteDependentEntities = true, | ||
resources = [{ | ||
kind = "my-custom-kind" | ||
selector = { | ||
query = ".title" | ||
} | ||
port = { | ||
entity = { | ||
mappings = [{ | ||
identifier = "'my-identifier'" | ||
title = ".title" | ||
blueprint = "'my-blueprint'" | ||
properties = { | ||
my_property = 123 | ||
} | ||
relations = {} | ||
}] | ||
} | ||
} | ||
}] | ||
}) | ||
} | ||
``` | ||
|
||
### NOTICE: | ||
|
||
The following config properties (`selector.query|entity.mappings.*`) are jq expressions, which means that you need to input either a valid jq expression (E.g `.title`), or if you want a string value, a qouted escaped string val (E.g `'my-string'`). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `installation_id` (String) | ||
|
||
### Optional | ||
|
||
- `config` (String) Integration Config Raw JSON string (use `jsonencode`) | ||
- `installation_app_type` (String) | ||
- `kafka_changelog_destination` (Object) The changelog destination of the blueprint (just an empty `{}`) (see [below for nested schema](#nestedatt--kafka_changelog_destination)) | ||
- `title` (String) | ||
- `version` (String) | ||
- `webhook_changelog_destination` (Attributes) The webhook changelog destination of the integration (see [below for nested schema](#nestedatt--webhook_changelog_destination)) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedatt--kafka_changelog_destination"></a> | ||
### Nested Schema for `kafka_changelog_destination` | ||
|
||
Optional: | ||
|
||
|
||
|
||
<a id="nestedatt--webhook_changelog_destination"></a> | ||
### Nested Schema for `webhook_changelog_destination` | ||
|
||
Required: | ||
|
||
- `url` (String) The url of the webhook changelog destination | ||
|
||
Optional: | ||
|
||
- `agent` (Boolean) The agent of the webhook changelog destination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resource "port_integration" "my_custom_integration" { | ||
installation_id = "my-custom-integration-id" | ||
title = "My Custom Integration" | ||
version = "1.33.7" | ||
installation_app_type = "WEBHOOK" | ||
config = jsonencode({ | ||
createMissingRelatedEntitiesboolean = true | ||
deleteDependentEntities = true | ||
resources = [{ | ||
kind = "my-custom-kind" | ||
selector = { | ||
query = ".title" | ||
} | ||
port = { | ||
entity = { | ||
mappings = [{ | ||
identifier = "'my-identifier'" | ||
title = ".title" | ||
blueprint = "'my-blueprint'" | ||
properties = { | ||
my_property = 123 | ||
} | ||
relations = {} | ||
}] | ||
} | ||
} | ||
}] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../provider.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type PortBodyForIntegration struct { | ||
OK bool `json:"ok"` | ||
Integration Integration `json:"integration"` | ||
} | ||
|
||
func (c *PortClient) GetIntegration(ctx context.Context, id string) (*Integration, error) { | ||
pb := &PortBodyForIntegration{} | ||
url := "v1/integration/{identifier}" | ||
resp, err := c.Client.R(). | ||
SetContext(ctx). | ||
SetHeader("Accept", "application/json"). | ||
SetResult(pb). | ||
SetPathParam("identifier", id). | ||
SetQueryParam("byField", "installationId"). | ||
Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to read migration, got: %s", resp.Body()) | ||
} | ||
return &pb.Integration, nil | ||
} | ||
|
||
func (c *PortClient) UpdateIntegration(ctx context.Context, id string, integration *Integration) (*Integration, error) { | ||
url := "v1/integration/{identifier}" | ||
|
||
resp, err := c.Client.R(). | ||
SetBody(integration). | ||
SetContext(ctx). | ||
SetPathParam("identifier", id). | ||
Patch(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var pppb PortBodyForIntegration | ||
err = json.Unmarshal(resp.Body(), &pppb) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pppb.OK { | ||
return nil, fmt.Errorf("failed to update integration, got: %s", resp.Body()) | ||
} | ||
return &pppb.Integration, nil | ||
} | ||
|
||
func (c *PortClient) CreateIntegration(ctx context.Context, integration *Integration) (*Integration, error) { | ||
url := "v1/integration" | ||
|
||
resp, err := c.Client.R(). | ||
SetBody(integration). | ||
SetContext(ctx). | ||
Post(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var pppb PortBodyForIntegration | ||
err = json.Unmarshal(resp.Body(), &pppb) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pppb.OK { | ||
return nil, fmt.Errorf("failed to create integration, got: %s", resp.Body()) | ||
} | ||
|
||
return &pppb.Integration, nil | ||
} | ||
|
||
func (c *PortClient) DeleteIntegration(ctx context.Context, id string) (int, error) { | ||
url := "v1/integration/{identifier}" | ||
resp, err := c.Client.R(). | ||
SetContext(ctx). | ||
SetPathParam("identifier", id). | ||
Delete(url) | ||
if err != nil { | ||
return resp.StatusCode(), err | ||
} | ||
var pb PortBodyForIntegration | ||
err = json.Unmarshal(resp.Body(), &pb) | ||
if err != nil { | ||
return resp.StatusCode(), err | ||
} | ||
if !pb.OK { | ||
return resp.StatusCode(), fmt.Errorf("failed to delete integration, got: %s", resp.Body()) | ||
} | ||
return resp.StatusCode(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package integration | ||
|
||
import ( | ||
"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli" | ||
"github.com/port-labs/terraform-provider-port-labs/v2/internal/consts" | ||
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils" | ||
) | ||
|
||
func integrationToPortBody(state *IntegrationModel) (*cli.Integration, error) { | ||
if state == nil { | ||
return nil, nil | ||
} | ||
|
||
integration := &cli.Integration{ | ||
InstallationId: state.InstallationId.ValueString(), | ||
Version: state.Version.ValueString(), | ||
Title: state.Title.ValueString(), | ||
} | ||
|
||
if !state.InstallationAppType.IsNull() { | ||
installationAppType := state.InstallationAppType.ValueString() | ||
integration.InstallationAppType = &installationAppType | ||
} | ||
|
||
if !state.Config.IsNull() { | ||
configStr := state.Config.ValueString() | ||
config, err := utils.TerraformJsonStringToGoObject(&configStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
integration.Config = config | ||
} | ||
if !state.KafkaChangelogDestination.IsNull() { | ||
integration.ChangelogDestination = &cli.ChangelogDestination{ | ||
Type: consts.Kafka, | ||
} | ||
} | ||
if state.WebhookChangelogDestination != nil { | ||
integration.ChangelogDestination = &cli.ChangelogDestination{ | ||
Type: consts.Webhook, | ||
Url: state.WebhookChangelogDestination.Url.ValueString(), | ||
Agent: state.WebhookChangelogDestination.Agent.ValueBoolPointer(), | ||
} | ||
} | ||
|
||
return integration, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package integration | ||
|
||
import "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
type WebhookChangelogDestinationModel struct { | ||
Url types.String `tfsdk:"url"` | ||
Agent types.Bool `tfsdk:"agent"` | ||
} | ||
|
||
type IntegrationModel struct { | ||
ID types.String `tfsdk:"id"` | ||
InstallationId types.String `tfsdk:"installation_id"` | ||
InstallationAppType types.String `tfsdk:"installation_app_type"` | ||
Title types.String `tfsdk:"title"` | ||
Version types.String `tfsdk:"version"` | ||
Config types.String `tfsdk:"config"` | ||
KafkaChangelogDestination types.Object `tfsdk:"kafka_changelog_destination"` | ||
WebhookChangelogDestination *WebhookChangelogDestinationModel `tfsdk:"webhook_changelog_destination"` | ||
} |
Oops, something went wrong.