• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Terraform
  • Install
  • Tutorials
    • About the Docs
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • CDK for Terraform
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
  • Registry(opens in new tab)
  • Try Cloud(opens in new tab)
  • Sign up
Plugin Development

SDKv2

Skip to main content
  • SDKv2
  • Migrate to the Framework
    (opens in new tab)
    • Overview
    • Schema Types
    • Schema Behaviors
  • Debugging Providers

  • Resources

  • Tutorial Library
  • Certifications
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  • Terraform Registry
    (opens in new tab)
  1. Developer
  2. Terraform
  3. Plugin Development
  4. SDKv2
  5. Schemas
  • Plugin SDK
  • v2.23.x
  • v2.22.x
  • v2.21.x
  • v2.20.x
  • v2.19.x
  • v2.18.x
  • v2.17.x
  • v2.16.x
  • v2.15.x

»Terraform Schemas

Terraform Plugins are expressed using schemas to define attributes and their behaviors, using a high level package exposed by Terraform Core named schema. Providers, Resources, and Provisioners all contains schemas, and Terraform Core uses them to produce plan and apply executions based on the behaviors described.

Below is an example provider.go file, detailing a hypothetical ExampleProvider implementation:

package exampleprovider

import (
    "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func Provider() *schema.Provider {
    // Example Provider requires an API Token.
    // The Email is optional
    return &schema.Provider{
        Schema: map[string]*schema.Schema{
            "api_token": {
                Type:        schema.TypeString,
                Required:    true,
            },
            "email": {
                Type:        schema.TypeString,
                Optional:    true,
                Default:     "",
            },
        },
    }
}

In this example we’re creating a Provider and setting it’s schema. This schema is a collection of key value pairs of schema elements the attributes a user can specify in their configuration. The keys are strings, and the values are schema.Schema structs that define the behavior.

Schemas can be thought of as a type paired one or more properties that describe it’s behavior.

Schema Types

Schema items must be defined using one of the builtin types, such as TypeString, TypeBool, TypeInt, et. al. The type defines what is considered valid input for a given schema item in a users configuration.

See Schema Types for more information on the types available to schemas.

Schema Behaviors

Schema items can have various properties that can be combined to match their behaviors represented by their API. Some items are Required, others Optional, while others may be Computed such that they are useful to be tracked in state, but cannot be configured by users.

See Schema Behaviors for more information on the properties a schema can have.

Edit this page on GitHub

On this page

  1. Terraform Schemas
  2. Schema Types
  3. Schema Behaviors
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)