Skip to content

Commit

Permalink
added spec (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsinai authored Feb 26, 2023
1 parent dcdf1ba commit e5c2d5d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions port/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type (
Blueprint string `json:"blueprint,omitempty"`
Pattern string `json:"pattern,omitempty"`
Enum []string `json:"enum,omitempty"`
Spec string `json:"spec,omitempty"`
EnumColors map[string]string `json:"enumColors,omitempty"`
}

Expand Down
12 changes: 12 additions & 0 deletions port/resource_port_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func newBlueprintResource() *schema.Resource {
Optional: true,
Description: "The format of the Property",
},
"spec": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"async-api", "open-api", "embedded-url"}, false),
Description: "The specification of the property, one of \"async-api\", \"open-api\", \"embedded-url\"",
},
"enum": {
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -331,6 +337,7 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
p["description"] = v.Description
p["format"] = v.Format
p["icon"] = v.Icon
p["spec"] = v.Spec
p["enum"] = v.Enum
p["enum_colors"] = v.EnumColors
if lo.Contains(b.Schema.Required, k) {
Expand Down Expand Up @@ -470,6 +477,11 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
if i, ok := p["icon"]; ok && i != "" {
propFields.Icon = i.(string)
}

if s, ok := p["spec"]; ok && s != "" {
propFields.Spec = s.(string)
}

if r, ok := p["required"]; ok && r.(bool) {
required = append(required, p["identifier"].(string))
}
Expand Down
31 changes: 31 additions & 0 deletions port/resource_port_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ func TestAccPortBlueprint(t *testing.T) {
})
}

func TestAccBlueprintWithSpecification(t *testing.T) {
identifier := genID()
var testAccActionConfigCreate = fmt.Sprintf(`
resource "port-labs_blueprint" "microservice" {
title = "TF Provider Test BP0"
icon = "Terraform"
identifier = "%s"
properties {
title = "text"
identifier = "text"
type = "string"
format = "url"
spec = "embedded-url"
}
}
`, identifier)
resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"port-labs": Provider(),
},
Steps: []resource.TestStep{
{
Config: testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.spec", "embedded-url"),
),
},
},
})
}

func TestAccBlueprintWithChangelogDestination(t *testing.T) {
identifier := genID()
var testAccActionConfigCreate = fmt.Sprintf(`
Expand Down

0 comments on commit e5c2d5d

Please sign in to comment.