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

Reflect v0.15 schema changes #28

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Changes from all 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
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor assuming that this is going to be logic that will need to be changed in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I assume so, but from what I understand it most likely won't happen until the next major version of Terraform itself.

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"`
}