Skip to content

Commit

Permalink
Introspection links (#77)
Browse files Browse the repository at this point in the history
* add links attribute to introspection resource

* update example and doc

* fix typos, add links variable to example
  • Loading branch information
amiros89 authored Oct 14, 2024
1 parent 2017097 commit 15ead78
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
27 changes: 24 additions & 3 deletions docs/resources/introspection_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@ provider "torque" {
token = "111111111111"
}
resource "torque_introspection_resource" "example" {
display_name = "resource_name"
image = "resource_image"
introspection_data = { "data1" : "value1" }
display_name = "resource_name"
image = "resource_image"
introspection_data = {
"data1" : "value1"
"data2" : "value2"
"data3" : "value3"
}
links = [{
"icon" : "connect",
"href" : "https://example1.com"
},
{
"icon" : "connect",
"href" : "https://example2.com"
}]
}
```

Expand All @@ -44,3 +56,12 @@ resource "torque_introspection_resource" "example" {

- `image` (String) Example configurable attribute with default value
- `introspection_data` (Map of String) Resource attribute to show in resource card. Note that only the first 4 attributes will be presented
- `links` (Attributes List) List of links that will be available as buttons in the resource introspection card. (see [below for nested schema](#nestedatt--links))

<a id="nestedatt--links"></a>
### Nested Schema for `links`

Required:

- `href` (String) Button's link
- `icon` (String) Button's icon
18 changes: 15 additions & 3 deletions examples/resources/torque_introspection_resource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ provider "torque" {
token = "111111111111"
}
resource "torque_introspection_resource" "example" {
display_name = "resource_name"
image = "resource_image"
introspection_data = { "data1" : "value1" }
display_name = "resource_name"
image = "resource_image"
introspection_data = {
"data1" : "value1"
"data2" : "value2"
"data3" : "value3"
}
links = [{
"icon" : "connect",
"href" : "https://example1.com"
},
{
"icon" : "connect",
"href" : "https://example2.com"
}]
}
15 changes: 12 additions & 3 deletions examples/resources/torque_introspection_resource/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ variable "torque_token" {

variable "resource_name" {
type = string
description = "Resource name to be presented in the resouce catalog card"
description = "Resource name to be presented in the resource catalog card"
}

variable "resource_image" {
type = string
default = "https://portal.qtorque.io/static/media/networking.dc1b7fb73182de0136d059a1eb00af4f.svg"
description = "Resource image to be presented in the resouce catalog card. Image should be uploaded to Torque prior to usage."
description = "Resource image to be presented in the resource catalog card. Image should be uploaded to Torque prior to usage."
}

variable "resource_data" {
description = "Resource data to be oresented in the resouce catalog card"
description = "Resource data to be presented in the resource catalog card"
type = map(string)
}

variable "links" {
description = "List of links that will be available as buttons in the resource introspection card."
type = list(object({
icon = string, # Button's icon
href = string # Button's link
}))
default = []
}
18 changes: 18 additions & 0 deletions internal/provider/resources/introspection_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type TorqueIntrospectionResourceModel struct {
DisplayName types.String `tfsdk:"display_name"`
Image types.String `tfsdk:"image"`
IntrospectionData types.Map `tfsdk:"introspection_data"`
Links types.List `tfsdk:"links"`
}

func (r *TorqueIntrospectionResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
Expand Down Expand Up @@ -54,6 +55,23 @@ func (r *TorqueIntrospectionResource) Schema(ctx context.Context, req resource.S
Optional: true,
Computed: false,
},
"links": schema.ListNestedAttribute{
Description: "List of links that will be available as buttons in the resource introspection card.",
Required: false,
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"icon": schema.StringAttribute{
Description: "Button's icon",
Required: true,
},
"href": schema.StringAttribute{
Description: "Button's link",
Required: true,
},
},
},
},
},
}
}
Expand Down

0 comments on commit 15ead78

Please sign in to comment.