diff --git a/internal/configs/configschema/decoder_spec.go b/internal/configs/configschema/decoder_spec.go index 896cbc04b245..5fc6e77131c4 100644 --- a/internal/configs/configschema/decoder_spec.go +++ b/internal/configs/configschema/decoder_spec.go @@ -183,19 +183,6 @@ func (b *Block) DecoderSpec() hcldec.Spec { return ret } -func (b *IdentityAttributes) DecoderSpec() hcldec.Spec { - ret := hcldec.ObjectSpec{} - if b == nil { - return ret - } - - for name, attrS := range *b { - ret[name] = attrS.decoderSpec(name) - } - - return ret -} - func (a *Attribute) decoderSpec(name string) hcldec.Spec { if a == nil || (a.Type == cty.NilType && a.NestedType == nil) { panic("Invalid attribute schema: schema is nil.") @@ -218,23 +205,6 @@ func (a *Attribute) decoderSpec(name string) hcldec.Spec { return ret } -func (a *IdentityAttribute) decoderSpec(name string) hcldec.Spec { - if a == nil || a.Type == cty.NilType { - panic("Invalid attribute schema: schema is nil.") - } - - ret := &hcldec.AttrSpec{Name: name} - ret.Type = a.Type - // When dealing with IdentityAttribute we expect every attribute to be required. - // This is generally true for all communication between providers and Terraform. - // For import, we allow the user to only specify a subset of the attributes, where - // RequiredForImport attributes are required and OptionalForImport attributes are optional. - // The validation for this will rely on a separate spec. - ret.Required = true - - return ret -} - // listOptionalAttrsFromObject is a helper function which does *not* recurse // into NestedType Attributes, because the optional types for each of those will // belong to their own cty.Object definitions. It is used in other functions diff --git a/internal/configs/configschema/identity_schema.go b/internal/configs/configschema/identity_schema.go new file mode 100644 index 000000000000..49f20893e585 --- /dev/null +++ b/internal/configs/configschema/identity_schema.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package configschema + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// IdentityAttributes represents a set of attributes in an identity schema +type IdentityAttributes map[string]*IdentityAttribute + +// IdentityAttribute represents a single attribute in an identity schema +type IdentityAttribute struct { + // Type is a type specification that the attribute's value must conform to. + Type cty.Type + + Description string + + RequiredForImport bool + OptionalForImport bool +} + +func (ia *IdentityAttributes) ImpliedType() cty.Type { + return ia.specType().WithoutOptionalAttributesDeep() +} + +func (ia *IdentityAttributes) specType() cty.Type { + if ia == nil { + return cty.EmptyObject + } + + return hcldec.ImpliedType(ia.DecoderSpec()) +} + +func (ia *IdentityAttributes) DecoderSpec() hcldec.Spec { + ret := hcldec.ObjectSpec{} + if ia == nil { + return ret + } + + for name, attrS := range *ia { + ret[name] = attrS.decoderSpec(name) + } + + return ret +} + +func (ia *IdentityAttribute) decoderSpec(name string) hcldec.Spec { + if ia == nil || ia.Type == cty.NilType { + panic("Invalid attribute schema: schema is nil.") + } + + ret := &hcldec.AttrSpec{Name: name} + ret.Type = ia.Type + // When dealing with IdentityAttribute we expect every attribute to be required. + // This is generally true for all communication between providers and Terraform. + // For import, we allow the user to only specify a subset of the attributes, where + // RequiredForImport attributes are required and OptionalForImport attributes are optional. + // The validation for this will rely on a separate spec. + ret.Required = true + + return ret +} diff --git a/internal/configs/configschema/implied_type.go b/internal/configs/configschema/implied_type.go index 0ffad5926097..4affa6eaa8b0 100644 --- a/internal/configs/configschema/implied_type.go +++ b/internal/configs/configschema/implied_type.go @@ -35,21 +35,6 @@ func (b *Block) specType() cty.Type { return hcldec.ImpliedType(b.DecoderSpec()) } -func (b *IdentityAttributes) ImpliedType() cty.Type { - return b.specType().WithoutOptionalAttributesDeep() -} - -// specType returns the cty.Type used for decoding a configuration -// block using the receiving block schema. This is the type used internally by -// hcldec to decode configuration. -func (b *IdentityAttributes) specType() cty.Type { - if b == nil { - return cty.EmptyObject - } - - return hcldec.ImpliedType(b.DecoderSpec()) -} - // ContainsSensitive returns true if any of the attributes of the receiving // block or any of its descendant blocks are marked as sensitive. // diff --git a/internal/configs/configschema/schema.go b/internal/configs/configschema/schema.go index 0d1d8725a4bd..0e5d387c3037 100644 --- a/internal/configs/configschema/schema.go +++ b/internal/configs/configschema/schema.go @@ -84,18 +84,6 @@ type Attribute struct { WriteOnly bool } -type IdentityAttributes map[string]*IdentityAttribute - -type IdentityAttribute struct { - // Type is a type specification that the attribute's value must conform to. - Type cty.Type - - Description string - - RequiredForImport bool - OptionalForImport bool -} - // Object represents the embedding of a structural object inside an Attribute. type Object struct { // Attributes describes the nested attributes which may appear inside the