@@ -10,7 +10,7 @@ import (
1010
1111// ProviderSchemasFormatVersion is the version of the JSON provider
1212// schema format that is supported by this package.
13- const ProviderSchemasFormatVersion = "0.1 "
13+ const ProviderSchemasFormatVersion = "0.2 "
1414
1515// ProviderSchemas represents the schemas of all providers and
1616// resources in use by the configuration.
@@ -38,8 +38,10 @@ func (p *ProviderSchemas) Validate() error {
3838 return errors .New ("unexpected provider schema data, format version is missing" )
3939 }
4040
41- if ProviderSchemasFormatVersion != p .FormatVersion {
42- return fmt .Errorf ("unsupported provider schema data format version: expected %q, got %q" , PlanFormatVersion , p .FormatVersion )
41+ oldVersion := "0.1"
42+ if p .FormatVersion != ProviderSchemasFormatVersion && p .FormatVersion != oldVersion {
43+ return fmt .Errorf ("unsupported provider schema data format version: expected %q or %q, got %q" ,
44+ PlanFormatVersion , oldVersion , p .FormatVersion )
4345 }
4446
4547 return nil
@@ -123,6 +125,20 @@ const (
123125 // with a single-element constraint.
124126 SchemaNestingModeSingle SchemaNestingMode = "single"
125127
128+ // SchemaNestingModeGroup is similar to SchemaNestingModeSingle in that it
129+ // calls for only a single instance of a given block type with no labels,
130+ // but it additonally guarantees that its result will never be null,
131+ // even if the block is absent, and instead the nested attributes
132+ // and blocks will be treated as absent in that case.
133+ //
134+ // This is useful for the situation where a remote API has a feature that
135+ // is always enabled but has a group of settings related to that feature
136+ // that themselves have default values. By using SchemaNestingModeGroup
137+ // instead of SchemaNestingModeSingle in that case, generated plans will
138+ // show the block as present even when not present in configuration,
139+ // thus allowing any default values within to be displayed to the user.
140+ SchemaNestingModeGroup SchemaNestingMode = "group"
141+
126142 // SchemaNestingModeList denotes list block nesting mode, which
127143 // allows an ordered list of blocks where duplicates are allowed.
128144 SchemaNestingModeList SchemaNestingMode = "list"
@@ -162,9 +178,14 @@ type SchemaBlockType struct {
162178
163179// SchemaAttribute describes an attribute within a schema block.
164180type SchemaAttribute struct {
165- // The attribute type.
181+ // The attribute type
182+ // Either AttributeType or AttributeNestedType is set, never both.
166183 AttributeType cty.Type `json:"type,omitempty"`
167184
185+ // Details about a nested attribute type
186+ // Either AttributeType or AttributeNestedType is set, never both.
187+ AttributeNestedType * SchemaNestedAttributeType `json:"nested_type,omitempty"`
188+
168189 // The description field for this attribute. If no kind is
169190 // provided, it can be assumed to be plain text.
170191 Description string `json:"description,omitempty"`
@@ -191,3 +212,23 @@ type SchemaAttribute struct {
191212 // treat these values with greater care than non-sensitive fields.
192213 Sensitive bool `json:"sensitive,omitempty"`
193214}
215+
216+ // SchemaNestedAttributeType describes a nested attribute
217+ // which could also be just expressed simply as cty.Object(...),
218+ // cty.List(cty.Object(...)) etc. but this allows tracking additional
219+ // metadata which can help interpreting or validating the data.
220+ type SchemaNestedAttributeType struct {
221+ // A map of nested attributes
222+ Attributes map [string ]* SchemaAttribute `json:"attributes,omitempty"`
223+
224+ // The nesting mode for this attribute.
225+ NestingMode string `json:"nesting_mode,omitempty"`
226+
227+ // The lower limit on number of items that can be declared
228+ // of this attribute type.
229+ MinItems uint64 `json:"min_items,omitempty"`
230+
231+ // The upper limit on number of items that can be declared
232+ // of this attribute type.
233+ MaxItems uint64 `json:"max_items,omitempty"`
234+ }
0 commit comments