Exclude nested config block from list resource schemas (#37495)

* Exclude nested config block from list resource schemas

* Guard action schemas by experimental flag

* Fix tests
pull/37500/head
Daniel Banck 6 months ago committed by GitHub
parent f14baf178d
commit 2463f864dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8544,7 +8544,7 @@ func TestResourceChange_actions(t *testing.T) {
},
},
}
jsonschemas := jsonprovider.MarshalForRenderer(fullSchema, false)
jsonschemas := jsonprovider.MarshalForRenderer(fullSchema, true)
diffs := precomputeDiffs(Plan{
ResourceChanges: []jsonplan.ResourceChange{defaultResourceChange},
ActionInvocations: tc.actionInvocations,

@ -68,11 +68,23 @@ func marshalProvider(tps providers.ProviderSchema, includeExperimentalSchemas bo
EphemeralResourceSchemas: marshalSchemas(tps.EphemeralResourceTypes),
Functions: jsonfunction.MarshalProviderFunctions(tps.Functions),
ResourceIdentitySchemas: marshalIdentitySchemas(tps.ResourceTypes),
ActionSchemas: marshalActionSchemas(tps.Actions),
}
if includeExperimentalSchemas {
p.ListResourceSchemas = marshalSchemas(tps.ListResourceTypes)
// List resource schemas are nested under a "config" block, so we need to
// extract that block to get the actual provider schema for the list resource.
// When getting the provider schemas, Terraform adds this extra level to
// better match the actual configuration structure.
listSchemas := make(map[string]providers.Schema, len(tps.ListResourceTypes))
for k, v := range tps.ListResourceTypes {
listSchemas[k] = providers.Schema{
Body: &v.Body.BlockTypes["config"].Block,
Version: v.Version,
}
}
p.ListResourceSchemas = marshalSchemas(listSchemas)
p.ActionSchemas = marshalActionSchemas(tps.Actions)
}
return p

@ -33,7 +33,6 @@ func TestMarshalProvider(t *testing.T) {
DataSourceSchemas: map[string]*Schema{},
EphemeralResourceSchemas: map[string]*Schema{},
ResourceIdentitySchemas: map[string]*IdentitySchema{},
ActionSchemas: map[string]*ActionSchema{},
},
},
{
@ -213,7 +212,6 @@ func TestMarshalProvider(t *testing.T) {
},
},
ResourceIdentitySchemas: map[string]*IdentitySchema{},
ActionSchemas: map[string]*ActionSchema{},
},
},
{
@ -223,8 +221,21 @@ func TestMarshalProvider(t *testing.T) {
Version: 1,
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Optional: true},
"items": {Type: cty.List(cty.String), Required: true},
"data": {
Type: cty.DynamicPseudoType,
Computed: true,
},
},
BlockTypes: map[string]*configschema.NestedBlock{
"config": {
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Optional: true},
"items": {Type: cty.List(cty.String), Required: true},
},
},
Nesting: configschema.NestingSingle,
},
},
},
},
@ -483,8 +494,21 @@ func testProvider() providers.ProviderSchema {
Version: 1,
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Optional: true},
"items": {Type: cty.List(cty.String), Required: true},
"data": {
Type: cty.DynamicPseudoType,
Computed: true,
},
},
BlockTypes: map[string]*configschema.NestedBlock{
"config": {
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Optional: true},
"items": {Type: cty.List(cty.String), Required: true},
},
},
Nesting: configschema.NestingSingle,
},
},
},
},

Loading…
Cancel
Save