Skip to content

Commit

Permalink
Entity | use float64 of terraform instead of go (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirsegev authored Jul 30, 2023
1 parent 3e4cd26 commit 373fc50
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion port/entity/entityResourceToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func entityResourceToBody(ctx context.Context, state *EntityModel, bp *cli.Bluep

if state.Properties.NumberProps != nil {
for propIdentifier, prop := range state.Properties.NumberProps {
properties[propIdentifier] = prop
properties[propIdentifier] = prop.ValueFloat64()
}
}

Expand Down
10 changes: 5 additions & 5 deletions port/entity/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type ArrayPropsModel struct {
}

type EntityPropertiesModel struct {
StringProps map[string]string `tfsdk:"string_props"`
NumberProps map[string]float64 `tfsdk:"number_props"`
BooleanProps map[string]bool `tfsdk:"boolean_props"`
ObjectProps map[string]string `tfsdk:"object_props"`
ArrayProps *ArrayPropsModel `tfsdk:"array_props"`
StringProps map[string]string `tfsdk:"string_props"`
NumberProps map[string]types.Float64 `tfsdk:"number_props"`
BooleanProps map[string]bool `tfsdk:"boolean_props"`
ObjectProps map[string]string `tfsdk:"object_props"`
ArrayProps *ArrayPropsModel `tfsdk:"array_props"`
}

type RelationModel struct {
Expand Down
5 changes: 3 additions & 2 deletions port/entity/refreshEntityState.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

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

Expand Down Expand Up @@ -56,9 +57,9 @@ func refreshPropertiesEntityState(ctx context.Context, state *EntityModel, e *cl
switch t := v.(type) {
case float64:
if state.Properties.NumberProps == nil {
state.Properties.NumberProps = make(map[string]float64)
state.Properties.NumberProps = make(map[string]types.Float64)
}
state.Properties.NumberProps[k] = float64(t)
state.Properties.NumberProps[k] = basetypes.NewFloat64Value(t)
case string:
if state.Properties.StringProps == nil {
state.Properties.StringProps = make(map[string]string)
Expand Down
4 changes: 2 additions & 2 deletions port/entity/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestAccPortEntity(t *testing.T) {
"myStringIdentifier" = "My String Value"
}
"number_props" = {
"myNumberIdentifier" = 123
"myNumberIdentifier" = 123.456
}
"boolean_props" = {
"myBooleanIdentifier" = true
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestAccPortEntity(t *testing.T) {
resource.TestCheckResourceAttr("port_entity.microservice", "title", "TF Provider Test Entity0"),
resource.TestCheckResourceAttr("port_entity.microservice", "blueprint", identifier),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.string_props.myStringIdentifier", "My String Value"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.number_props.myNumberIdentifier", "123"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.number_props.myNumberIdentifier", "123.456"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.boolean_props.myBooleanIdentifier", "true"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.object_props.myObjectIdentifier", "{\"foo\":\"bar\"}"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myStringArrayIdentifier.0", "My Array Value"),
Expand Down

0 comments on commit 373fc50

Please sign in to comment.