Skip to content

Commit

Permalink
UseStateForUnknown for agent policy ids (#885)
Browse files Browse the repository at this point in the history
* UseStateForUnknown for agent policy ids

* Changelog
  • Loading branch information
tobio authored Oct 30, 2024
1 parent 7845a51 commit 761cc7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Support multiple group by fields in SLOs ([#870](https://github.com/elastic/terraform-provider-elasticstack/pull/878))
- Use the auto-generated OAS schema from elastic/kibana for the Fleet API. ([#834](https://github.com/elastic/terraform-provider-elasticstack/issues/834))
- Support description in `elasticstack_elasticsearch_security_role` data sources. ([#884](https://github.com/elastic/terraform-provider-elasticstack/pull/884))
- Prevent spurious recreation of `elasticstack_fleet_agent_policy` resources due to 'changing' policy ids ([#885](https://github.com/elastic/terraform-provider-elasticstack/pull/885))

## [0.11.11] - 2024-10-25

Expand Down
18 changes: 18 additions & 0 deletions internal/fleet/agent_policy/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent_policy_test

import (
"context"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -62,6 +63,7 @@ func TestAccResourceAgentPolicyFromSDK(t *testing.T) {

func TestAccResourceAgentPolicy(t *testing.T) {
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
var originalPolicyId string

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Expand All @@ -78,6 +80,15 @@ func TestAccResourceAgentPolicy(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"),
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"),
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
resource.TestCheckResourceAttrWith("elasticstack_fleet_agent_policy.test_policy", "policy_id", func(value string) error {
originalPolicyId = value

if len(value) == 0 {
return errors.New("expected policy_id to be non empty")
}

return nil
}),
),
},
{
Expand All @@ -90,6 +101,13 @@ func TestAccResourceAgentPolicy(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "false"),
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "true"),
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
resource.TestCheckResourceAttrWith("elasticstack_fleet_agent_policy.test_policy", "policy_id", func(value string) error {
if value != originalPolicyId {
return fmt.Errorf("expected policy_id to not change between test steps. Was [%s], now [%s]", originalPolicyId, value)
}

return nil
}),
),
},
{
Expand Down
4 changes: 4 additions & 0 deletions internal/fleet/agent_policy/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ func (r *agentPolicyResource) Schema(ctx context.Context, req resource.SchemaReq
"id": schema.StringAttribute{
Description: "The ID of this resource.",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"policy_id": schema.StringAttribute{
Description: "Unique identifier of the agent policy.",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
},
Expand Down

0 comments on commit 761cc7c

Please sign in to comment.