Skip to content

Commit cd68c06

Browse files
tobiodimuon
andauthored
Move the input blocks to an inputs map (#1482)
* Move the input blocks to an inputs map By itself this is just a bit of a painful breaking change, however it allows us to provide much nicer handling for default value handling, allowing practitioners to only supply non-default input/stream variables * Add missing output_id from schema migration * Update internal/fleet/integration_policy/models.go Co-authored-by: Dmitry Onishchenko <8962171+dimuon@users.noreply.github.com> * Update docs example * Remove unused enrollment tokens from acceptance tests * CHANGELOG.md --------- Co-authored-by: Dmitry Onishchenko <8962171+dimuon@users.noreply.github.com>
1 parent 5286a72 commit cd68c06

File tree

28 files changed

+1618
-518
lines changed

28 files changed

+1618
-518
lines changed

CHANGELOG.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
## [Unreleased]
22

3+
### Breaking changes
4+
5+
#### `elasticstack_fleet_integration_policy` input block has changed to a map attribute.
6+
7+
The `input` block in the `elasticstack_fleet_integration_policy` resource has been restructured into the `inputs` map attribute.
8+
This transition:
9+
* Allows the provider to implement semantic equality checking across all inputs within the integration policy. This change:
10+
* Prevents several state consistency errors experienced whilst using this resource
11+
* Allow practitioners to only define configuration for the inputs, streams, and variables that differ from the package defined defaults.
12+
* Reduces the scope of the large `streams_json` string. Instead allowing each stream to be defined as it's own object for Terraform drift checking.
13+
14+
Existing usage of the `input` block must be migrated to the attribute syntax. Some [examples](https://github.com/elastic/terraform-provider-elasticstack/compare/input-attribute?expand=1#diff-3346189f5ed24da90a529a5fa0d06be1745ee9013775c4b8e42a0e909155e5b6) of this migration can be seen in the changes to the provider automated tests. As a step-by-step guide however:
15+
16+
1. `input` blocks are merged together into a single `inputs` attribute
17+
2. The `input_id` attribute is removed, and instead used as the map key when defining an input
18+
3. `streams_json` is removed, with the contents becoming a `streams` map attribute
19+
20+
Combined, this looks like:
21+
22+
```hcl
23+
input {
24+
input_id = "tcp-tcp"
25+
enabled = false
26+
streams_json = jsonencode({
27+
"tcp.generic" : {
28+
"enabled" : false
29+
"vars" : {
30+
"listen_address" : "localhost"
31+
"listen_port" : 8085
32+
"data_stream.dataset" : "tcp.generic"
33+
"tags" : []
34+
"syslog_options" : "field: message"
35+
"ssl" : ""
36+
"custom" : ""
37+
}
38+
}
39+
})
40+
}
41+
```
42+
43+
becoming
44+
45+
```hcl
46+
inputs = {
47+
"tcp-tcp" = {
48+
enabled = false
49+
streams = {
50+
"tcp.generic" = {
51+
enabled = false
52+
vars = jsonencode({
53+
"listen_address" : "localhost"
54+
"listen_port" : 8085
55+
"data_stream.dataset" : "tcp.generic"
56+
"tags" : []
57+
"syslog_options" : "field: message"
58+
"ssl" : ""
59+
"custom" : ""
60+
})
61+
}
62+
}
63+
}
64+
}
65+
```
66+
67+
### Changes
68+
- Move the `input` block to an `inputs` map in `elasticstack_fleet_integration_policy` ([#1482](https://github.com/elastic/terraform-provider-elasticstack/pull/1482))
69+
370
## [0.13.0] - 2025-12-10
471

572
### Breaking changes

docs/resources/fleet_integration_policy.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,24 @@ resource "elasticstack_fleet_integration_policy" "sample" {
6666
// Optional: specify a custom output to send data to
6767
// output_id = "my-custom-output-id"
6868
69-
input {
70-
input_id = "tcp-tcp"
71-
streams_json = jsonencode({
72-
"tcp.generic" : {
73-
"enabled" : true,
74-
"vars" : {
75-
"listen_address" : "localhost",
76-
"listen_port" : 8080,
77-
"data_stream.dataset" : "tcp.generic",
78-
"tags" : [],
79-
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
80-
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
81-
"custom" : ""
69+
inputs = {
70+
"tcp-tcp" = {
71+
enabled = true
72+
streams = {
73+
"tcp.generic" = {
74+
enabled = true,
75+
vars = jsonencode({
76+
"listen_address" : "localhost",
77+
"listen_port" : 8080,
78+
"data_stream.dataset" : "tcp.generic",
79+
"tags" : [],
80+
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
81+
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
82+
"custom" : ""
83+
})
8284
}
8385
}
84-
})
86+
}
8587
}
8688
}
8789
```
@@ -103,7 +105,7 @@ resource "elasticstack_fleet_integration_policy" "sample" {
103105
- `description` (String) The description of the integration policy.
104106
- `enabled` (Boolean) Enable the integration policy.
105107
- `force` (Boolean) Force operations, such as creation and deletion, to occur.
106-
- `input` (Block List) Integration inputs. (see [below for nested schema](#nestedblock--input))
108+
- `inputs` (Attributes Map) Integration inputs mapped by input ID. (see [below for nested schema](#nestedatt--inputs))
107109
- `output_id` (String) The ID of the output to send data to. When not specified, the default output of the agent policy will be used.
108110
- `policy_id` (String) Unique identifier of the integration policy.
109111
- `space_ids` (Set of String) The Kibana space IDs where this integration policy is available. When set, must match the space_ids of the referenced agent policy. If not set, will be inherited from the agent policy. Note: The order of space IDs does not matter as this is a set.
@@ -113,18 +115,22 @@ resource "elasticstack_fleet_integration_policy" "sample" {
113115

114116
- `id` (String) The ID of this resource.
115117

116-
<a id="nestedblock--input"></a>
117-
### Nested Schema for `input`
118+
<a id="nestedatt--inputs"></a>
119+
### Nested Schema for `inputs`
118120

119-
Required:
121+
Optional:
122+
123+
- `enabled` (Boolean) Enable the input.
124+
- `streams` (Attributes Map) Input streams mapped by stream ID. (see [below for nested schema](#nestedatt--inputs--streams))
125+
- `vars` (String, Sensitive) Input-level variables as JSON.
120126

121-
- `input_id` (String) The identifier of the input.
127+
<a id="nestedatt--inputs--streams"></a>
128+
### Nested Schema for `inputs.streams`
122129

123130
Optional:
124131

125-
- `enabled` (Boolean) Enable the input.
126-
- `streams_json` (String, Sensitive) Input streams as JSON.
127-
- `vars_json` (String, Sensitive) Input variables as JSON.
132+
- `enabled` (Boolean) Enable the stream.
133+
- `vars` (String, Sensitive) Stream-level variables as JSON.
128134

129135
## Import
130136

examples/resources/elasticstack_fleet_integration_policy/resource.tf

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ resource "elasticstack_fleet_integration_policy" "sample" {
3535
// Optional: specify a custom output to send data to
3636
// output_id = "my-custom-output-id"
3737

38-
input {
39-
input_id = "tcp-tcp"
40-
streams_json = jsonencode({
41-
"tcp.generic" : {
42-
"enabled" : true,
43-
"vars" : {
44-
"listen_address" : "localhost",
45-
"listen_port" : 8080,
46-
"data_stream.dataset" : "tcp.generic",
47-
"tags" : [],
48-
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
49-
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
50-
"custom" : ""
38+
inputs = {
39+
"tcp-tcp" = {
40+
enabled = true
41+
streams = {
42+
"tcp.generic" = {
43+
enabled = true,
44+
vars = jsonencode({
45+
"listen_address" : "localhost",
46+
"listen_port" : 8080,
47+
"data_stream.dataset" : "tcp.generic",
48+
"tags" : [],
49+
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
50+
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
51+
"custom" : ""
52+
})
5153
}
5254
}
53-
})
55+
}
5456
}
5557
}

internal/fleet/integration/acc_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,23 @@ resource "elasticstack_fleet_integration_policy" "sample" {
199199
integration_name = elasticstack_fleet_integration.test_integration.name
200200
integration_version = elasticstack_fleet_integration.test_integration.version
201201
202-
input {
203-
input_id = "tcp-tcp"
204-
streams_json = jsonencode({
205-
"tcp.generic" : {
206-
"enabled" : true,
207-
"vars" : {
208-
"listen_address" : "localhost",
209-
"listen_port" : 8080,
210-
"data_stream.dataset" : "tcp.generic",
211-
"tags" : [],
212-
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
213-
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
214-
"custom" : ""
215-
}
202+
inputs = {
203+
"tcp-tcp" = {
204+
streams = {
205+
"tcp.generic" = {
206+
enabled = true,
207+
vars = jsonencode({
208+
"listen_address" : "localhost",
209+
"listen_port" : 8080,
210+
"data_stream.dataset" : "tcp.generic",
211+
"tags" : [],
212+
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
213+
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
214+
"custom" : ""
215+
})
216+
}
216217
}
217-
})
218+
}
218219
}
219220
}
220221
`, version, policyName, policyName)

0 commit comments

Comments
 (0)