Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ListNestedAttributesOptions, SetNestedAttributesOptions and MapNestedAttributesOptions types, as they were empty (no fields) and unused #349

Merged
merged 6 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/349.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
tfsdk: Removed `ListNestedAttributesOptions`, `SetNestedAttributesOptions` and `MapNestedAttributesOptions` types, as they were empty (no fields) and unused.
```

```release-note:breaking-change
tfsdk: `ListNestedAttributes`, `SetNestedAttributes` and `MapNestedAttributes` functions lost the second argument `opts`, as it was unused.
```
7 changes: 3 additions & 4 deletions docs/design/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func (t exampleThingResourceType) GetSchema(_ context.Context) (Schema, diag.Dia
Required: true,
Type: types.StringType,
},
}, ListNestedAttributesOptions{}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the design documentation with the original context/decision here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with it, even though I can foresee someone coming here, reading the doc, and getting confused.

But we already discussed this, so 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

}),
},
},
}, nil
Expand Down Expand Up @@ -572,7 +572,7 @@ For example:
Type: types.StringType,
Required: true,
},
}, ListNestedBlocksOptions{}),
}),
},
```

Expand All @@ -591,15 +591,14 @@ For example:
Type: types.StringType,
Required: true,
},
}, ListNestedBlocksOptions{}),
}),
},
```

This allows the framework to differentiate between block and nested attributes by fields. This would allow for a potential block to attribute migration path of:

- Rename `Blocks` field identifier to `Attributes`
- Rename `ListNestedBlocks`/`SetNestedBlocks` call expressions to `ListNestedAttributes`/`SetNestedAttributes`
- Rename `ListNestedBlocksOptions`/`SetNestedBlocksOptions` declarations to `ListNestedAttributesOptions`/`SetNestedBlocksOptions`
- Either default to adding `Required`/`Optional`/`Computed` field identifier(s) and `true` value(s) or its a manual step for provider developers

However, this does introduce the possibility of creating a schema that passes compilation checks, but is not a valid schema. For example, `Attributes` that contains `Blocks` which is not possible in the protocol. At best the framework could introduce unit testable schema validation logic to catch this situation, or worse case, it would result in runtime errors for practitioners that get reported back to provider developers.
Expand Down
12 changes: 6 additions & 6 deletions internal/fwserver/attribute_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestAttributeValidate(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestAttributeValidate(t *testing.T) {
testErrorAttributeValidator{},
},
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestAttributeValidate(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -606,7 +606,7 @@ func TestAttributeValidate(t *testing.T) {
testErrorAttributeValidator{},
},
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -667,7 +667,7 @@ func TestAttributeValidate(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -727,7 +727,7 @@ func TestAttributeValidate(t *testing.T) {
testErrorAttributeValidator{},
},
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down
6 changes: 3 additions & 3 deletions internal/proto6server/serve_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (t *testServeProvider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
Type: types.NumberType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Optional: true,
},
"map-nested-attributes": {
Expand All @@ -244,7 +244,7 @@ func (t *testServeProvider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
Type: types.NumberType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Optional: true,
},
"set-nested-attributes": {
Expand All @@ -258,7 +258,7 @@ func (t *testServeProvider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
Type: types.NumberType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Optional: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/proto6server/serve_resource_three_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (rt testServeResourceTypeThree) GetSchema(_ context.Context) (tfsdk.Schema,
Optional: true,
Type: types.StringType,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
},
},
}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/proto6server/serve_resource_two_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (rt testServeResourceTypeTwo) GetSchema(_ context.Context) (tfsdk.Schema, d
Required: true,
Type: types.BoolType,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
},
},
Blocks: map[string]tfsdk.Block{
Expand Down
24 changes: 12 additions & 12 deletions internal/toproto6/getproviderschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -523,7 +523,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -669,7 +669,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -1288,7 +1288,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -1399,7 +1399,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -1533,7 +1533,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -2126,7 +2126,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -2237,7 +2237,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -2371,7 +2371,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -3044,7 +3044,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -3164,7 +3164,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down Expand Up @@ -3310,7 +3310,7 @@ func TestGetProviderSchemaResponse(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Required: true,
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/toproto6/schema_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestSchemaAttribute(t *testing.T) {
Computed: true,
Sensitive: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Optional: true,
},
path: tftypes.NewAttributePath(),
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestSchemaAttribute(t *testing.T) {
Computed: true,
Sensitive: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Optional: true,
},
path: tftypes.NewAttributePath(),
Expand Down
6 changes: 3 additions & 3 deletions internal/toproto6/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestSchema(t *testing.T) {
Computed: true,
Optional: true,
},
}, tfsdk.ListNestedAttributesOptions{}),
}),
Optional: true,
},
"set": {
Expand All @@ -201,7 +201,7 @@ func TestSchema(t *testing.T) {
Computed: true,
Optional: true,
},
}, tfsdk.SetNestedAttributesOptions{}),
}),
Computed: true,
},
"map": {
Expand All @@ -223,7 +223,7 @@ func TestSchema(t *testing.T) {
Computed: true,
Optional: true,
},
}, tfsdk.MapNestedAttributesOptions{}),
}),
Optional: true,
Computed: true,
},
Expand Down
14 changes: 7 additions & 7 deletions tfsdk/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, ListNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
}),
Optional: true,
},
}, ListNestedAttributesOptions{}),
}),
Optional: true,
},
"other": {
Expand Down Expand Up @@ -631,7 +631,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, ListNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down Expand Up @@ -925,7 +925,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, MapNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down Expand Up @@ -977,7 +977,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, MapNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, SetNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func TestConfigGetAttributeValue(t *testing.T) {
Type: types.StringType,
Required: true,
},
}, SetNestedAttributesOptions{}),
}),
Required: true,
},
"other": {
Expand Down
Loading