Skip to content

Commit d576572

Browse files
authored
Merge pull request #79 from port-labs/PORT-4794-Terraform-provider-port_action-resource-add-support-in-secret-property
PORT-4794-Terraform-provider-port_action-resource-add-support-in-secret-property
2 parents b636416 + 7bdbe13 commit d576572

13 files changed

+100
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.vscode/
22
.env
33
local/
4-
__debug_bin
4+
__debug_bin*
55
terraform-provider-port-labs

docs/resources/port_action.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ Optional:
310310
- `default_jq_query` (String) The default jq query of the object property
311311
- `depends_on` (List of String) The properties that this property depends on
312312
- `description` (String) The description of the property
313+
- `encryption` (String) The algorithm to encrypt the property with
313314
- `icon` (String) The icon of the property
314315
- `required` (Boolean) Whether the property is required
315316
- `title` (String) The title of the property
@@ -357,6 +358,7 @@ Optional:
357358
- `default_jq_query` (String) The default jq query of the string property
358359
- `depends_on` (List of String) The properties that this property depends on
359360
- `description` (String) The description of the property
361+
- `encryption` (String) The algorithm to encrypt the property with
360362
- `enum` (List of String) The enum of the string property
361363
- `enum_jq_query` (String) The enum jq query of the string property
362364
- `format` (String) The format of the string property
@@ -410,5 +412,5 @@ Required:
410412
Optional:
411413

412414
- `agent` (Boolean) Use the agent to invoke the action
413-
414-
415+
- `method` (String) The HTTP method to invoke the action
416+
- `synchronized` (Boolean) Synchronize the action

docs/resources/port_blueprint.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,3 @@ Required:
242242
Optional:
243243

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

docs/resources/port_entity.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,3 @@ Optional:
6767

6868
- `many_relations` (Map of List of String) The many relation of the entity
6969
- `single_relations` (Map of String) The single relation of the entity
70-
71-

docs/resources/port_scorecard.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ description: |-
1010

1111
scorecard resource
1212

13-
<!-- schema generated by tfplugindocs -->
1413

14+
15+
<!-- schema generated by tfplugindocs -->
1516
## Schema
1617

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

3233
<a id="nestedatt--rules"></a>
33-
3434
### Nested Schema for `rules`
3535

3636
Required:
@@ -41,7 +41,6 @@ Required:
4141
- `title` (String) The title of the rule
4242

4343
<a id="nestedatt--rules--query"></a>
44-
4544
### Nested Schema for `rules.query`
4645

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

5251
<a id="nestedatt--rules--query--conditions"></a>
53-
5452
### Nested Schema for `rules.query.conditions`
5553

5654
Required:

docs/resources/port_team.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@ Team resource
3030
- `id` (String) The ID of this resource.
3131
- `provider_name` (String) The provider of the team
3232
- `updated_at` (String) The last update date of the team
33-
34-

docs/resources/port_webhook.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,3 @@ Optional:
7575
- `signature_algorithm` (String) The signature algorithm of the webhook
7676
- `signature_header_name` (String) The signature header name of the webhook
7777
- `signature_prefix` (String) The signature prefix of the webhook
78-
79-

internal/cli/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type (
7676
EnumColors map[string]string `json:"enumColors,omitempty"`
7777
DependsOn []string `json:"dependsOn,omitempty"`
7878
Dataset *Dataset `json:"dataset,omitempty"`
79+
Encryption *string `json:"encryption,omitempty"`
7980
}
8081

8182
SpecAuthentication struct {

port/action/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type StringPropModel struct {
6464
Dataset *DatasetModel `tfsdk:"dataset"`
6565
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
6666
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
67+
Encryption types.String `tfsdk:"encryption"`
6768
}
6869

6970
type NumberPropModel struct {
@@ -117,6 +118,7 @@ type ObjectPropModel struct {
117118
DependsOn types.List `tfsdk:"depends_on"`
118119
Dataset *DatasetModel `tfsdk:"dataset"`
119120
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
121+
Encryption types.String `tfsdk:"encryption"`
120122
}
121123

122124
type StringItems struct {

port/action/object.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66

77
"github.com/port-labs/terraform-provider-port-labs/internal/cli"
8+
"github.com/port-labs/terraform-provider-port-labs/internal/flex"
89
"github.com/port-labs/terraform-provider-port-labs/internal/utils"
910
)
1011

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

61+
if !prop.Encryption.IsNull() {
62+
encryption := prop.Encryption.ValueString()
63+
property.Encryption = &encryption
5964
}
6065

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

7580
func addObjectPropertiesToResource(v *cli.ActionProperty) *ObjectPropModel {
76-
objectProp := &ObjectPropModel{}
81+
objectProp := &ObjectPropModel{
82+
Encryption: flex.GoStringToFramework(v.Encryption),
83+
}
7784

7885
return objectProp
7986
}

port/action/resource_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,60 @@ func TestAccPortActionOrderProperties(t *testing.T) {
797797
},
798798
})
799799
}
800+
801+
func TestAccPortActionEncryption(t *testing.T) {
802+
blueprintIdentifier := utils.GenID()
803+
actionIdentifier := utils.GenID()
804+
var testAccActionConfigCreate = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(`
805+
resource "port_action" "action1" {
806+
title = "TF Provider Test"
807+
identifier = "%s"
808+
icon = "Terraform"
809+
blueprint = port_blueprint.microservice.id
810+
trigger = "DAY-2"
811+
webhook_method = {
812+
url = "https://getport.io"
813+
}
814+
user_properties = {
815+
"string_props" = {
816+
"encryptedStringProp" = {
817+
"title" = "Encrypted string"
818+
"required" = true
819+
"encryption" = "fernet"
820+
}
821+
}
822+
"object_props" = {
823+
"encryptedObjectProp" = {
824+
"title" = "Encrypted object"
825+
"required" = true
826+
"encryption" = "fernet"
827+
}
828+
}
829+
}
830+
}`, actionIdentifier)
831+
832+
resource.Test(t, resource.TestCase{
833+
PreCheck: func() { acctest.TestAccPreCheck(t) },
834+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
835+
836+
Steps: []resource.TestStep{
837+
{
838+
Config: acctest.ProviderConfig + testAccActionConfigCreate,
839+
Check: resource.ComposeTestCheckFunc(
840+
resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"),
841+
resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier),
842+
resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"),
843+
resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier),
844+
resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"),
845+
resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"),
846+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.title", "Encrypted string"),
847+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.required", "true"),
848+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.encryption", "fernet"),
849+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.title", "Encrypted object"),
850+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.required", "true"),
851+
resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.encryption", "fernet"),
852+
),
853+
},
854+
},
855+
})
856+
}

port/action/schema.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ func StringPropertySchema() schema.Attribute {
316316
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("enum")),
317317
},
318318
},
319+
"encryption": schema.StringAttribute{
320+
MarkdownDescription: "The algorithm to encrypt the property with",
321+
Optional: true,
322+
Validators: []validator.String{
323+
stringvalidator.OneOf("fernet"),
324+
},
325+
},
319326
}
320327

321328
utils.CopyMaps(stringPropertySchema, MetadataProperties())
@@ -415,6 +422,13 @@ func ObjectPropertySchema() schema.Attribute {
415422
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("default")),
416423
},
417424
},
425+
"encryption": schema.StringAttribute{
426+
MarkdownDescription: "The algorithm to encrypt the property with",
427+
Optional: true,
428+
Validators: []validator.String{
429+
stringvalidator.OneOf("fernet"),
430+
},
431+
},
418432
}
419433
utils.CopyMaps(objectPropertySchema, MetadataProperties())
420434
return schema.MapNestedAttribute{

port/action/string.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
9494
property.DependsOn = utils.InterfaceToStringArray(dependsOn)
9595
}
9696

97+
if !prop.Encryption.IsNull() {
98+
encryption := prop.Encryption.ValueString()
99+
property.Encryption = &encryption
100+
}
101+
97102
if prop.Dataset != nil {
98103
property.Dataset = actionDataSetToPortBody(prop.Dataset)
99104
}
@@ -109,11 +114,12 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
109114

110115
func addStringPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *StringPropModel {
111116
stringProp := &StringPropModel{
112-
MinLength: flex.GoInt64ToFramework(v.MinLength),
113-
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
114-
Pattern: flex.GoStringToFramework(v.Pattern),
115-
Format: flex.GoStringToFramework(v.Format),
116-
Blueprint: flex.GoStringToFramework(v.Blueprint),
117+
MinLength: flex.GoInt64ToFramework(v.MinLength),
118+
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
119+
Pattern: flex.GoStringToFramework(v.Pattern),
120+
Format: flex.GoStringToFramework(v.Format),
121+
Blueprint: flex.GoStringToFramework(v.Blueprint),
122+
Encryption: flex.GoStringToFramework(v.Encryption),
117123
}
118124

119125
if v.Enum != nil {

0 commit comments

Comments
 (0)