Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Prevent a provider panic in `elasticstack_kibana_data_view` when a `field_format` does not include a `pattern`. ([#619](https://github.com/elastic/terraform-provider-elasticstack/pull/619/files))
- Fixed a bug where the `id` attribute for `elasticstack_kibana_slo` resources was ignored by renaming the attribute to `slo_id`. ([#622](https://github.com/elastic/terraform-provider-elasticstack/pull/622))
- Fixed a bug where the `rule_id` attribute for `elasticstack_kibana_alerting_rule` was ignored. ([#626](https://github.com/elastic/terraform-provider-elasticstack/pull/626))
- Fix provider crash when running against Serverless projects ([#630](https://github.com/elastic/terraform-provider-elasticstack/pull/630))

### Added

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/elasticsearch_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ If specified, this mapping can include: field names, [field data types](https://
**NOTE:**
- Changing datatypes in the existing _mappings_ will force index to be re-created.
- Removing field will be ignored by default same as elasticsearch. You need to recreate the index to remove field completely.
- `master_timeout` (String) Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`.
- `master_timeout` (String) Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`. This value is ignored when running against Serverless projects.
- `max_docvalue_fields_search` (Number) The maximum number of `docvalue_fields` that are allowed in a query.
- `max_inner_result_window` (Number) The maximum value of `from + size` for inner hits definition and top hits aggregations to this index.
- `max_ngram_diff` (Number) The maximum allowed difference between min_gram and max_gram for NGramTokenizer and NGramTokenFilter.
Expand Down Expand Up @@ -130,7 +130,7 @@ If specified, this mapping can include: field names, [field data types](https://
- `sort_order` (List of String) The direction to sort shards in. Accepts `asc`, `desc`.
- `timeout` (String) Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`.
- `unassigned_node_left_delayed_timeout` (String) Time to delay the allocation of replica shards which become unassigned because a node has left, in time units, e.g. `10s`
- `wait_for_active_shards` (String) The number of shard copies that must be active before proceeding with the operation. Set to `all` or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: `1`, the primary shard.
- `wait_for_active_shards` (String) The number of shard copies that must be active before proceeding with the operation. Set to `all` or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: `1`, the primary shard. This value is ignored when running against Serverless projects.

### Read-Only

Expand Down
9 changes: 9 additions & 0 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ func (a *ApiClient) ServerVersion(ctx context.Context) (*version.Version, diag.D
return serverVersion, nil
}

func (a *ApiClient) ServerFlavor(ctx context.Context) (string, diag.Diagnostics) {
info, diags := a.serverInfo(ctx)
if diags.HasError() {
return "", diags
}

return info.Version.BuildFlavor, nil
}

func (a *ApiClient) ClusterID(ctx context.Context) (*string, diag.Diagnostics) {
info, diags := a.serverInfo(ctx)
if diags.HasError() {
Expand Down
30 changes: 20 additions & 10 deletions internal/elasticsearch/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,13 @@ If specified, this mapping can include: field names, [field data types](https://
},
"wait_for_active_shards": {
Type: schema.TypeString,
Description: "The number of shard copies that must be active before proceeding with the operation. Set to `all` or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: `1`, the primary shard.",
Description: "The number of shard copies that must be active before proceeding with the operation. Set to `all` or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: `1`, the primary shard. This value is ignored when running against Serverless projects.",
Optional: true,
Default: "1",
},
"master_timeout": {
Type: schema.TypeString,
Description: "Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`.",
Description: "Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`. This value is ignored when running against Serverless projects.",
Optional: true,
Default: "30s",
ValidateFunc: utils.StringIsDuration,
Expand Down Expand Up @@ -759,25 +759,35 @@ func resourceIndexCreate(ctx context.Context, d *schema.ResourceData, meta inter
}
}

params := models.PutIndexParams{
WaitForActiveShards: d.Get("wait_for_active_shards").(string),
IncludeTypeName: d.Get("include_type_name").(bool),
}
serverVersion, diags := client.ServerVersion(ctx)
if diags.HasError() {
return diags
}

serverFlavor, diags := client.ServerFlavor(ctx)
if diags.HasError() {
return diags
}

params := models.PutIndexParams{
IncludeTypeName: d.Get("include_type_name").(bool),
}

if includeTypeName := d.Get("include_type_name").(bool); includeTypeName {
if serverVersion.GreaterThanOrEqual(includeTypeNameMinUnsupportedVersion) {
return diag.FromErr(fmt.Errorf("'include_type_name' field is supported only for elasticsearch v7.x"))
}
params.IncludeTypeName = includeTypeName
}
masterTimeout, err := time.ParseDuration(d.Get("master_timeout").(string))
if err != nil {
return diag.FromErr(err)

if serverFlavor != "serverless" {
params.WaitForActiveShards = d.Get("wait_for_active_shards").(string)
masterTimeout, err := time.ParseDuration(d.Get("master_timeout").(string))
if err != nil {
return diag.FromErr(err)
}
params.MasterTimeout = masterTimeout
}
params.MasterTimeout = masterTimeout

timeout, err := time.ParseDuration(d.Get("timeout").(string))
if err != nil {
Expand Down
25 changes: 24 additions & 1 deletion internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ import (
"time"
)

type BuildDate struct {
time.Time
}

func (b *BuildDate) UnmarshalJSON(dateBytes []byte) error {
dateStr := strings.Trim(string(dateBytes), "\"")
if dateStr == "null" {
b.Time = time.Time{}
return nil
}

t, err := time.Parse("2006-01-02T15:04:05Z07:00", dateStr)
if err != nil {
t, err = time.Parse("2006-01-02", dateStr)
if err != nil {
return err
}
}

b.Time = t
return nil
}

type ClusterInfo struct {
Name string `json:"name"`
ClusterName string `json:"cluster_name"`
Expand All @@ -16,7 +39,7 @@ type ClusterInfo struct {
BuildType string `json:"build_type"`
BuildHash string `json:"build_hash"`
BuildFlavor string `json:"build_flavor"`
BuildDate time.Time `json:"build_date"`
BuildDate BuildDate `json:"build_date"`
BuildSnapshot bool `json:"build_snapshot"`
LuceneVersion string `json:"lucene_version"`
MinimumWireCompatibilityVersion string `json:"minimum_wire_compatibility_version"`
Expand Down