Skip to content

Commit

Permalink
Merge pull request #170 from port-labs/PORT-9634-bug-terraform-import…
Browse files Browse the repository at this point in the history
…-action-failed

Fix upsert entity invocation
  • Loading branch information
talsabagport authored Aug 5, 2024
2 parents 7bacc49 + 9212ed5 commit 0bc13ee
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
10 changes: 8 additions & 2 deletions port/action/actionStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,14 @@ func invocationMethodToBody(ctx context.Context, data *ActionModel) (*cli.Invoca
Identifier: data.UpsertEntityMethod.Mapping.Identifier.ValueStringPointer(),
Title: data.UpsertEntityMethod.Title.ValueStringPointer(),
Icon: data.UpsertEntityMethod.Mapping.Icon.ValueStringPointer(),
Properties: *properties,
Relations: *relations,
}

if properties != nil {
mapping.Properties = *properties
}

if relations != nil {
mapping.Relations = *relations
}
}

Expand Down
2 changes: 1 addition & 1 deletion port/action/refreshActionState.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func writeInvocationMethodToResource(ctx context.Context, a *cli.Action, state *
Relations: relations,
Icon: flex.GoStringToFramework(a.InvocationMethod.Mapping.Icon),
Teams: teams,
Identifier: types.StringValue(*a.InvocationMethod.Mapping.Identifier),
Identifier: types.StringPointerValue(a.InvocationMethod.Mapping.Identifier),
},
}
}
Expand Down
43 changes: 43 additions & 0 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2024,3 +2024,46 @@ func TestAccPortActionConditionalTrigger(t *testing.T) {
},
})
}

func TestAccPortActionUpsertEntityWithoutMappingIdentifier(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 = {
properties = jsonencode({"text": "test"})
}
}
}`, 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.TestCheckNoResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.identifier"),
resource.TestCheckResourceAttr("port_action.create_microservice", "upsert_entity_method.mapping.properties", "{\"text\":\"test\"}"),
),
},
},
})
}
2 changes: 1 addition & 1 deletion port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func ActionSchema() map[string]schema.Attribute {
Attributes: map[string]schema.Attribute{
"identifier": schema.StringAttribute{
MarkdownDescription: "Required when selecting type Upsert Entity. The entity identifier for the upsert",
Required: true,
Optional: true,
},
"teams": schema.ListAttribute{
MarkdownDescription: "The teams the entity belongs to",
Expand Down

0 comments on commit 0bc13ee

Please sign in to comment.