Skip to content

Commit 41f8aaf

Browse files
authored
Add support for action schemas (#166)
1 parent 54f28af commit 41f8aaf

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

schemas.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ type ProviderSchema struct {
9090
// The schemas for any ephemeral resources in this provider.
9191
EphemeralResourceSchemas map[string]*Schema `json:"ephemeral_resource_schemas,omitempty"`
9292

93+
// The schemas for any actions in this provider.
94+
ActionSchemas map[string]*ActionSchema `json:"action_schemas,omitempty"`
95+
9396
// The definitions for any functions in this provider.
9497
Functions map[string]*FunctionSignature `json:"functions,omitempty"`
9598

@@ -328,3 +331,20 @@ type IdentityAttribute struct {
328331
// provider
329332
OptionalForImport bool `json:"optional_for_import,omitempty"`
330333
}
334+
335+
// ActionSchema is the JSON representation of an action schema
336+
type ActionSchema struct {
337+
// The version of the action schema.
338+
Version uint64 `json:"version"`
339+
340+
// The root-level block of configuration values.
341+
Block *SchemaBlock `json:"block,omitempty"`
342+
343+
// Additional information about the action, only populated if the action is unlinked.
344+
Unlinked *UnlinkedSchemaType `json:"unlinked,omitempty"`
345+
}
346+
347+
// UnlinkedSchemaType contains any additional information about an unlinked action.
348+
type UnlinkedSchemaType struct {
349+
// Currently there is no additional information for unlinked action schema types
350+
}

schemas_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"encoding/json"
88
"os"
99
"testing"
10+
11+
"github.com/google/go-cmp/cmp"
12+
"github.com/google/go-cmp/cmp/cmpopts"
13+
"github.com/zclconf/go-cty/cty"
1014
)
1115

1216
func TestProviderSchemasValidate(t *testing.T) {
@@ -75,3 +79,49 @@ func TestProviderSchemas_writeOnlyAttribute(t *testing.T) {
7579
t.Fatal("expected terraform_example.foo to not be marked as write-only")
7680
}
7781
}
82+
83+
func TestProviderSchemas_unlinked_action(t *testing.T) {
84+
expectedAction := &ActionSchema{
85+
Block: &SchemaBlock{
86+
DescriptionKind: SchemaDescriptionKindPlain,
87+
Attributes: map[string]*SchemaAttribute{
88+
"program": {
89+
AttributeType: cty.List(cty.String),
90+
Description: "A list of strings, whose first element is the program to run and whose subsequent elements are optional command line arguments to the program.",
91+
DescriptionKind: SchemaDescriptionKindPlain,
92+
Required: true,
93+
},
94+
"query": {
95+
AttributeType: cty.Map(cty.String),
96+
Description: "A map of string values to pass to the external program as the query arguments. If not supplied, the program will receive an empty object as its input.",
97+
DescriptionKind: SchemaDescriptionKindPlain,
98+
Optional: true,
99+
},
100+
"working_dir": {
101+
AttributeType: cty.String,
102+
Description: "Working directory of the program. If not supplied, the program will run in the current directory.",
103+
DescriptionKind: SchemaDescriptionKindPlain,
104+
Optional: true,
105+
},
106+
},
107+
},
108+
Unlinked: &UnlinkedSchemaType{},
109+
}
110+
111+
f, err := os.Open("testdata/actions/unlinked_schemas.json")
112+
if err != nil {
113+
t.Fatal(err)
114+
}
115+
defer f.Close()
116+
117+
var schemas *ProviderSchemas
118+
if err := json.NewDecoder(f).Decode(&schemas); err != nil {
119+
t.Fatal(err)
120+
}
121+
122+
gotAction := schemas.Schemas["registry.terraform.io/hashicorp/external"].ActionSchemas["external"]
123+
if diff := cmp.Diff(gotAction, expectedAction, cmpopts.EquateComparable(cty.Type{})); diff != "" {
124+
t.Errorf("Unexpected diff (+wanted, -got): %s", diff)
125+
return
126+
}
127+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"format_version":"1.0","provider_schemas":{"registry.terraform.io/hashicorp/external":{"provider":{"version":0,"block":{"description_kind":"plain"}},"action_schemas":{"external":{"block":{"attributes":{"program":{"type":["list","string"],"description":"A list of strings, whose first element is the program to run and whose subsequent elements are optional command line arguments to the program.","description_kind":"plain","required":true},"query":{"type":["map","string"],"description":"A map of string values to pass to the external program as the query arguments. If not supplied, the program will receive an empty object as its input.","description_kind":"plain","optional":true},"working_dir":{"type":"string","description":"Working directory of the program. If not supplied, the program will run in the current directory.","description_kind":"plain","optional":true}},"description_kind":"plain"},"unlinked":{}}}}}}

0 commit comments

Comments
 (0)