Skip to content

Commit 36f0b42

Browse files
authored
Don't force replacement when changing integration versions (#1255)
* Don't force replacement when changing integration versions * Changelog
1 parent 5a76239 commit 36f0b42

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add `slo_id` validation to `elasticstack_kibana_slo` ([#1221](https://github.com/elastic/terraform-provider-elasticstack/pull/1221))
44
- Add `ignore_missing_component_templates` to `elasticstack_elasticsearch_index_template` ([#1206](https://github.com/elastic/terraform-provider-elasticstack/pull/1206))
55
- Prevent provider panic when a script exists in state, but not in Elasticsearch ([#1218](https://github.com/elastic/terraform-provider-elasticstack/pull/1218))
6+
- Allow version changes without a destroy/create cycle with `elasticstack_fleet_integration` ([#1255](https://github.com/elastic/terraform-provider-elasticstack/pull/1255)). This fixes an issue where it was impossible to upgrade integrations which are used by an integration policy.
67
- Add `namespace` attribute to `elasticstack_kibana_synthetics_monitor` resource to support setting data stream namespace independently from `space_id` ([#1247](https://github.com/elastic/terraform-provider-elasticstack/pull/1247))
78

89
## [0.11.17] - 2025-07-21

internal/fleet/integration/read.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (r *integrationResource) Read(ctx context.Context, req resource.ReadRequest
2828
pkg, diags := fleet.GetPackage(ctx, client, name, version)
2929
resp.Diagnostics.Append(diags...)
3030
if resp.Diagnostics.HasError() {
31-
resp.State.RemoveResource(ctx)
3231
return
3332
}
3433
if pkg.Status != nil && *pkg.Status != "installed" {

internal/fleet/integration/resource_test.go

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration_test
22

33
import (
44
"context"
5+
"fmt"
56
"regexp"
67
"testing"
78

@@ -10,11 +11,15 @@ import (
1011
"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
1112
"github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
1213
"github.com/hashicorp/go-version"
14+
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1315
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1416
"github.com/stretchr/testify/require"
1517
)
1618

17-
var minVersionIntegration = version.Must(version.NewVersion("8.6.0"))
19+
var (
20+
minVersionIntegration = version.Must(version.NewVersion("8.6.0"))
21+
minVersionIntegrationPolicy = version.Must(version.NewVersion("8.10.0"))
22+
)
1823

1924
func TestAccResourceIntegrationFromSDK(t *testing.T) {
2025
resource.Test(t, resource.TestCase{
@@ -72,6 +77,40 @@ func TestAccResourceIntegration(t *testing.T) {
7277
})
7378
}
7479

80+
func TestAccResourceIntegrationWithPolicy(t *testing.T) {
81+
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
82+
resource.Test(t, resource.TestCase{
83+
PreCheck: func() { acctest.PreCheck(t) },
84+
ProtoV6ProviderFactories: acctest.Providers,
85+
Steps: []resource.TestStep{
86+
{
87+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
88+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.16.0"),
89+
Check: resource.ComposeTestCheckFunc(
90+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "name", "tcp"),
91+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "version", "1.16.0"),
92+
),
93+
},
94+
{
95+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
96+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.17.0"),
97+
Check: resource.ComposeTestCheckFunc(
98+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "name", "tcp"),
99+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "version", "1.17.0"),
100+
),
101+
},
102+
{
103+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
104+
ResourceName: "elasticstack_fleet_integration.test_integration",
105+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.17.0"),
106+
ImportState: true,
107+
ImportStateVerify: true,
108+
ExpectError: regexp.MustCompile("Resource Import Not Implemented"),
109+
},
110+
},
111+
})
112+
}
113+
75114
func TestAccResourceIntegrationDeleted(t *testing.T) {
76115
resource.Test(t, resource.TestCase{
77116
PreCheck: func() { acctest.PreCheck(t) },
@@ -122,6 +161,65 @@ resource "elasticstack_fleet_integration" "test_integration" {
122161
}
123162
`
124163

164+
func testAccResourceIntegrationWithPolicy(policyName, version string) string {
165+
return fmt.Sprintf(`
166+
provider "elasticstack" {
167+
elasticsearch {}
168+
kibana {}
169+
}
170+
171+
resource "elasticstack_fleet_integration" "test_integration" {
172+
name = "tcp"
173+
version = "%s"
174+
force = true
175+
skip_destroy = true
176+
}
177+
178+
// An agent policy to hold the integration policy.
179+
resource "elasticstack_fleet_agent_policy" "sample" {
180+
name = "%s"
181+
namespace = "default"
182+
description = "A sample agent policy"
183+
monitor_logs = true
184+
monitor_metrics = true
185+
skip_destroy = false
186+
}
187+
188+
// The associated enrollment token.
189+
data "elasticstack_fleet_enrollment_tokens" "sample" {
190+
policy_id = elasticstack_fleet_agent_policy.sample.policy_id
191+
}
192+
193+
// The integration policy.
194+
resource "elasticstack_fleet_integration_policy" "sample" {
195+
name = "%s"
196+
namespace = "default"
197+
description = "A sample integration policy"
198+
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
199+
integration_name = elasticstack_fleet_integration.test_integration.name
200+
integration_version = elasticstack_fleet_integration.test_integration.version
201+
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+
}
216+
}
217+
})
218+
}
219+
}
220+
`, version, policyName, policyName)
221+
}
222+
125223
const testAccResourceIntegrationDeleted = `
126224
provider "elasticstack" {
127225
elasticsearch {}

internal/fleet/integration/schema.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func (r *integrationResource) Schema(ctx context.Context, req resource.SchemaReq
2626
"version": schema.StringAttribute{
2727
Description: "The integration package version.",
2828
Required: true,
29-
PlanModifiers: []planmodifier.String{
30-
stringplanmodifier.RequiresReplace(),
31-
},
3229
},
3330
"force": schema.BoolAttribute{
3431
Description: "Set to true to force the requested action.",

0 commit comments

Comments
 (0)