Skip to content

Commit bf462e7

Browse files
committed
Only require any input parameters to be specified if they differ from the defaults
1 parent 5942359 commit bf462e7

File tree

25 files changed

+3482
-210
lines changed

25 files changed

+3482
-210
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
STACK_VERSION=9.1.5
1+
STACK_VERSION=9.2.0
22
ELASTICSEARCH_CONTAINER_NAME=terraform-elasticstack-es
33
ELASTICSEARCH_PASSWORD=password
44
ELASTICSEARCH_PORT=9200

docker-compose.yml

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

docs/resources/fleet_integration_policy.md

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

112112
### Read-Only
113113

@@ -120,15 +120,36 @@ Optional:
120120

121121
- `enabled` (Boolean) Enable the input.
122122
- `streams` (Attributes Map) Input streams mapped by stream ID. (see [below for nested schema](#nestedatt--inputs--streams))
123-
- `vars` (String, Sensitive) Input-level variables as JSON.
123+
- `vars` (String) Input-level variables as JSON.
124+
125+
Read-Only:
126+
127+
- `defaults` (Attributes) Input defaults. (see [below for nested schema](#nestedatt--inputs--defaults))
124128

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

128132
Optional:
129133

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

133154
## Import
134155

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)