github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/configs/configschema/schema.go (about)

     1  package configschema
     2  
     3  import (
     4  	"github.com/zclconf/go-cty/cty"
     5  )
     6  
     7  // StringKind represents the format a string is in.
     8  type StringKind int
     9  
    10  const (
    11  	// StringPlain indicates a string is plain-text and requires no processing for display.
    12  	StringPlain StringKind = iota
    13  	// StringMarkdown indicates a string is in markdown format and may
    14  	// require additional processing to display.
    15  	StringMarkdown
    16  )
    17  
    18  // Block represents a configuration block.
    19  //
    20  // "Block" here is a logical grouping construct, though it happens to map
    21  // directly onto the physical block syntax of Terraform's native configuration
    22  // syntax. It may be a more a matter of convention in other syntaxes, such as
    23  // JSON.
    24  //
    25  // When converted to a value, a Block always becomes an instance of an object
    26  // type derived from its defined attributes and nested blocks
    27  type Block struct {
    28  	// Attributes describes any attributes that may appear directly inside
    29  	// the block.
    30  	Attributes map[string]*Attribute
    31  
    32  	// BlockTypes describes any nested block types that may appear directly
    33  	// inside the block.
    34  	BlockTypes map[string]*NestedBlock
    35  
    36  	// Description and DescriptionKind contain a user facing description of the block
    37  	// and the format of that string.
    38  	Description     string
    39  	DescriptionKind StringKind
    40  
    41  	// Deprecated indicates whether the block has been marked as deprecated in the
    42  	// provider and usage should be discouraged.
    43  	Deprecated bool
    44  }
    45  
    46  // Attribute represents a configuration attribute, within a block.
    47  type Attribute struct {
    48  	// Type is a type specification that the attribute's value must conform to.
    49  	Type cty.Type
    50  
    51  	// Description is an English-language description of the purpose and
    52  	// usage of the attribute. A description should be concise and use only
    53  	// one or two sentences, leaving full definition to longer-form
    54  	// documentation defined elsewhere.
    55  	Description     string
    56  	DescriptionKind StringKind
    57  
    58  	// Required, if set to true, specifies that an omitted or null value is
    59  	// not permitted.
    60  	Required bool
    61  
    62  	// Optional, if set to true, specifies that an omitted or null value is
    63  	// permitted. This field conflicts with Required.
    64  	Optional bool
    65  
    66  	// Computed, if set to true, specifies that the value comes from the
    67  	// provider rather than from configuration. If combined with Optional,
    68  	// then the config may optionally provide an overridden value.
    69  	Computed bool
    70  
    71  	// Sensitive, if set to true, indicates that an attribute may contain
    72  	// sensitive information.
    73  	//
    74  	// At present nothing is done with this information, but callers are
    75  	// encouraged to set it where appropriate so that it may be used in the
    76  	// future to help Terraform mask sensitive information. (Terraform
    77  	// currently achieves this in a limited sense via other mechanisms.)
    78  	Sensitive bool
    79  
    80  	// Deprecated indicates whether the attribute has been marked as deprecated in the
    81  	// provider and usage should be discouraged.
    82  	Deprecated bool
    83  }
    84  
    85  // NestedBlock represents the embedding of one block within another.
    86  type NestedBlock struct {
    87  	// Block is the description of the block that's nested.
    88  	Block
    89  
    90  	// Nesting provides the nesting mode for the child block, which determines
    91  	// how many instances of the block are allowed, how many labels it expects,
    92  	// and how the resulting data will be converted into a data structure.
    93  	Nesting NestingMode
    94  
    95  	// MinItems and MaxItems set, for the NestingList and NestingSet nesting
    96  	// modes, lower and upper limits on the number of child blocks allowed
    97  	// of the given type. If both are left at zero, no limit is applied.
    98  	//
    99  	// As a special case, both values can be set to 1 for NestingSingle in
   100  	// order to indicate that a particular single block is required.
   101  	//
   102  	// These fields are ignored for other nesting modes and must both be left
   103  	// at zero.
   104  	MinItems, MaxItems int
   105  }
   106  
   107  // NestingMode is an enumeration of modes for nesting blocks inside other
   108  // blocks.
   109  type NestingMode int
   110  
   111  //go:generate go run golang.org/x/tools/cmd/stringer -type=NestingMode
   112  
   113  const (
   114  	nestingModeInvalid NestingMode = iota
   115  
   116  	// NestingSingle indicates that only a single instance of a given
   117  	// block type is permitted, with no labels, and its content should be
   118  	// provided directly as an object value.
   119  	NestingSingle
   120  
   121  	// NestingGroup is similar to NestingSingle in that it calls for only a
   122  	// single instance of a given block type with no labels, but it additonally
   123  	// guarantees that its result will never be null, even if the block is
   124  	// absent, and instead the nested attributes and blocks will be treated
   125  	// as absent in that case. (Any required attributes or blocks within the
   126  	// nested block are not enforced unless the block is explicitly present
   127  	// in the configuration, so they are all effectively optional when the
   128  	// block is not present.)
   129  	//
   130  	// This is useful for the situation where a remote API has a feature that
   131  	// is always enabled but has a group of settings related to that feature
   132  	// that themselves have default values. By using NestingGroup instead of
   133  	// NestingSingle in that case, generated plans will show the block as
   134  	// present even when not present in configuration, thus allowing any
   135  	// default values within to be displayed to the user.
   136  	NestingGroup
   137  
   138  	// NestingList indicates that multiple blocks of the given type are
   139  	// permitted, with no labels, and that their corresponding objects should
   140  	// be provided in a list.
   141  	NestingList
   142  
   143  	// NestingSet indicates that multiple blocks of the given type are
   144  	// permitted, with no labels, and that their corresponding objects should
   145  	// be provided in a set.
   146  	NestingSet
   147  
   148  	// NestingMap indicates that multiple blocks of the given type are
   149  	// permitted, each with a single label, and that their corresponding
   150  	// objects should be provided in a map whose keys are the labels.
   151  	//
   152  	// It's an error, therefore, to use the same label value on multiple
   153  	// blocks.
   154  	NestingMap
   155  )