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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Added
- Add `path_style_access` setting to `elasticstack_elasticsearch_snapshot_repository` on s3 repositories to enable path style access pattern ([#331](https://github.com/elastic/terraform-provider-elasticstack/pull/331))
- Add `transform` field to `elasticstack_elasticsearch_watch` to allow for payload transforms to be defined ([#340](https://github.com/elastic/terraform-provider-elasticstack/pull/340))

### Fixed
- Fix error presented by incorrect handling of `disabled_features` field in `elasticstack_kibana_space` resource ([#340](https://github.com/elastic/terraform-provider-elasticstack/pull/340))

## [0.6.0] - 2023-05-24

Expand Down Expand Up @@ -58,6 +62,14 @@
})
}
```
- If migrating existing resources in state from a previous version of the provider, then you will need to remove the reference to the resources in state before reapplying / reimporting:
- Run `terraform state rm` against your logstash pipelines (https://developer.hashicorp.com/terraform/cli/commands/state/rm)
- Ensure any definitions of the `pipeline_metadata` field in your resource definitions have been encapsulated with `jsonencode()` as mentioned above.
- EITHER
- run `terraform plan`
- run `terraform apply`
- OR
- reimport the resources into state using `terraform import` (https://developer.hashicorp.com/terraform/cli/import)
- Fix order of `indices` field in SLM ([#326](https://github.com/elastic/terraform-provider-elasticstack/pull/326))

## [0.5.0] - 2022-12-07
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/elasticsearch_watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ resource "elasticstack_elasticsearch_watch" "example" {
metadata = jsonencode({
"example_key" = "example_value"
})
transform = jsonencode({
"script" = "return [ 'time' : ctx.trigger.scheduled_time ]"
})
throttle_period_in_millis = 10000
}

Expand All @@ -60,6 +63,7 @@ output "watch" {
- `input` (String) The input that defines the input that loads the data for the watch.
- `metadata` (String) Metadata json that will be copied into the history entries.
- `throttle_period_in_millis` (Number) Minimum time in milliseconds between actions being run. Defaults to 5000.
- `transform` (String) Processes the watch payload to prepare it for the watch actions.

### Read-Only

Expand Down
9 changes: 5 additions & 4 deletions docs/resources/kibana_space.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ provider "elasticstack" {
}

resource "elasticstack_kibana_space" "example" {
space_id = "test_space"
name = "Test Space"
description = "A fresh space for testing visualisations"
initials = "ts"
space_id = "test_space"
name = "Test Space"
description = "A fresh space for testing visualisations"
disabled_features = ["ingestManager", "enterpriseSearch"]
initials = "ts"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ resource "elasticstack_elasticsearch_watch" "example" {
metadata = jsonencode({
"example_key" = "example_value"
})
transform = jsonencode({
"script" = "return [ 'time' : ctx.trigger.scheduled_time ]"
})
throttle_period_in_millis = 10000
}

Expand Down
9 changes: 5 additions & 4 deletions examples/resources/elasticstack_kibana_space/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ provider "elasticstack" {
}

resource "elasticstack_kibana_space" "example" {
space_id = "test_space"
name = "Test Space"
description = "A fresh space for testing visualisations"
initials = "ts"
space_id = "test_space"
name = "Test Space"
description = "A fresh space for testing visualisations"
disabled_features = ["ingestManager", "enterpriseSearch"]
initials = "ts"
}
25 changes: 25 additions & 0 deletions internal/elasticsearch/watcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func ResourceWatch() *schema.Resource {
Optional: true,
Default: "{}",
},
"transform": {
Description: "Processes the watch payload to prepare it for the watch actions.",
Type: schema.TypeString,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: utils.DiffJsonSuppress,
Optional: true,
},
"throttle_period_in_millis": {
Description: "Minimum time in milliseconds between actions being run. Defaults to 5000.",
Type: schema.TypeInt,
Expand Down Expand Up @@ -143,6 +150,14 @@ func resourceWatchPut(ctx context.Context, d *schema.ResourceData, meta interfac
}
watch.Body.Metadata = metadata

if transformJSON, ok := d.GetOk("transform"); ok {
var transform map[string]interface{}
if err := json.Unmarshal([]byte(transformJSON.(string)), &transform); err != nil {
return diag.FromErr(err)
}
watch.Body.Transform = transform
}

watch.Body.Throttle_period_in_millis = d.Get("throttle_period_in_millis").(int)

if diags := elasticsearch.PutWatch(ctx, client, &watch); diags.HasError() {
Expand Down Expand Up @@ -220,6 +235,16 @@ func resourceWatchRead(ctx context.Context, d *schema.ResourceData, meta interfa
return diag.FromErr(err)
}

if watch.Body.Transform != nil {
transform, err := json.Marshal(watch.Body.Transform)
if err != nil {
return diag.FromErr(err)
}
if err := d.Set("transform", string(transform)); err != nil {
return diag.FromErr(err)
}
}

if err := d.Set("throttle_period_in_millis", watch.Body.Throttle_period_in_millis); err != nil {
return diag.FromErr(err)
}
Expand Down
18 changes: 18 additions & 0 deletions internal/elasticsearch/watcher/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestResourceWatch(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_elasticsearch_watch.test", "condition", `{"never":{}}`),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_watch.test", "actions", `{"log":{"logging":{"level":"info","text":"example logging text"}}}`),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_watch.test", "metadata", `{"example_key":"example_value"}`),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_watch.test", "transform", `{"search":{"request":{"body":{"query":{"match_all":{}}},"indices":[],"rest_total_hits_as_int":true,"search_type":"query_then_fetch"}}}`),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_watch.test", "throttle_period_in_millis", "10000"),
),
},
Expand Down Expand Up @@ -114,6 +115,23 @@ EOF
}
EOF

transform = <<EOF
{
"search" : {
"request" : {
"body" : {
"query" : {
"match_all" : {}
}
},
"indices": [],
"rest_total_hits_as_int" : true,
"search_type": "query_then_fetch"
}
}
}
EOF

throttle_period_in_millis = 10000
}
`, watchID)
Expand Down
9 changes: 7 additions & 2 deletions internal/kibana/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ func resourceSpaceUpsert(ctx context.Context, d *schema.ResourceData, meta inter
space.Description = description.(string)
}

if disabledFeatures, ok := d.GetOk("disabled_features"); ok {
space.DisabledFeatures = disabledFeatures.([]string)
features := make([]string, 0)
if v, ok := d.GetOk("disabled_features"); ok {
p := v.(*schema.Set)
for _, e := range p.List() {
features = append(features, e.(string))
}
}
space.DisabledFeatures = features

if initials, ok := d.GetOk("initials"); ok {
space.Initials = initials.(string)
Expand Down
9 changes: 6 additions & 3 deletions internal/kibana/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func TestAccResourceSpace(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "space_id", spaceId),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "name", fmt.Sprintf("Updated %s", spaceId)),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "description", "Updated space description"),
resource.TestCheckTypeSetElemAttr("elasticstack_kibana_space.test_space", "disabled_features.*", "ingestManager"),
resource.TestCheckTypeSetElemAttr("elasticstack_kibana_space.test_space", "disabled_features.*", "enterpriseSearch"),
),
},
},
Expand Down Expand Up @@ -62,9 +64,10 @@ provider "elasticstack" {
}

resource "elasticstack_kibana_space" "test_space" {
space_id = "%s"
name = "%s"
description = "Updated space description"
space_id = "%s"
name = "%s"
description = "Updated space description"
disabled_features = ["ingestManager", "enterpriseSearch"]
}
`, id, fmt.Sprintf("Updated %s", id))
}
Expand Down
1 change: 1 addition & 0 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,6 @@ type WatchBody struct {
Condition map[string]interface{} `json:"condition"`
Actions map[string]interface{} `json:"actions"`
Metadata map[string]interface{} `json:"metadata"`
Transform map[string]interface{} `json:"transform,omitempty"`
Throttle_period_in_millis int `json:"throttle_period_in_millis,omitempty"`
}