Skip to content

Commit

Permalink
Reflect v0.15 schema changes (#28)
Browse files Browse the repository at this point in the history
* Reflect v0.15 schema changes

* Bump format version
  • Loading branch information
radeksimko authored Mar 22, 2021
1 parent e7d8f7c commit 04bbe76
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// ProviderSchemasFormatVersion is the version of the JSON provider
// schema format that is supported by this package.
const ProviderSchemasFormatVersion = "0.1"
const ProviderSchemasFormatVersion = "0.2"

// ProviderSchemas represents the schemas of all providers and
// resources in use by the configuration.
Expand Down Expand Up @@ -38,8 +38,10 @@ func (p *ProviderSchemas) Validate() error {
return errors.New("unexpected provider schema data, format version is missing")
}

if ProviderSchemasFormatVersion != p.FormatVersion {
return fmt.Errorf("unsupported provider schema data format version: expected %q, got %q", PlanFormatVersion, p.FormatVersion)
oldVersion := "0.1"
if p.FormatVersion != ProviderSchemasFormatVersion && p.FormatVersion != oldVersion {
return fmt.Errorf("unsupported provider schema data format version: expected %q or %q, got %q",
PlanFormatVersion, oldVersion, p.FormatVersion)
}

return nil
Expand Down Expand Up @@ -123,6 +125,20 @@ const (
// with a single-element constraint.
SchemaNestingModeSingle SchemaNestingMode = "single"

// SchemaNestingModeGroup is similar to SchemaNestingModeSingle in that it
// calls for only a single instance of a given block type with no labels,
// but it additonally guarantees that its result will never be null,
// even if the block is absent, and instead the nested attributes
// and blocks will be treated as absent in that case.
//
// This is useful for the situation where a remote API has a feature that
// is always enabled but has a group of settings related to that feature
// that themselves have default values. By using SchemaNestingModeGroup
// instead of SchemaNestingModeSingle in that case, generated plans will
// show the block as present even when not present in configuration,
// thus allowing any default values within to be displayed to the user.
SchemaNestingModeGroup SchemaNestingMode = "group"

// SchemaNestingModeList denotes list block nesting mode, which
// allows an ordered list of blocks where duplicates are allowed.
SchemaNestingModeList SchemaNestingMode = "list"
Expand Down Expand Up @@ -162,9 +178,14 @@ type SchemaBlockType struct {

// SchemaAttribute describes an attribute within a schema block.
type SchemaAttribute struct {
// The attribute type.
// The attribute type
// Either AttributeType or AttributeNestedType is set, never both.
AttributeType cty.Type `json:"type,omitempty"`

// Details about a nested attribute type
// Either AttributeType or AttributeNestedType is set, never both.
AttributeNestedType *SchemaNestedAttributeType `json:"nested_type,omitempty"`

// The description field for this attribute. If no kind is
// provided, it can be assumed to be plain text.
Description string `json:"description,omitempty"`
Expand All @@ -191,3 +212,23 @@ type SchemaAttribute struct {
// treat these values with greater care than non-sensitive fields.
Sensitive bool `json:"sensitive,omitempty"`
}

// SchemaNestedAttributeType describes a nested attribute
// which could also be just expressed simply as cty.Object(...),
// cty.List(cty.Object(...)) etc. but this allows tracking additional
// metadata which can help interpreting or validating the data.
type SchemaNestedAttributeType struct {
// A map of nested attributes
Attributes map[string]*SchemaAttribute `json:"attributes,omitempty"`

// The nesting mode for this attribute.
NestingMode string `json:"nesting_mode,omitempty"`

// The lower limit on number of items that can be declared
// of this attribute type.
MinItems uint64 `json:"min_items,omitempty"`

// The upper limit on number of items that can be declared
// of this attribute type.
MaxItems uint64 `json:"max_items,omitempty"`
}

0 comments on commit 04bbe76

Please sign in to comment.