in internal/elasticsearch/transform/transform.go [46:317]
func ResourceTransform() *schema.Resource {
transformSchema := map[string]*schema.Schema{
"id": {
Description: "Internal identifier of the resource",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the transform you wish to create.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 64),
validation.StringMatch(regexp.MustCompile(`^[a-z0-9_-]+$`), "must contain only lower case alphanumeric characters, hyphens, and underscores"),
validation.StringMatch(regexp.MustCompile(`^[a-z0-9].*[a-z0-9]$`), "must start and end with a lowercase alphanumeric character"),
),
},
"description": {
Description: "Free text description of the transform.",
Type: schema.TypeString,
Optional: true,
},
"source": {
Description: "The source of the data for the transform.",
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"indices": {
Description: "The source indices for the transform.",
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"query": {
Description: "A query clause that retrieves a subset of data from the source index.",
Type: schema.TypeString,
Optional: true,
Default: `{"match_all":{}}`,
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.StringIsJSON,
},
"runtime_mappings": {
Description: "Definitions of search-time runtime fields that can be used by the transform.",
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.StringIsJSON,
},
},
},
},
"destination": {
Description: "The destination for the transform.",
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"index": {
Description: "The destination index for the transform.",
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 255),
validation.StringNotInSlice([]string{".", ".."}, true),
validation.StringMatch(regexp.MustCompile(`^[^-_+]`), "cannot start with -, _, +"),
validation.StringMatch(regexp.MustCompile(`^[a-z0-9!$%&'()+.;=@[\]^{}~_-]+$`), "must contain lower case alphanumeric characters and selected punctuation, see: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#indices-create-api-path-params"),
),
},
"aliases": {
Description: "The aliases that the destination index for the transform should have.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"alias": {
Description: "The name of the alias.",
Type: schema.TypeString,
Required: true,
},
"move_on_creation": {
Description: "Whether the destination index should be the only index in this alias. Defaults to false.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
"pipeline": {
Description: "The unique identifier for an ingest pipeline.",
Type: schema.TypeString,
Optional: true,
},
},
},
},
"pivot": {
Description: "The pivot method transforms the data by aggregating and grouping it. JSON definition expected. Either 'pivot' or 'latest' must be present.",
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"pivot", "latest"},
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.StringIsJSON,
ForceNew: true,
},
"latest": {
Description: "The latest method transforms the data by finding the latest document for each unique key. JSON definition expected. Either 'pivot' or 'latest' must be present.",
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"pivot", "latest"},
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.StringIsJSON,
ForceNew: true,
},
"frequency": {
Type: schema.TypeString,
Description: "The interval between checks for changes in the source indices when the transform is running continuously. Defaults to `1m`.",
Optional: true,
Default: "1m",
ValidateFunc: utils.StringIsElasticDuration,
},
"metadata": {
Description: "Defines optional transform metadata.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: utils.DiffJsonSuppress,
},
"retention_policy": {
Description: "Defines a retention policy for the transform.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"time": {
Description: "Specifies that the transform uses a time field to set the retention policy. This is currently the only supported option.",
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field": {
Description: "The date field that is used to calculate the age of the document.",
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotWhiteSpace,
},
"max_age": {
Description: "Specifies the maximum age of a document in the destination index.",
Type: schema.TypeString,
Required: true,
ValidateFunc: utils.StringIsElasticDuration,
},
},
},
},
},
},
},
"sync": {
Description: "Defines the properties transforms require to run continuously.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"time": {
Description: "Specifies that the transform uses a time field to synchronize the source and destination indices. This is currently the only supported option.",
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field": {
Description: "The date field that is used to identify new documents in the source.",
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotWhiteSpace,
},
"delay": {
Description: "The time delay between the current time and the latest input data time. The default value is 60s.",
Type: schema.TypeString,
Optional: true,
Default: "60s",
ValidateFunc: utils.StringIsElasticDuration,
},
},
},
},
},
},
},
"align_checkpoints": {
Description: "Specifies whether the transform checkpoint ranges should be optimized for performance.",
Type: schema.TypeBool,
Optional: true,
},
"dates_as_epoch_millis": {
Description: "Defines if dates in the output should be written as ISO formatted string (default) or as millis since epoch.",
Type: schema.TypeBool,
Optional: true,
},
"deduce_mappings": {
Description: "Specifies whether the transform should deduce the destination index mappings from the transform config.",
Type: schema.TypeBool,
Optional: true,
},
"docs_per_second": {
Description: "Specifies a limit on the number of input documents per second. Default (unset) value disables throttling.",
Type: schema.TypeFloat,
Optional: true,
ValidateFunc: validation.FloatAtLeast(0),
},
"max_page_search_size": {
Description: "Defines the initial page size to use for the composite aggregation for each checkpoint. Default is 500.",
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(10, 65536),
},
"num_failure_retries": {
Description: "Defines the number of retries on a recoverable failure before the transform task is marked as failed. The default value is the cluster-level setting num_transform_failure_retries.",
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(-1, 100),
},
"unattended": {
Description: "In unattended mode, the transform retries indefinitely in case of an error which means the transform never fails.",
Type: schema.TypeBool,
Optional: true,
},
"defer_validation": {
Type: schema.TypeBool,
Description: "When true, deferrable validations are not run upon creation, but rather when the transform is started. This behavior may be desired if the source index does not exist until after the transform is created. Default is `false`",
Optional: true,
Default: false,
},
"timeout": {
Type: schema.TypeString,
Description: "Period to wait for a response from Elasticsearch when performing any management operation. If no response is received before the timeout expires, the operation fails and returns an error. Defaults to `30s`.",
Optional: true,
Default: "30s",
ValidateFunc: utils.StringIsDuration,
},
"enabled": {
Type: schema.TypeBool,
Description: "Controls whether the transform should be started or stopped. Default is `false` (stopped).",
Optional: true,
Default: false,
},
}
return &schema.Resource{
Schema: transformSchema,
Description: "Manages Elasticsearch transforms. See: https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html",
CreateContext: resourceTransformCreate,
ReadContext: resourceTransformRead,
UpdateContext: resourceTransformUpdate,
DeleteContext: resourceTransformDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}