Skip to content

Commit 63c193b

Browse files
authored
Treat data source and resource response properties as computed (#44)
Reference: #36 In both cases, the read response properties are lower precedence and therefore any new ones should not be configurable.
1 parent 90acf3b commit 63c193b

File tree

9 files changed

+2621
-3468
lines changed

9 files changed

+2621
-3468
lines changed

DESIGN.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ If not required, then the field will be mapped as [Optional](https://developer.h
152152
#### Resources
153153
For resources, all fields, in the `Create` operation `requestBody` OAS schema, marked as [required](https://json-schema.org/understanding-json-schema/reference/object.html#required-properties) will be mapped as a [Required](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#required) attribute. If [default](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-default) is also specified, it will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed) and [Optional](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#optional) instead.
154154

155-
If not required, or if the field is in a different schema than the `Create` operation `requestbody`, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed) and [Optional](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#optional).
155+
If not required, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed) and [Optional](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#optional).
156+
157+
If the field is in a different schema than the `Create` operation `requestbody`, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed).
156158

157159
#### Data Sources
158160
For data sources, all fields, in the `Read` operation `parameters` OAS schema, marked as [required](https://json-schema.org/understanding-json-schema/reference/object.html#required-properties) will be mapped as a [Required](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#required) attribute.
159161

160-
If not required, or if the field is in a different schema than the `Read` operation `parameters`, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed) and [Optional](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#optional).
162+
If not required, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed) and [Optional](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#optional).
163+
164+
If the field is in a different schema than the `Read` operation `parameters`, then the field will be mapped as [Computed](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#computed).
161165

162166
### Other field mapping
163167

internal/cmd/testdata/edgecase/generated_framework_ir.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "map_prop",
99
"map": {
10-
"computed_optional_required": "computed_optional",
10+
"computed_optional_required": "computed",
1111
"element_type": {
1212
"float64": {}
1313
},
@@ -17,20 +17,20 @@
1717
{
1818
"name": "mapnested_prop",
1919
"map_nested": {
20-
"computed_optional_required": "computed_optional",
20+
"computed_optional_required": "computed",
2121
"nested_object": {
2222
"attributes": [
2323
{
2424
"name": "bool_prop",
2525
"bool": {
26-
"computed_optional_required": "computed_optional",
26+
"computed_optional_required": "computed",
2727
"description": "Bool inside a map!"
2828
}
2929
},
3030
{
3131
"name": "string_prop",
3232
"string": {
33-
"computed_optional_required": "computed_optional",
33+
"computed_optional_required": "computed",
3434
"description": "String inside a map!"
3535
}
3636
}
@@ -49,7 +49,7 @@
4949
{
5050
"name": "double_nested_list",
5151
"list": {
52-
"computed_optional_required": "computed_optional",
52+
"computed_optional_required": "computed",
5353
"element_type": {
5454
"list": {
5555
"element_type": {
@@ -63,7 +63,7 @@
6363
{
6464
"name": "double_nested_map",
6565
"list": {
66-
"computed_optional_required": "computed_optional",
66+
"computed_optional_required": "computed",
6767
"element_type": {
6868
"map": {
6969
"element_type": {
@@ -77,7 +77,7 @@
7777
{
7878
"name": "double_nested_set",
7979
"set": {
80-
"computed_optional_required": "computed_optional",
80+
"computed_optional_required": "computed",
8181
"element_type": {
8282
"set": {
8383
"element_type": {
@@ -91,7 +91,7 @@
9191
{
9292
"name": "triple_nested_map",
9393
"list": {
94-
"computed_optional_required": "computed_optional",
94+
"computed_optional_required": "computed",
9595
"element_type": {
9696
"set": {
9797
"element_type": {
@@ -127,7 +127,7 @@
127127
{
128128
"name": "set_prop",
129129
"set": {
130-
"computed_optional_required": "computed_optional",
130+
"computed_optional_required": "computed",
131131
"element_type": {
132132
"string": {}
133133
},
@@ -137,20 +137,20 @@
137137
{
138138
"name": "setnested_prop",
139139
"set_nested": {
140-
"computed_optional_required": "computed_optional",
140+
"computed_optional_required": "computed",
141141
"nested_object": {
142142
"attributes": [
143143
{
144144
"name": "bool_prop",
145145
"bool": {
146-
"computed_optional_required": "computed_optional",
146+
"computed_optional_required": "computed",
147147
"description": "Bool inside a set!"
148148
}
149149
},
150150
{
151151
"name": "string_prop",
152152
"string": {
153-
"computed_optional_required": "computed_optional",
153+
"computed_optional_required": "computed",
154154
"description": "String inside a set!"
155155
}
156156
}

0 commit comments

Comments
 (0)