Skip to content

Commit

Permalink
Merge pull request #192 from port-labs/PORT-12030-bug-teams-attribute…
Browse files Browse the repository at this point in the history
…-in-ssa-expects-a-list-of-strings-but-fails-saying-it-expected-a-string-and-got-array-2

add teams_jq support
  • Loading branch information
Tomer-Buhadana-Port authored Dec 24, 2024
2 parents 14f639f + c699e78 commit 10618fe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions port/action/actionStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca
if data.UpsertEntityMethod.Mapping.Teams != nil {
team = flex.TerraformStringListToGoArray(data.UpsertEntityMethod.Mapping.Teams)
}
if !data.UpsertEntityMethod.Mapping.TeamsJQ.IsNull() {
team = data.UpsertEntityMethod.Mapping.TeamsJQ.ValueString()
}
properties, err := utils.TerraformJsonStringToGoObject(data.UpsertEntityMethod.Mapping.Properties.ValueStringPointer())
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ type MappingModel struct {
Relations types.String `tfsdk:"relations"`
Identifier types.String `tfsdk:"identifier"`
Teams []types.String `tfsdk:"teams"`
TeamsJQ types.String `tfsdk:"teams_jq"`
Icon types.String `tfsdk:"icon"`
}

Expand Down
5 changes: 4 additions & 1 deletion port/action/refreshActionState.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state *

if a.InvocationMethod.Type == consts.UpsertEntity {
var teams []types.String
var teamsJQ types.String
switch team := a.InvocationMethod.Mapping.Team.(type) {
case string:
teams = append(teams, types.StringValue(team))
teamsJQ = types.StringValue(team)
case []interface{}:
teams = make([]types.String, 0)
for _, t := range team {
teams = append(teams, types.StringValue(t.(string)))
}
teamsJQ = types.StringNull()
}
properties, err := utils.GoObjectToTerraformString(a.InvocationMethod.Mapping.Properties)
if err != nil {
Expand All @@ -128,6 +130,7 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state *
Relations: relations,
Icon: flex.GoStringToFramework(a.InvocationMethod.Mapping.Icon),
Teams: teams,
TeamsJQ: teamsJQ,
Identifier: types.StringPointerValue(a.InvocationMethod.Mapping.Identifier),
},
}
Expand Down
50 changes: 50 additions & 0 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,56 @@ func TestAccPortActionUpsertEntityInvocation(t *testing.T) {
})
}

func TestAccPortActionUpsertEntityInvocationWithJqTeams(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 = {
title = "Test Entity"
blueprint_identifier = port_blueprint.microservice.identifier
mapping = {
identifier = "test-entity"
teams_jq = "{{.entity.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.title", "Test Entity"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.blueprint_identifier", identifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.identifier", "test-entity"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.teams_jq", "{{.entity.teams}}"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.properties", "{\"text\":\"test\"}"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.relations", "{\"test-rel\":\"target-bp\"}"),
),
},
},
})
}

func TestAccPortActionImport(t *testing.T) {
blueprintIdentifier := utils.GenID()
actionIdentifier := utils.GenID()
Expand Down
7 changes: 7 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ func ActionSchema() map[string]schema.Attribute {
ElementType: types.StringType,
Optional: true,
},
"teams_jq": schema.StringAttribute{
MarkdownDescription: "Jq that returns the teams the entity belongs to",
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("teams")),
},
},
"icon": schema.StringAttribute{
MarkdownDescription: "The icon of the entity",
Optional: true,
Expand Down

0 comments on commit 10618fe

Please sign in to comment.