diff --git a/CHANGELOG.MD b/CHANGELOG.MD new file mode 100644 index 00000000..1b4ee2c4 --- /dev/null +++ b/CHANGELOG.MD @@ -0,0 +1,6 @@ +## 0.2.0 +FEATURES: +- `resource/port-labs_entity`: The attribute `properties/type` is DEPRECATED. You do not need to specify the type of a property, and it is inferred from the blueprint. It is recommended to remove `type`. + +BREAKING CHANGES: +- `resource/port-labs_blueprint`: Removed deprecated attribute `data_source`. diff --git a/Makefile b/Makefile index 8f00211c..5747b252 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ HOSTNAME=github.com NAMESPACE=port-labs NAME=port-labs BINARY=terraform-provider-${NAME} -VERSION=0.1.1 +VERSION=0.2.0 OS=$(shell go env GOOS) ARCH=$(shell go env GOARCH) OS_ARCH=${OS}_${ARCH} diff --git a/docs/resources/blueprint.md b/docs/resources/blueprint.md index 6a148eb8..a956b6f0 100644 --- a/docs/resources/blueprint.md +++ b/docs/resources/blueprint.md @@ -24,7 +24,7 @@ Port blueprint ### Optional -- `data_source` (String) The data source for entities of this blueprint +- `data_source` (String, Deprecated) The data source for entities of this blueprint - `relations` (Block Set) The blueprints that are connected to this blueprint (see [below for nested schema](#nestedblock--relations)) ### Read-Only diff --git a/docs/resources/entity.md b/docs/resources/entity.md index 46c98dcb..4fbd7a9c 100644 --- a/docs/resources/entity.md +++ b/docs/resources/entity.md @@ -40,11 +40,11 @@ Port entity Required: - `name` (String) The name of this property -- `type` (String) The type of the property Optional: - `items` (List of String) The list of items, in case the type of this property is a list +- `type` (String, Deprecated) The type of the property - `value` (String) The value for this property diff --git a/examples/main.tf b/examples/main.tf index 8746c4ed..a1b136f0 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -14,6 +14,5 @@ resource "port-labs_entity" "microservice" { properties { name = "microservice_name" value = "golang_monolith" - type = "string" } } diff --git a/examples/provider/basic/main.tf b/examples/provider/basic/main.tf index b39cabdd..53cb2624 100644 --- a/examples/provider/basic/main.tf +++ b/examples/provider/basic/main.tf @@ -6,6 +6,5 @@ resource "port-labs_entity" "microservice" { properties { name = "microservice_name" value = "golang_monolith" - type = "string" } } diff --git a/examples/resources/port-labs_entity/main.tf b/examples/resources/port-labs_entity/main.tf index b71229c7..b411c5c7 100644 --- a/examples/resources/port-labs_entity/main.tf +++ b/examples/resources/port-labs_entity/main.tf @@ -8,7 +8,6 @@ resource "port-labs_entity" "microservice" { properties { name = "microservice_name" value = "golang_monolith" - type = "string" } } @@ -18,6 +17,5 @@ resource "port-labs_entity" "prod_env" { properties { name = "name" value = "production-env" - type = "string" } } diff --git a/port/cli/models.go b/port/cli/models.go index c1c82bd1..ba6847ab 100644 --- a/port/cli/models.go +++ b/port/cli/models.go @@ -45,7 +45,6 @@ type ( Identifier string `json:"identifier,omitempty"` Title string `json:"title"` Icon string `json:"icon"` - DataSource string `json:"dataSource"` Schema BlueprintSchema `json:"schema"` // TODO: relations } diff --git a/port/resource_port_blueprint.go b/port/resource_port_blueprint.go index a161feb1..3e4f1807 100644 --- a/port/resource_port_blueprint.go +++ b/port/resource_port_blueprint.go @@ -34,6 +34,7 @@ func newBlueprintResource() *schema.Resource { Description: "The data source for entities of this blueprint", Default: "Port", Optional: true, + Deprecated: "Data source is ignored", }, "icon": { Type: schema.TypeString, @@ -172,7 +173,6 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) { d.SetId(b.Identifier) d.Set("title", b.Title) d.Set("icon", b.Icon) - d.Set("data_source", b.DataSource) d.Set("created_at", b.CreatedAt.String()) d.Set("created_by", b.CreatedBy) d.Set("updated_at", b.UpdatedAt.String()) @@ -206,9 +206,6 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) { b.Title = d.Get("title").(string) b.Icon = d.Get("icon").(string) - if ds, ok := d.GetOk("data_source"); ok { - b.DataSource = ds.(string) - } props := d.Get("properties").(*schema.Set) properties := make(map[string]cli.BlueprintProperty, props.Len()) diff --git a/port/resource_port_entity.go b/port/resource_port_entity.go index 60cf8694..2a822879 100644 --- a/port/resource_port_entity.go +++ b/port/resource_port_entity.go @@ -67,7 +67,8 @@ func newEntityResource() *schema.Resource { "type": { Type: schema.TypeString, ValidateFunc: validation.StringInSlice([]string{"number", "string", "boolean", "array", "object"}, false), - Required: true, + Optional: true, + Deprecated: "property type is not required anymore", Description: "The type of the property", }, "value": { @@ -117,8 +118,15 @@ func deleteEntity(ctx context.Context, d *schema.ResourceData, m interface{}) di return diags } -func convert(prop map[string]interface{}) (interface{}, error) { +func convert(prop map[string]interface{}, bp *cli.Blueprint) (interface{}, error) { valType := prop["type"].(string) + if valType == "" { + if p, ok := bp.Schema.Properties[prop["name"].(string)]; ok { + valType = p.Type + } else { + return nil, fmt.Errorf("no type found for property %s", prop["name"]) + } + } switch valType { case "string", "number", "boolean": return prop["value"], nil @@ -135,7 +143,7 @@ func convert(prop map[string]interface{}) (interface{}, error) { return "", fmt.Errorf("unsupported type %s", valType) } -func entityResourceToBody(d *schema.ResourceData) (*cli.Entity, error) { +func entityResourceToBody(d *schema.ResourceData, bp *cli.Blueprint) (*cli.Entity, error) { e := &cli.Entity{} if identifier, ok := d.GetOk("identifier"); ok { e.Identifier = identifier.(string) @@ -157,7 +165,7 @@ func entityResourceToBody(d *schema.ResourceData) (*cli.Entity, error) { properties := make(map[string]interface{}, props.Len()) for _, prop := range props.List() { p := prop.(map[string]interface{}) - propValue, err := convert(p) + propValue, err := convert(p, bp) if err != nil { return nil, err } @@ -194,23 +202,17 @@ func writeEntityFieldsToResource(d *schema.ResourceData, e *cli.Entity) { p["name"] = k switch t := v.(type) { case map[string]interface{}: - p["type"] = "object" js, _ := json.Marshal(&t) p["value"] = string(js) case []interface{}: - p["type"] = "array" p["items"] = t case float64: - p["type"] = "number" p["value"] = strconv.FormatFloat(t, 'f', -1, 64) case int: - p["type"] = "number" p["value"] = strconv.Itoa(t) case string: - p["type"] = "string" p["value"] = t case bool: - p["type"] = "boolean" p["value"] = "false" if t { p["value"] = "true" @@ -224,7 +226,11 @@ func writeEntityFieldsToResource(d *schema.ResourceData, e *cli.Entity) { func createEntity(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*cli.PortClient) - e, err := entityResourceToBody(d) + bp, err := c.ReadBlueprint(ctx, d.Get("blueprint").(string)) + if err != nil { + return diag.FromErr(err) + } + e, err := entityResourceToBody(d, bp) if err != nil { return diag.FromErr(err) } diff --git a/port/resource_port_entity_test.go b/port/resource_port_entity_test.go index 13e0ab46..84a95c8d 100644 --- a/port/resource_port_entity_test.go +++ b/port/resource_port_entity_test.go @@ -16,7 +16,6 @@ func TestAccPortEntityUpdateProp(t *testing.T) { properties { name = "text" value = "hedwig" - type = "string" } } ` @@ -28,7 +27,6 @@ func TestAccPortEntityUpdateProp(t *testing.T) { properties { name = "text" value = "hedwig2" - type = "string" } } ` @@ -57,27 +55,22 @@ func TestAccPortEntity(t *testing.T) { properties { name = "text" value = "hedwig" - type = "string" } properties { name = "bool" value = "true" - type = "boolean" } properties { name = "num" value = 123 - type = "number" } properties { name = "arr" items = [1,2,3] - type = "array" } properties { name = "obj" value = jsonencode({"a":"b"}) - type = "object" } } ` @@ -106,7 +99,6 @@ func TestAccPortEntitiesRelation(t *testing.T) { properties { name = "text" value = "test-relation" - type = "string" } } resource "port-labs_entity" "microservice2" { @@ -115,7 +107,6 @@ func TestAccPortEntitiesRelation(t *testing.T) { properties { name = "str" value = "test-relation" - type = "string" } } `