Skip to content

Commit 85de69c

Browse files
Declare CRUD actions
1 parent 0c7fbf9 commit 85de69c

File tree

3 files changed

+224
-7
lines changed

3 files changed

+224
-7
lines changed

docs/resources/custom_resource.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ Custom Resource resource
1717

1818
### Required
1919

20+
- `create` (Attributes) Resource's create action (see [below for nested schema](#nestedatt--create))
21+
- `delete` (Attributes) Resource's delete action (see [below for nested schema](#nestedatt--delete))
2022
- `description` (String) Describe the resource in few sentences
2123
- `display_name` (String) A friendly name
2224
- `project_id` (String) Project ID
25+
- `read` (Attributes) Resource's read action (see [below for nested schema](#nestedatt--read))
2326
- `resource_type` (String) Define the type (must be unique, e.g. Custom.DB.PostgreSQL)
27+
- `update` (Attributes) Resource's update action (see [below for nested schema](#nestedatt--update))
2428

2529
### Optional
2630

@@ -31,3 +35,62 @@ Custom Resource resource
3135

3236
- `id` (String) Resource identifier
3337
- `org_id` (String) Organisation ID
38+
39+
<a id="nestedatt--create"></a>
40+
### Nested Schema for `create`
41+
42+
Required:
43+
44+
- `id` (String) Runnable ID
45+
- `name` (String) Runnable name
46+
- `project_id` (String) Runnable's project ID
47+
- `type` (String) Runnable type, either abx.action or vro.workflow
48+
49+
Optional:
50+
51+
- `input_parameters` (List of String) TODO
52+
53+
54+
<a id="nestedatt--delete"></a>
55+
### Nested Schema for `delete`
56+
57+
Required:
58+
59+
- `id` (String) Runnable ID
60+
- `name` (String) Runnable name
61+
- `project_id` (String) Runnable's project ID
62+
- `type` (String) Runnable type, either abx.action or vro.workflow
63+
64+
Optional:
65+
66+
- `input_parameters` (List of String) TODO
67+
68+
69+
<a id="nestedatt--read"></a>
70+
### Nested Schema for `read`
71+
72+
Required:
73+
74+
- `id` (String) Runnable ID
75+
- `name` (String) Runnable name
76+
- `project_id` (String) Runnable's project ID
77+
- `type` (String) Runnable type, either abx.action or vro.workflow
78+
79+
Optional:
80+
81+
- `input_parameters` (List of String) TODO
82+
83+
84+
<a id="nestedatt--update"></a>
85+
### Nested Schema for `update`
86+
87+
Required:
88+
89+
- `id` (String) Runnable ID
90+
- `name` (String) Runnable name
91+
- `project_id` (String) Runnable's project ID
92+
- `type` (String) Runnable type, either abx.action or vro.workflow
93+
94+
Optional:
95+
96+
- `input_parameters` (List of String) TODO

internal/provider/custom_resource_resource.go

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import (
88
"fmt"
99

1010
"github.com/go-resty/resty/v2"
11-
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
11+
"github.com/hashicorp/terraform-plugin-framework/attr"
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1515
//"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
1616
//"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
17-
//"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
17+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
18+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
1819
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1920
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
2021
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2122
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
22-
//"github.com/hashicorp/terraform-plugin-framework/types"
23+
"github.com/hashicorp/terraform-plugin-framework/types"
2324
"github.com/hashicorp/terraform-plugin-log/tflog"
2425
)
2526

@@ -88,10 +89,134 @@ func (self *CustomResourceResource) Schema(
8889
},
8990
},
9091
// FIXME "properties": {},
91-
// FIXME "create": {},
92-
// FIXME "read": {},
93-
// FIXME "update": {},
94-
// FIXME "delete": {},
92+
"create": schema.SingleNestedAttribute{
93+
MarkdownDescription: "Resource's create action",
94+
Attributes: map[string]schema.Attribute{
95+
"id": schema.StringAttribute{
96+
MarkdownDescription: "Runnable ID",
97+
Required: true,
98+
},
99+
"name": schema.StringAttribute{
100+
MarkdownDescription: "Runnable name",
101+
Required: true,
102+
},
103+
"type": schema.StringAttribute{
104+
MarkdownDescription: "Runnable type, either abx.action or vro.workflow",
105+
Required: true,
106+
Validators: []validator.String{
107+
stringvalidator.OneOf([]string{"abx.action", "vro.workflow"}...),
108+
},
109+
},
110+
"project_id": schema.StringAttribute{
111+
MarkdownDescription: "Runnable's project ID",
112+
Required: true,
113+
},
114+
"input_parameters": schema.ListAttribute{
115+
MarkdownDescription: "TODO",
116+
ElementType: types.StringType,
117+
Computed: true,
118+
Optional: true,
119+
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
120+
},
121+
},
122+
Required: true,
123+
},
124+
"read": schema.SingleNestedAttribute{
125+
MarkdownDescription: "Resource's read action",
126+
Attributes: map[string]schema.Attribute{
127+
"id": schema.StringAttribute{
128+
MarkdownDescription: "Runnable ID",
129+
Required: true,
130+
},
131+
"name": schema.StringAttribute{
132+
MarkdownDescription: "Runnable name",
133+
Required: true,
134+
},
135+
"type": schema.StringAttribute{
136+
MarkdownDescription: "Runnable type, either abx.action or vro.workflow",
137+
Required: true,
138+
Validators: []validator.String{
139+
stringvalidator.OneOf([]string{"abx.action", "vro.workflow"}...),
140+
},
141+
},
142+
"project_id": schema.StringAttribute{
143+
MarkdownDescription: "Runnable's project ID",
144+
Required: true,
145+
},
146+
"input_parameters": schema.ListAttribute{
147+
MarkdownDescription: "TODO",
148+
ElementType: types.StringType,
149+
Computed: true,
150+
Optional: true,
151+
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
152+
},
153+
},
154+
Required: true,
155+
},
156+
"update": schema.SingleNestedAttribute{
157+
MarkdownDescription: "Resource's update action",
158+
Attributes: map[string]schema.Attribute{
159+
"id": schema.StringAttribute{
160+
MarkdownDescription: "Runnable ID",
161+
Required: true,
162+
},
163+
"name": schema.StringAttribute{
164+
MarkdownDescription: "Runnable name",
165+
Required: true,
166+
},
167+
"type": schema.StringAttribute{
168+
MarkdownDescription: "Runnable type, either abx.action or vro.workflow",
169+
Required: true,
170+
Validators: []validator.String{
171+
stringvalidator.OneOf([]string{"abx.action", "vro.workflow"}...),
172+
},
173+
},
174+
"project_id": schema.StringAttribute{
175+
MarkdownDescription: "Runnable's project ID",
176+
Required: true,
177+
},
178+
"input_parameters": schema.ListAttribute{
179+
MarkdownDescription: "TODO",
180+
ElementType: types.StringType,
181+
Computed: true,
182+
Optional: true,
183+
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
184+
},
185+
},
186+
Required: true,
187+
},
188+
"delete": schema.SingleNestedAttribute{
189+
MarkdownDescription: "Resource's delete action",
190+
Attributes: map[string]schema.Attribute{
191+
"id": schema.StringAttribute{
192+
MarkdownDescription: "Runnable ID",
193+
Required: true,
194+
},
195+
"name": schema.StringAttribute{
196+
MarkdownDescription: "Runnable name",
197+
Required: true,
198+
},
199+
"type": schema.StringAttribute{
200+
MarkdownDescription: "Runnable type, either abx.action or vro.workflow",
201+
Required: true,
202+
Validators: []validator.String{
203+
stringvalidator.OneOf([]string{"abx.action", "vro.workflow"}...),
204+
},
205+
},
206+
"project_id": schema.StringAttribute{
207+
MarkdownDescription: "Runnable's project ID",
208+
Required: true,
209+
},
210+
"input_parameters": schema.ListAttribute{
211+
MarkdownDescription: "TODO",
212+
ElementType: types.StringType,
213+
Computed: true,
214+
Optional: true,
215+
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
216+
},
217+
},
218+
Required: true,
219+
},
95220
// FIXME "additional_actions": {},
96221
"project_id": schema.StringAttribute{
97222
MarkdownDescription: "Project ID",

internal/provider/custom_resource_resource_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,35 @@ resource "aria_custom_resource" "test" {
100100
schema_type = "ABX_USER_DEFINED"
101101
status = "DRAFT"
102102
project_id = var.test_project_id
103+
104+
// TODO Create a function to simplify this
105+
create = {
106+
id = aria_abx_action.create.id
107+
name = aria_abx_action.create.name
108+
project_id = aria_abx_action.create.project_id
109+
type = "abx.action"
110+
}
111+
112+
read = {
113+
id = aria_abx_action.read.id
114+
name = aria_abx_action.read.name
115+
project_id = aria_abx_action.read.project_id
116+
type = "abx.action"
117+
}
118+
119+
update = {
120+
id = aria_abx_action.update.id
121+
name = aria_abx_action.update.name
122+
project_id = aria_abx_action.update.project_id
123+
type = "abx.action"
124+
}
125+
126+
delete = {
127+
id = aria_abx_action.delete.id
128+
name = aria_abx_action.delete.name
129+
project_id = aria_abx_action.delete.project_id
130+
type = "abx.action"
131+
}
103132
}
104133
`,
105134
/*Check: resource.ComposeAggregateTestCheckFunc(

0 commit comments

Comments
 (0)