Skip to content

Commit

Permalink
Merge pull request #79 from port-labs/PORT-4794-Terraform-provider-po…
Browse files Browse the repository at this point in the history
…rt_action-resource-add-support-in-secret-property

PORT-4794-Terraform-provider-port_action-resource-add-support-in-secret-property
  • Loading branch information
pazhersh authored Oct 3, 2023
2 parents b636416 + 7bdbe13 commit d576572
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vscode/
.env
local/
__debug_bin
__debug_bin*
terraform-provider-port-labs
6 changes: 4 additions & 2 deletions docs/resources/port_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ Optional:
- `default_jq_query` (String) The default jq query of the object property
- `depends_on` (List of String) The properties that this property depends on
- `description` (String) The description of the property
- `encryption` (String) The algorithm to encrypt the property with
- `icon` (String) The icon of the property
- `required` (Boolean) Whether the property is required
- `title` (String) The title of the property
Expand Down Expand Up @@ -357,6 +358,7 @@ Optional:
- `default_jq_query` (String) The default jq query of the string property
- `depends_on` (List of String) The properties that this property depends on
- `description` (String) The description of the property
- `encryption` (String) The algorithm to encrypt the property with
- `enum` (List of String) The enum of the string property
- `enum_jq_query` (String) The enum jq query of the string property
- `format` (String) The format of the string property
Expand Down Expand Up @@ -410,5 +412,5 @@ Required:
Optional:

- `agent` (Boolean) Use the agent to invoke the action


- `method` (String) The HTTP method to invoke the action
- `synchronized` (Boolean) Synchronize the action
2 changes: 0 additions & 2 deletions docs/resources/port_blueprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,3 @@ Required:
Optional:

- `agent` (Boolean) The agent of the webhook changelog destination


2 changes: 0 additions & 2 deletions docs/resources/port_entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ 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


6 changes: 2 additions & 4 deletions docs/resources/port_scorecard.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ description: |-

scorecard resource

<!-- schema generated by tfplugindocs -->


<!-- schema generated by tfplugindocs -->
## Schema

### Required
Expand All @@ -30,7 +31,6 @@ scorecard resource
- `updated_by` (String) The last updater of the scorecard

<a id="nestedatt--rules"></a>

### Nested Schema for `rules`

Required:
Expand All @@ -41,7 +41,6 @@ Required:
- `title` (String) The title of the rule

<a id="nestedatt--rules--query"></a>

### Nested Schema for `rules.query`

Required:
Expand All @@ -50,7 +49,6 @@ Required:
- `conditions` (Attributes List) The conditions of the query (see [below for nested schema](#nestedatt--rules--query--conditions))

<a id="nestedatt--rules--query--conditions"></a>

### Nested Schema for `rules.query.conditions`

Required:
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/port_team.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ 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


2 changes: 0 additions & 2 deletions docs/resources/port_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ 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


1 change: 1 addition & 0 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type (
EnumColors map[string]string `json:"enumColors,omitempty"`
DependsOn []string `json:"dependsOn,omitempty"`
Dataset *Dataset `json:"dataset,omitempty"`
Encryption *string `json:"encryption,omitempty"`
}

SpecAuthentication struct {
Expand Down
2 changes: 2 additions & 0 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type StringPropModel struct {
Dataset *DatasetModel `tfsdk:"dataset"`
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
Encryption types.String `tfsdk:"encryption"`
}

type NumberPropModel struct {
Expand Down Expand Up @@ -117,6 +118,7 @@ type ObjectPropModel struct {
DependsOn types.List `tfsdk:"depends_on"`
Dataset *DatasetModel `tfsdk:"dataset"`
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
Encryption types.String `tfsdk:"encryption"`
}

type StringItems struct {
Expand Down
9 changes: 8 additions & 1 deletion port/action/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

"github.com/port-labs/terraform-provider-port-labs/internal/cli"
"github.com/port-labs/terraform-provider-port-labs/internal/flex"
"github.com/port-labs/terraform-provider-port-labs/internal/utils"
)

Expand Down Expand Up @@ -55,7 +56,11 @@ func objectPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
return err
}
property.DependsOn = utils.InterfaceToStringArray(dependsOn)
}

if !prop.Encryption.IsNull() {
encryption := prop.Encryption.ValueString()
property.Encryption = &encryption
}

if prop.Dataset != nil {
Expand All @@ -73,7 +78,9 @@ func objectPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
}

func addObjectPropertiesToResource(v *cli.ActionProperty) *ObjectPropModel {
objectProp := &ObjectPropModel{}
objectProp := &ObjectPropModel{
Encryption: flex.GoStringToFramework(v.Encryption),
}

return objectProp
}
57 changes: 57 additions & 0 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,60 @@ func TestAccPortActionOrderProperties(t *testing.T) {
},
})
}

func TestAccPortActionEncryption(t *testing.T) {
blueprintIdentifier := utils.GenID()
actionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(`
resource "port_action" "action1" {
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" = "fernet"
}
}
"object_props" = {
"encryptedObjectProp" = {
"title" = "Encrypted object"
"required" = true
"encryption" = "fernet"
}
}
}
}`, 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.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", "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", "fernet"),
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", "fernet"),
),
},
},
})
}
14 changes: 14 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func StringPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("enum")),
},
},
"encryption": schema.StringAttribute{
MarkdownDescription: "The algorithm to encrypt the property with",
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("fernet"),
},
},
}

utils.CopyMaps(stringPropertySchema, MetadataProperties())
Expand Down Expand Up @@ -415,6 +422,13 @@ func ObjectPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("default")),
},
},
"encryption": schema.StringAttribute{
MarkdownDescription: "The algorithm to encrypt the property with",
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("fernet"),
},
},
}
utils.CopyMaps(objectPropertySchema, MetadataProperties())
return schema.MapNestedAttribute{
Expand Down
16 changes: 11 additions & 5 deletions port/action/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
property.DependsOn = utils.InterfaceToStringArray(dependsOn)
}

if !prop.Encryption.IsNull() {
encryption := prop.Encryption.ValueString()
property.Encryption = &encryption
}

if prop.Dataset != nil {
property.Dataset = actionDataSetToPortBody(prop.Dataset)
}
Expand All @@ -109,11 +114,12 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str

func addStringPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *StringPropModel {
stringProp := &StringPropModel{
MinLength: flex.GoInt64ToFramework(v.MinLength),
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
Pattern: flex.GoStringToFramework(v.Pattern),
Format: flex.GoStringToFramework(v.Format),
Blueprint: flex.GoStringToFramework(v.Blueprint),
MinLength: flex.GoInt64ToFramework(v.MinLength),
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
Pattern: flex.GoStringToFramework(v.Pattern),
Format: flex.GoStringToFramework(v.Format),
Blueprint: flex.GoStringToFramework(v.Blueprint),
Encryption: flex.GoStringToFramework(v.Encryption),
}

if v.Enum != nil {
Expand Down

0 comments on commit d576572

Please sign in to comment.