Skip to content

Commit 6fb67d8

Browse files
committed
Generate datasources based on OpenAPI specification
This is an experiment to see whether generating the provider based on the OpenAPI specification at https://github.com/hashicorp/boundary/blob/main/internal/gen/controller.swagger.json could work. The schema is converted from the definitions given in the document to to map[string]*schema.Schema, with two special cases: - when there is an object in an object, I convert it to a one element list as terraform-plugin-sdk v2 does not know how to express this, - when there is an opaque attribute (`map[string]interface{}`), I skip it completely as terraform-plugin-sdk does not expose `DynamicPseudoType` that would make it possible to express this attribute in native Terraform, the workaround I use in the Consul provider is to use `schema.TypeString` and `jsonencode()` but it is not ideal. Since I only worked on the datasources here I chose to skip those attributes for now. Once the schema is converted, we create the `ReadContext` function that is needed for the datasource. As it can be a bit tricky to use the Go client for each service, I chose to use directly the global *api.Client and to manually add the query params and get the raw response. While it would not be recommended for an external project to use the client this way, it fits nicely here and keep the code simple. Finally the result is written to the state, looking at the schema we generated previously to convert it. The tests are written manually so the developper can make sure that everything is working as expected even thought the code was generated and not written manually. While the conversion of the schema could be made at runtime and only one `ReadContext` function is actually needed, I find generating the code make it quite easy to review and should make it easier for contributors already accustomed to writing Terraform providers to look for errors or fork the provider for their needs. While I only worked on datasources returning lists of elements for now, I think the same approach could be used to generate datasources returning a single element and ultimately resources. This would make it very easy to keep the Terraform provider in sync with new Boundary versions, especially as the OpenAPI spec is created from the Protobuf files and the CLI is already generated on a similar principle. The code in generate_datasource.go is not very nice, but it does get the job done. I may spin it off in its own project in the future to add more feature to it. Closes #99
1 parent a24f9e1 commit 6fb67d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5404
-0
lines changed

docs/data-sources/accounts.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_accounts Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Accounts in a specific Auth Method.
7+
---
8+
9+
# boundary_accounts (Data Source)
10+
11+
Lists all Accounts in a specific Auth Method.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **auth_method_id** (String)
21+
- **filter** (String)
22+
- **id** (String) The ID of this resource.
23+
24+
### Read-Only
25+
26+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
27+
28+
<a id="nestedatt--items"></a>
29+
### Nested Schema for `items`
30+
31+
Read-Only:
32+
33+
- **auth_method_id** (String)
34+
- **authorized_actions** (List of String)
35+
- **created_time** (String)
36+
- **description** (String)
37+
- **id** (String)
38+
- **managed_group_ids** (List of String)
39+
- **name** (String)
40+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
41+
- **type** (String)
42+
- **updated_time** (String)
43+
- **version** (Number)
44+
45+
<a id="nestedobjatt--items--scope"></a>
46+
### Nested Schema for `items.scope`
47+
48+
Read-Only:
49+
50+
- **description** (String)
51+
- **id** (String)
52+
- **name** (String)
53+
- **parent_scope_id** (String)
54+
- **type** (String)
55+
56+

docs/data-sources/auth_methods.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_auth_methods Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Auth Methods.
7+
---
8+
9+
# boundary_auth_methods (Data Source)
10+
11+
Lists all Auth Methods.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **filter** (String)
21+
- **id** (String) The ID of this resource.
22+
- **recursive** (Boolean)
23+
- **scope_id** (String)
24+
25+
### Read-Only
26+
27+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
28+
29+
<a id="nestedatt--items"></a>
30+
### Nested Schema for `items`
31+
32+
Read-Only:
33+
34+
- **authorized_actions** (List of String)
35+
- **created_time** (String)
36+
- **description** (String)
37+
- **id** (String)
38+
- **is_primary** (Boolean)
39+
- **name** (String)
40+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
41+
- **scope_id** (String)
42+
- **type** (String)
43+
- **updated_time** (String)
44+
- **version** (Number)
45+
46+
<a id="nestedobjatt--items--scope"></a>
47+
### Nested Schema for `items.scope`
48+
49+
Read-Only:
50+
51+
- **description** (String)
52+
- **id** (String)
53+
- **name** (String)
54+
- **parent_scope_id** (String)
55+
- **type** (String)
56+
57+

docs/data-sources/auth_tokens.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_auth_tokens Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Auth Tokens.
7+
---
8+
9+
# boundary_auth_tokens (Data Source)
10+
11+
Lists all Auth Tokens.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **filter** (String)
21+
- **id** (String) The ID of this resource.
22+
- **recursive** (Boolean)
23+
- **scope_id** (String)
24+
25+
### Read-Only
26+
27+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
28+
29+
<a id="nestedatt--items"></a>
30+
### Nested Schema for `items`
31+
32+
Read-Only:
33+
34+
- **account_id** (String)
35+
- **approximate_last_used_time** (String)
36+
- **auth_method_id** (String)
37+
- **authorized_actions** (List of String)
38+
- **created_time** (String)
39+
- **expiration_time** (String)
40+
- **id** (String)
41+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
42+
- **scope_id** (String)
43+
- **token** (String)
44+
- **updated_time** (String)
45+
- **user_id** (String)
46+
47+
<a id="nestedobjatt--items--scope"></a>
48+
### Nested Schema for `items.scope`
49+
50+
Read-Only:
51+
52+
- **description** (String)
53+
- **id** (String)
54+
- **name** (String)
55+
- **parent_scope_id** (String)
56+
- **type** (String)
57+
58+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_credential_libraries Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Credential Library.
7+
---
8+
9+
# boundary_credential_libraries (Data Source)
10+
11+
Lists all Credential Library.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **credential_store_id** (String)
21+
- **filter** (String)
22+
- **id** (String) The ID of this resource.
23+
24+
### Read-Only
25+
26+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
27+
28+
<a id="nestedatt--items"></a>
29+
### Nested Schema for `items`
30+
31+
Read-Only:
32+
33+
- **authorized_actions** (List of String)
34+
- **created_time** (String)
35+
- **credential_store_id** (String)
36+
- **description** (String)
37+
- **id** (String)
38+
- **name** (String)
39+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
40+
- **type** (String)
41+
- **updated_time** (String)
42+
- **version** (Number)
43+
44+
<a id="nestedobjatt--items--scope"></a>
45+
### Nested Schema for `items.scope`
46+
47+
Read-Only:
48+
49+
- **description** (String)
50+
- **id** (String)
51+
- **name** (String)
52+
- **parent_scope_id** (String)
53+
- **type** (String)
54+
55+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_credential_stores Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Credential Stores.
7+
---
8+
9+
# boundary_credential_stores (Data Source)
10+
11+
Lists all Credential Stores.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **filter** (String)
21+
- **id** (String) The ID of this resource.
22+
- **recursive** (Boolean)
23+
- **scope_id** (String)
24+
25+
### Read-Only
26+
27+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
28+
29+
<a id="nestedatt--items"></a>
30+
### Nested Schema for `items`
31+
32+
Read-Only:
33+
34+
- **authorized_actions** (List of String)
35+
- **created_time** (String)
36+
- **description** (String)
37+
- **id** (String)
38+
- **name** (String)
39+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
40+
- **scope_id** (String)
41+
- **type** (String)
42+
- **updated_time** (String)
43+
- **version** (Number)
44+
45+
<a id="nestedobjatt--items--scope"></a>
46+
### Nested Schema for `items.scope`
47+
48+
Read-Only:
49+
50+
- **description** (String)
51+
- **id** (String)
52+
- **name** (String)
53+
- **parent_scope_id** (String)
54+
- **type** (String)
55+
56+

docs/data-sources/groups.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "boundary_groups Data Source - terraform-provider-boundary"
4+
subcategory: ""
5+
description: |-
6+
Lists all Groups.
7+
---
8+
9+
# boundary_groups (Data Source)
10+
11+
Lists all Groups.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- **filter** (String)
21+
- **id** (String) The ID of this resource.
22+
- **recursive** (Boolean)
23+
- **scope_id** (String)
24+
25+
### Read-Only
26+
27+
- **items** (List of Object) (see [below for nested schema](#nestedatt--items))
28+
29+
<a id="nestedatt--items"></a>
30+
### Nested Schema for `items`
31+
32+
Read-Only:
33+
34+
- **authorized_actions** (List of String)
35+
- **created_time** (String)
36+
- **description** (String)
37+
- **id** (String)
38+
- **member_ids** (List of String)
39+
- **members** (List of Object) (see [below for nested schema](#nestedobjatt--items--members))
40+
- **name** (String)
41+
- **scope** (List of Object) (see [below for nested schema](#nestedobjatt--items--scope))
42+
- **scope_id** (String)
43+
- **updated_time** (String)
44+
- **version** (Number)
45+
46+
<a id="nestedobjatt--items--members"></a>
47+
### Nested Schema for `items.members`
48+
49+
Read-Only:
50+
51+
- **id** (String)
52+
- **scope_id** (String)
53+
54+
55+
<a id="nestedobjatt--items--scope"></a>
56+
### Nested Schema for `items.scope`
57+
58+
Read-Only:
59+
60+
- **description** (String)
61+
- **id** (String)
62+
- **name** (String)
63+
- **parent_scope_id** (String)
64+
- **type** (String)
65+
66+

0 commit comments

Comments
 (0)