Documentation ¶
Overview ¶
tf-schema is a library to help trim down the verbosity of writing terraform providers.
It does this in a couple of ways.
1. By providing primitive combinators to make writing schemas/resources simpler, easier to read and write.
2. By providing a codegen tool so a provider can have its own typed resources, not relying on interface{}, but whatever userland type is desired.
These two features can be used separately or together.
See the README at https://github.com/stanistan/tf-schema for examples.
Index ¶
- Variables
- func Bool(s *schema.Schema)
- func Computed(s *schema.Schema)
- func ConvertResourceMap(in map[string]ResourceConverible) map[string]*schema.Resource
- func Int(s *schema.Schema)
- func List(s *schema.Schema)
- func Map(s *schema.Schema)
- func Optional(s *schema.Schema)
- func Required(s *schema.Schema)
- func String(s *schema.Schema)
- type MapMutator
- type Named
- type NamedSchemaFactory
- type Option
- type ProviderConvertible
- type ResourceConverible
- type Schema
- func (s *Schema) AsResource() *schema.Resource
- func (s *Schema) ComputedList(name string) MapMutator
- func (s *Schema) ComputedMap(name string) MapMutator
- func (s *Schema) Get() map[string]*schema.Schema
- func (s *Schema) MustPush(fs ...MapMutator) *Schema
- func (s *Schema) Push(fs ...MapMutator) (*Schema, error)
Constants ¶
This section is empty.
Variables ¶
var ( RequiredBool NamedSchemaFactory = Type(Required, Bool) RequiredInt = Type(Required, Int) RequiredString = Type(Required, String) ComputedBool = Type(Computed, Bool) ComputedInt = Type(Computed, Int) ComputedString = Type(Computed, String) OptionalBool = Type(Optional, Bool) OptionalInt = Type(Optional, Int) OptionalString = Type(Optional, String) )
These are pre-defined type constructors for Named.
Use them like so:
Resource( RequiredBool("bool_field_name") )
var Resource = Must
Resource is an alias for Must.
This may become the actual thing we call the package.
Functions ¶
func ConvertResourceMap ¶
func ConvertResourceMap(in map[string]ResourceConverible) map[string]*schema.Resource
ConvertResourceMap converts a map of ResourceConveribles into a map of schema.Resources.
Types ¶
type MapMutator ¶
MapMutator is an interface that describes something that can mutate a schema.Schema.
type Named ¶
type Named struct {
// contains filtered or unexported fields
}
Named holds a schema.Schema with it's name.
type NamedSchemaFactory ¶
NamedSchemaFactory is a function that creates a Named.
func Type ¶
func Type(defaultOpts ...Option) NamedSchemaFactory
Type is a constructor of NamedSchemaFactory given default Options.
type Option ¶
Option can mutate the schema.
Use this for composition.
func Default ¶
func Default(v interface{}) Option
Default creates an Option marks the schema's Default field.
func Elem ¶
func Elem(r interface{}) Option
Elem creates an Option that sets the Elem field on the schema.
Accepts either schema.Schema, schema.Response, or an Option.
func ListOf ¶
func ListOf(value interface{}) Option
ListOf is an Option that marks the schema to be a List of value.
type ProviderConvertible ¶
ProviderConvertible is anything that can be converted into a schema.Provider.
type ResourceConverible ¶
ResourceConverible is anything that can be converted to a schema.Resource.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is a wrapper for the terraform map[string]*schema.Schema.
This is similar to something you would use if you were creating a resource.
func Must ¶
func Must(fs ...MapMutator) *Schema
Must creates a Schema and panics if there is an error.
func New ¶
func New(fs ...MapMutator) (*Schema, error)
New creates a Schema given any MapMutators and applies them.
func (*Schema) AsResource ¶
AsResource turns this schema into a schema.Resource.
func (*Schema) ComputedList ¶
func (s *Schema) ComputedList(name string) MapMutator
ComputedList wraps this Schema into a MapMutator.
func (*Schema) ComputedMap ¶
func (s *Schema) ComputedMap(name string) MapMutator
ComputedMap wraps this Schema into a MapMutator.
func (*Schema) MustPush ¶
func (s *Schema) MustPush(fs ...MapMutator) *Schema
MustPush adds any MapMutators to a Schema, panics on failure.