Skip to content

Commit 171e82f

Browse files
committed
Don't force replacement when changing integration versions
1 parent 6b2db46 commit 171e82f

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

generated/kbapi/kibana.gen.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 72 additions & 2 deletions
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,6 +11,7 @@ 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
)
@@ -48,22 +50,31 @@ func TestAccResourceIntegrationFromSDK(t *testing.T) {
4850
}
4951

5052
func TestAccResourceIntegration(t *testing.T) {
53+
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
5154
resource.Test(t, resource.TestCase{
5255
PreCheck: func() { acctest.PreCheck(t) },
5356
ProtoV6ProviderFactories: acctest.Providers,
5457
Steps: []resource.TestStep{
5558
{
5659
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegration),
57-
Config: testAccResourceIntegration,
60+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.16.0"),
5861
Check: resource.ComposeTestCheckFunc(
5962
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "name", "tcp"),
6063
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "version", "1.16.0"),
6164
),
6265
},
66+
{
67+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegration),
68+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.17.0"),
69+
Check: resource.ComposeTestCheckFunc(
70+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "name", "tcp"),
71+
resource.TestCheckResourceAttr("elasticstack_fleet_integration.test_integration", "version", "1.17.0"),
72+
),
73+
},
6374
{
6475
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegration),
6576
ResourceName: "elasticstack_fleet_integration.test_integration",
66-
Config: testAccResourceIntegration,
77+
Config: testAccResourceIntegrationWithPolicy(policyName, "1.17.0"),
6778
ImportState: true,
6879
ImportStateVerify: true,
6980
ExpectError: regexp.MustCompile("Resource Import Not Implemented"),
@@ -122,6 +133,65 @@ resource "elasticstack_fleet_integration" "test_integration" {
122133
}
123134
`
124135

136+
func testAccResourceIntegrationWithPolicy(policyName, version string) string {
137+
return fmt.Sprintf(`
138+
provider "elasticstack" {
139+
elasticsearch {}
140+
kibana {}
141+
}
142+
143+
resource "elasticstack_fleet_integration" "test_integration" {
144+
name = "tcp"
145+
version = "%s"
146+
force = true
147+
skip_destroy = true
148+
}
149+
150+
// An agent policy to hold the integration policy.
151+
resource "elasticstack_fleet_agent_policy" "sample" {
152+
name = "%s"
153+
namespace = "default"
154+
description = "A sample agent policy"
155+
monitor_logs = true
156+
monitor_metrics = true
157+
skip_destroy = false
158+
}
159+
160+
// The associated enrollment token.
161+
data "elasticstack_fleet_enrollment_tokens" "sample" {
162+
policy_id = elasticstack_fleet_agent_policy.sample.policy_id
163+
}
164+
165+
// The integration policy.
166+
resource "elasticstack_fleet_integration_policy" "sample" {
167+
name = "%s"
168+
namespace = "default"
169+
description = "A sample integration policy"
170+
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
171+
integration_name = elasticstack_fleet_integration.test_integration.name
172+
integration_version = elasticstack_fleet_integration.test_integration.version
173+
174+
input {
175+
input_id = "tcp-tcp"
176+
streams_json = jsonencode({
177+
"tcp.generic" : {
178+
"enabled" : true,
179+
"vars" : {
180+
"listen_address" : "localhost",
181+
"listen_port" : 8080,
182+
"data_stream.dataset" : "tcp.generic",
183+
"tags" : [],
184+
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
185+
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
186+
"custom" : ""
187+
}
188+
}
189+
})
190+
}
191+
}
192+
`, version, policyName, policyName)
193+
}
194+
125195
const testAccResourceIntegrationDeleted = `
126196
provider "elasticstack" {
127197
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)