Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the colors mapping to blueprint in calculation property #189

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ setup:
acctest:
# TEST_FILTER can be any regex, E.g: .*PageResource.*
# TEST_FILTER='TestAccPortPageResource*' make acctest
TF_ACC=1 PORT_CLIENT_ID=$(PORT_CLIENT_ID) PORT_CLIENT_SECRET=$(PORT_CLIENT_SECRET) PORT_BASE_URL=$(PORT_BASE_URL) go test -p 1 ./... -run "$(TEST_FILTER)"
TF_ACC=1 PORT_CLIENT_ID=$(PORT_CLIENT_ID) PORT_CLIENT_SECRET=$(PORT_CLIENT_SECRET) PORT_BASE_URL=$(PORT_BASE_URL) go test -timeout 20m -p 1 ./... -run "$(TEST_FILTER)"

gen-docs:
tfplugindocs
Expand Down
45 changes: 24 additions & 21 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1570,11 +1570,12 @@ func TestAccPortAutomationTimerPropertyExpired(t *testing.T) {

func TestAccPortAutomationRunCreated(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
mainActionIdentifier := utils.GenID()
relatedActionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "self_serve_action" {
title = "self serve action"
identifier = "self_serve_action"
identifier = "%s"
icon = "Terraform"
self_service_trigger = {
operation = "CREATE"
Expand All @@ -1590,12 +1591,12 @@ func TestAccPortAutomationRunCreated(t *testing.T) {
icon = "Terraform"
automation_trigger = {
run_created_event = {
action_identifier = "self_serve_action"
action_identifier = "%s"
}
}
kafka_method = {}
depends_on = [port_action.self_serve_action]
}`, actionIdentifier)
}`, relatedActionIdentifier, mainActionIdentifier, relatedActionIdentifier)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Expand All @@ -1604,28 +1605,29 @@ func TestAccPortAutomationRunCreated(t *testing.T) {
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", "identifier", mainActionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_created_event.action_identifier", "self_serve_action"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_created_event.action_identifier", relatedActionIdentifier),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
ImportStateId: mainActionIdentifier,
},
},
})
}

func TestAccPortAutomationRunUpdated(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
mainActionIdentifier := utils.GenID()
relatedActionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "self_serve_action" {
title = "self serve action"
identifier = "self_serve_action"
identifier = "%s"
icon = "Terraform"
self_service_trigger = {
operation = "CREATE"
Expand All @@ -1641,12 +1643,12 @@ func TestAccPortAutomationRunUpdated(t *testing.T) {
icon = "Terraform"
automation_trigger = {
run_updated_event = {
action_identifier = "self_serve_action"
action_identifier = "%s"
}
}
kafka_method = {}
depends_on = [port_action.self_serve_action]
}`, actionIdentifier)
}`, relatedActionIdentifier, mainActionIdentifier, relatedActionIdentifier)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Expand All @@ -1655,28 +1657,29 @@ func TestAccPortAutomationRunUpdated(t *testing.T) {
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", "identifier", mainActionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_updated_event.action_identifier", "self_serve_action"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.run_updated_event.action_identifier", relatedActionIdentifier),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
ImportStateId: mainActionIdentifier,
},
},
})
}

func TestAccPortAutomationAnyRunChange(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
mainActionIdentifier := utils.GenID()
relatedActionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "self_serve_action" {
title = "self serve action"
identifier = "self_serve_action"
identifier = "%s"
icon = "Terraform"
self_service_trigger = {
operation = "CREATE"
Expand All @@ -1692,12 +1695,12 @@ func TestAccPortAutomationAnyRunChange(t *testing.T) {
icon = "Terraform"
automation_trigger = {
any_run_change_event = {
action_identifier = "self_serve_action"
action_identifier = "%s"
}
}
kafka_method = {}
depends_on = [port_action.self_serve_action]
}`, actionIdentifier)
}`, relatedActionIdentifier, mainActionIdentifier, relatedActionIdentifier)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Expand All @@ -1706,16 +1709,16 @@ func TestAccPortAutomationAnyRunChange(t *testing.T) {
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", "identifier", mainActionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.any_run_change_event.action_identifier", "self_serve_action"),
resource.TestCheckResourceAttr("port_action.create_microservice", "automation_trigger.any_run_change_event.action_identifier", relatedActionIdentifier),
),
},
{
ResourceName: "port_action.create_microservice",
ImportState: true,
ImportStateVerify: true,
ImportStateId: actionIdentifier,
ImportStateId: mainActionIdentifier,
},
},
})
Expand Down
5 changes: 4 additions & 1 deletion port/blueprint/readStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blueprint
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"
)

Expand Down Expand Up @@ -130,7 +131,9 @@ func calculationPropertiesToBody(ctx context.Context, state *BlueprintModel) map
if !prop.Colors.IsNull() {
colors := make(map[string]string)
for key, value := range prop.Colors.Elements() {
colors[key] = value.String()
if stringValue, ok := value.(basetypes.StringValue); ok {
colors[key] = stringValue.ValueString()
}
}

calculationProp.Colors = colors
Expand Down
9 changes: 8 additions & 1 deletion port/blueprint/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,12 @@ func TestAccPortBlueprintWithCalculationProperty(t *testing.T) {
calculation = "test-rel.$identifier"
type = "string"
icon = "Terraform"
colors = {
"test1" = "red"
"test2" = "blue"
"test3" = "green"
"test4" = "yellow"
}
}
}
}`, identifier1)
Expand All @@ -686,6 +692,7 @@ func TestAccPortBlueprintWithCalculationProperty(t *testing.T) {
resource.TestCheckResourceAttr("port_blueprint.microservice1", "calculation_properties.calculation-for-microservice1.title", "Calculation for microservice1"),
resource.TestCheckResourceAttr("port_blueprint.microservice1", "calculation_properties.calculation-for-microservice1.calculation", "test-rel.$identifier"),
resource.TestCheckResourceAttr("port_blueprint.microservice1", "calculation_properties.calculation-for-microservice1.icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint.microservice1", "calculation_properties.calculation-for-microservice1.colors.test2", "blue"),
),
},
},
Expand Down Expand Up @@ -885,7 +892,7 @@ func TestAccPortBlueprintCatalogPageCreation(t *testing.T) {
}

// give grace time for page creation
time.Sleep(3 * time.Second)
time.Sleep(10 * time.Second)

_, statusCode, err := portClient.GetPage(ctx, identifier)
if err != nil {
Expand Down
Loading