Almost every Terraform Plugin offers user configurable parameters, examples such
as a Provider’s region or a Resource's name. Each parameter is defined in
the items schema, which is a map of string names to schema structs.
In the below example implementation of a Resource you see parameters uuid and
name defined:
The Schema attribute Type defines what kind of values users can provide in
their configuration for this element. Here we define the available schema types
supported. See Schema Behaviors
for more information on configuring element behaviors.
The schema attribute Type determines what data is valid in configuring the
element, as well as the type of data returned when used in an
expression. Schemas attributes must
be one of the types defined below, and can be loosely categorized as either
Primitive or Aggregate types:
Primitive types
Primitive types are simple values such as integers, booleans, and strings.
Primitives are stored in the
state file as "key": "value"
string pairs, where both key and value are string representations.
Aggregate types
Aggregate types form more complicated data types by combining primitive types.
Aggregate types may define the types of elements they contain by using the
Elem property. If the Elem property is omitted, the default element data
type is a string.
Aggregate types are stored in state as a key.index and value pair for each
element of the property, with a unique index appended to the key based on
the type. There is an additional key.index item included in the state that
tracks the number of items the property contains.
A key based map (also known as a dictionary) with string keys and values defined
by the Elem property.
NOTE: Using the Elem block to define specific keys for the map is currently not possible. A potential workaround would be to confirm the required keys are set when expanding the Map object inside the resource code.
Used to represent an ordered collection of items, where the order the items
are presented can impact the behavior of the resource being modeled. An example
of ordered items would be network routing rules, where rules are examined in the
order they are given until a match is found. The items are all of the same type
defined by the Elem property.
TypeSet implements set behavior and is used to represent an unordered
collection of items, meaning that their ordering specified does not need to be
consistent, and the ordering itself has no impact on the behavior of the
resource.
The elements of a set can be any of the other types allowed by Terraform,
including another schema. Set items cannot be repeated.
resource "example_security_group""ex"{name="sg_test"description="managed by Terraform"ingress{protocol="tcp"from_port=80to_port=9000cidr_blocks=["10.0.0.0/8"]}ingress{protocol="tcp"from_port=80to_port=8000cidr_blocks=["0.0.0.0/0", "10.0.0.0/8"]}}
resource "example_security_group""ex"{name="sg_test"description="managed by Terraform"ingress{protocol="tcp"from_port=80to_port=9000cidr_blocks=["10.0.0.0/8"]}ingress{protocol="tcp"from_port=80to_port=8000cidr_blocks=["0.0.0.0/0", "10.0.0.0/8"]}}
State representation:
TypeSet items are stored in state with an index value calculated by the hash
of the attributes of the set.