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

schema/decoder: Introduce AddressingMode into AttributeAddrSchema #262

Open
radeksimko opened this issue Apr 14, 2023 · 0 comments
Open
Labels
enhancement New feature or request technical-debt

Comments

@radeksimko
Copy link
Member

Context

We currently have two boolean fields in both AttributeAddrSchema and BlockAddrSchema to indicate whether the attribute/block is meant to be collected as type-aware, and/or type-only.

In practice, when any *AddrSchema is declared, then at least one of these two is flipped to true. This may not be most obvious to end-users and also results in quite verbose logic whenever reference target collection is involved.

// AsExprType defines whether the value of the attribute
// is addressable as a matching literal type constraint included
// in attribute Expr.
//
// cty.DynamicPseudoType (also known as "any type") will create
// reference of the real type if value is present else cty.DynamicPseudoType.
AsExprType bool
// AsReference defines whether the attribute
// is addressable as a type-less reference
AsReference bool

// AsReference defines whether the block itself
// is addressable as a type-less reference
AsReference bool
// BodyAsData defines whether the data in the block body
// is addressable as cty.Object or cty.List(cty.Object),
// cty.Set(cty.Object) etc. depending on block type
BodyAsData bool

// AsExprType defines whether the value of the attribute
// is addressable as a matching literal type constraint included
// in attribute Expr.
//
// cty.DynamicPseudoType (also known as "any type") will create
// reference of the real type if value is present else cty.DynamicPseudoType.
AsExprType bool
// AsReference defines whether the attribute
// is addressable as a type-less reference
AsReference bool

Proposal

We could replace the two boolean fields with special type that expects three constants:

  • TypeAware
  • TypeUnaware
  • Both

names TBD, but the main idea is that having a single field means that the common case in Terraform (of both) will be less verbose and the collection related logic can also be less verbose as a result of dealing with one field, instead of two.

It should aid readability on both ends of maintainers and end-users.

@radeksimko radeksimko added enhancement New feature or request technical-debt labels Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request technical-debt
Projects
None yet
Development

No branches or pull requests

1 participant