Skip to content

Commit 1876e8e

Browse files
committed
Only require any input parameters to be specified if they differ from the defaults
1 parent 2a5d5bf commit 1876e8e

File tree

24 files changed

+3472
-232
lines changed

24 files changed

+3472
-232
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ services:
6666
ELASTICSEARCH_PASSWORD: ${KIBANA_PASSWORD}
6767
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: ${KIBANA_ENCRYPTION_KEY}
6868
ELASTICSEARCH_PUBLICBASEURL: http://localhost:${ELASTICSEARCH_PORT}
69+
SERVER_OAS_ENABLED: true
6970
healthcheck:
7071
test:
7172
[

docs/resources/fleet_integration_policy.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ resource "elasticstack_fleet_integration_policy" "sample" {
109109
- `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.
110110
- `policy_id` (String) Unique identifier of the integration policy.
111111
- `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.
112-
- `vars_json` (String, Sensitive) Integration-level variables as JSON.
112+
- `vars_json` (String) Integration-level variables as JSON.
113113

114114
### Read-Only
115115

@@ -122,15 +122,36 @@ Optional:
122122

123123
- `enabled` (Boolean) Enable the input.
124124
- `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.
125+
- `vars` (String) Input-level variables as JSON.
126+
127+
Read-Only:
128+
129+
- `defaults` (Attributes) Input defaults. (see [below for nested schema](#nestedatt--inputs--defaults))
126130

127131
<a id="nestedatt--inputs--streams"></a>
128132
### Nested Schema for `inputs.streams`
129133

130134
Optional:
131135

132136
- `enabled` (Boolean) Enable the stream.
133-
- `vars` (String, Sensitive) Stream-level variables as JSON.
137+
- `vars` (String) Stream-level variables as JSON.
138+
139+
140+
<a id="nestedatt--inputs--defaults"></a>
141+
### Nested Schema for `inputs.defaults`
142+
143+
Read-Only:
144+
145+
- `streams` (Attributes Map) Stream-level defaults mapped by stream ID. (see [below for nested schema](#nestedatt--inputs--defaults--streams))
146+
- `vars` (String) Input-level variable defaults as JSON.
147+
148+
<a id="nestedatt--inputs--defaults--streams"></a>
149+
### Nested Schema for `inputs.defaults.streams`
150+
151+
Read-Only:
152+
153+
- `enabled` (Boolean) Default enabled state for the stream.
154+
- `vars` (String) Stream-level variable defaults as JSON.
134155

135156
## Import
136157

internal/fleet/integration_policy/acc_test.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,14 @@ func TestAccResourceIntegrationPolicySecrets(t *testing.T) {
276276
"policy_name": config.StringVariable(policyName),
277277
"secret_key": config.StringVariable("updated"),
278278
},
279-
ImportState: true,
280-
ImportStateVerify: true,
281-
ImportStateVerifyIgnore: []string{"vars_json", "space_ids"},
279+
ImportState: true,
280+
ImportStateVerify: true,
281+
ImportStateVerifyIgnore: []string{
282+
"vars_json",
283+
"space_ids",
284+
"inputs.aws_logs-aws-cloudwatch.defaults",
285+
"inputs.aws_logs-aws-s3.defaults",
286+
},
282287
Check: resource.ComposeTestCheckFunc(
283288
resource.TestMatchResourceAttr("elasticstack_fleet_integration_policy.test_policy", "vars_json", regexp.MustCompile(`{"access_key_id":{"id":"\S+","isSecretRef":true},"default_region":"us-east-2","endpoint":"endpoint","secret_access_key":{"id":"\S+","isSecretRef":true},"session_token":{"id":"\S+","isSecretRef":true}}`)),
284289
),
@@ -398,6 +403,40 @@ func TestAccIntegrationPolicyInputs(t *testing.T) {
398403
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-logfile.enabled", "false"),
399404
),
400405
},
406+
{
407+
ProtoV6ProviderFactories: acctest.Providers,
408+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
409+
ConfigDirectory: acctest.NamedTestCaseDirectory("minimal"),
410+
ConfigVariables: config.Variables{
411+
"policy_name": config.StringVariable(policyName),
412+
},
413+
Check: resource.ComposeTestCheckFunc(
414+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "name", policyName),
415+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "description", "Kafka Integration Policy - Minimal"),
416+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "integration_name", "kafka"),
417+
// Check specified inputs
418+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-logfile.enabled", "false"),
419+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-kafka/metrics.enabled", "true"),
420+
// Check unspecified, disabled by default input
421+
resource.TestCheckNoResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-jolokia/metrics"),
422+
),
423+
},
424+
{
425+
ProtoV6ProviderFactories: acctest.Providers,
426+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
427+
ConfigDirectory: acctest.NamedTestCaseDirectory("unset"),
428+
ConfigVariables: config.Variables{
429+
"policy_name": config.StringVariable(policyName),
430+
},
431+
Check: resource.ComposeTestCheckFunc(
432+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "name", policyName),
433+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "description", "Kafka Integration Policy - Minimal"),
434+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "integration_name", "kafka"),
435+
// Check previously specified inputs
436+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-logfile.enabled", "false"),
437+
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "inputs.kafka-kafka/metrics.enabled", "true"),
438+
),
439+
},
401440
},
402441
})
403442
}

internal/fleet/integration_policy/create.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ func (r *integrationPolicyResource) Create(ctx context.Context, req resource.Cre
6767
// Remember if the user configured input in the plan
6868
planHadInput := utils.IsKnown(planModel.Inputs) && !planModel.Inputs.IsNull() && len(planModel.Inputs.Elements()) > 0
6969

70-
diags = planModel.populateFromAPI(ctx, policy)
70+
pkg, diags := fleet.GetPackage(ctx, client, policy.Package.Name, policy.Package.Version)
71+
resp.Diagnostics.Append(diags...)
72+
if resp.Diagnostics.HasError() {
73+
return
74+
}
75+
76+
diags = planModel.populateFromAPI(ctx, pkg, policy)
7177
resp.Diagnostics.Append(diags...)
7278
if resp.Diagnostics.HasError() {
7379
return
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package integration_policy
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/attr"
7+
"github.com/hashicorp/terraform-plugin-framework/diag"
8+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
9+
"github.com/hashicorp/terraform-plugin-go/tftypes"
10+
)
11+
12+
var (
13+
_ basetypes.ObjectTypable = (*InputType)(nil)
14+
_ basetypes.ObjectValuableWithSemanticEquals = (*InputValue)(nil)
15+
)
16+
17+
// InputType is a custom type for an individual input that supports semantic equality
18+
type InputType struct {
19+
basetypes.ObjectType
20+
}
21+
22+
// String returns a human readable string of the type name.
23+
func (t InputType) String() string {
24+
return "integration_policy.InputType"
25+
}
26+
27+
// ValueType returns the Value type.
28+
func (t InputType) ValueType(ctx context.Context) attr.Value {
29+
return InputValue{
30+
ObjectValue: basetypes.NewObjectUnknown(t.AttributeTypes()),
31+
}
32+
}
33+
34+
// Equal returns true if the given type is equivalent.
35+
func (t InputType) Equal(o attr.Type) bool {
36+
other, ok := o.(InputType)
37+
if !ok {
38+
return false
39+
}
40+
return t.ObjectType.Equal(other.ObjectType)
41+
}
42+
43+
// ValueFromObject returns an ObjectValuable type given a basetypes.ObjectValue.
44+
func (t InputType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) {
45+
return InputValue{
46+
ObjectValue: in,
47+
}, nil
48+
}
49+
50+
// ValueFromTerraform returns a Value given a tftypes.Value.
51+
func (t InputType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
52+
attrValue, err := t.ObjectType.ValueFromTerraform(ctx, in)
53+
if err != nil {
54+
return nil, err
55+
}
56+
57+
objectValue, ok := attrValue.(basetypes.ObjectValue)
58+
if !ok {
59+
return nil, err
60+
}
61+
62+
return InputValue{
63+
ObjectValue: objectValue,
64+
}, nil
65+
}
66+
67+
// NewInputType creates a new InputType with the given attribute types
68+
func NewInputType(attrTypes map[string]attr.Type) InputType {
69+
return InputType{
70+
ObjectType: basetypes.ObjectType{
71+
AttrTypes: attrTypes,
72+
},
73+
}
74+
}

0 commit comments

Comments
 (0)