Skip to content

Conversation

@tobio
Copy link
Member

@tobiotobio commented Dec 16, 2025

Related to #617
Fixes#1415
Fixes#889

This PR aims to allow users to only provide streams/vars for integration policies where they differ from the defaults for a specific integration. In reality, users have been attempting to do just that, but hitting some form of inconsistent state error. These errors should no longer occur as we're taking into account the integration defaults when comparing the user config and the API derived state.

@tobiotobio requested a review from dimuonDecember 16, 2025 10:50
@tobiotobio self-assigned this Dec 16, 2025
CopilotAI review requested due to automatic review settings December 16, 2025 10:50
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Fleet integration policy resource to intelligently handle integration defaults, allowing users to specify only parameters that differ from defaults rather than requiring full configuration. The implementation adds a defaults attribute to track integration-specific default values and implements semantic equality comparison that considers these defaults when determining configuration drift.

Key Changes:

  • Implemented default value tracking and application through a new defaults computed attribute
  • Enhanced semantic equality logic to compare user configuration against defaults before detecting changes
  • Removed requirement to specify all inputs/streams in configuration

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
internal/fleet/integration_policy/update.goFetches package info to populate defaults during update operations
internal/fleet/integration_policy/testdata/integration_kafka.jsonAdds Kafka integration test data for testing default value handling
internal/fleet/integration_policy/testdata/.../update_logfile_tags_only/integration_policy.tfTest case for partial configuration specifying only non-default values
internal/fleet/integration_policy/testdata/.../unset/integration_policy.tfTest case for minimal configuration without explicit inputs
internal/fleet/integration_policy/testdata/.../minimal/integration_policy.tfTest case for minimal configuration with only essential inputs
internal/fleet/integration_policy/schema_v1.goSets defaults to null during v1 to v2 migration
internal/fleet/integration_policy/schema.goAdds defaults attribute and plan modifiers for state management
internal/fleet/integration_policy/resource-description.mdUpdates documentation to remove recommendation to specify all inputs
internal/fleet/integration_policy/read.goFetches package info during read operations
internal/fleet/integration_policy/models_test.goUpdates test to pass nil package info
internal/fleet/integration_policy/models_defaults_test.goComprehensive tests for default value extraction and application
internal/fleet/integration_policy/models_defaults.goCore logic for extracting defaults from package metadata
internal/fleet/integration_policy/models.goIntegrates defaults into model population and API conversion
internal/fleet/integration_policy/inputs_value_test.goUpdates tests to handle defaults in equality checks
internal/fleet/integration_policy/inputs_value.goImplements semantic equality using defaults for inputs
internal/fleet/integration_policy/inputs_type.goUpdates type signature to use InputType
internal/fleet/integration_policy/input_value_test.goTests for input-level semantic equality with defaults
internal/fleet/integration_policy/input_value.goImplements semantic equality logic for individual inputs
internal/fleet/integration_policy/input_type.goDefines custom type supporting semantic equality for inputs
internal/fleet/integration_policy/create.goFetches package info during create operations
internal/fleet/integration_policy/acc_test.goAdds acceptance tests for partial and minimal configurations
docs/resources/fleet_integration_policy.mdUpdates resource documentation to reflect new behavior

},
"streams": schema.MapNestedAttribute{
Description: "Input streams mapped by stream ID.",
Optional: true,
Copy link

CopilotAIDec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The streams attribute is now optional-only (no longer computed), but there's no default value specified. Consider whether a default should be added for consistency with the previous schema behavior, or document why the computed+default was intentionally removed.

Suggested change
Optional: true,
Optional: true,
Default: objectdefault.StaticValue(basetypes.NewMapNull(types.ObjectType{AttrTypes: getInputStreamNestedObject(varsAreSensitive).Attributes})),

Copilot uses AI. Check for mistakes.
body.Inputs=utils.MapRef(model.toAPIInputsFromInputsAttribute(ctx, &diags))
}

body.Inputs=model.toAPIInputsFromInputsAttribute(ctx, &diags)
Copy link

CopilotAIDec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function now always returns a pointer to a map, but the previous logic conditionally set body.Inputs only when inputs were known and non-empty. This change means empty inputs {} will always be sent to the API. Verify this is the intended behavior and doesn't cause issues with the Fleet API.

Suggested change
body.Inputs=model.toAPIInputsFromInputsAttribute(ctx, &diags)
inputs:=model.toAPIInputsFromInputsAttribute(ctx, &diags)
ifinputs!=nil&&len(*inputs) >0{
body.Inputs=inputs
}

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +61
for_, stream:=rangeinput.Streams.Elements(){
streamModel:=integrationPolicyInputStreamModel{}
d:=stream.(types.Object).As(ctx, &streamModel, basetypes.ObjectAsOptions{})
Copy link

CopilotAIDec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type assertion stream.(types.Object) could panic if the element is not a types.Object. Consider adding a type check before the assertion or using the comma-ok idiom to safely handle unexpected types.

Suggested change
for_, stream:=rangeinput.Streams.Elements(){
streamModel:=integrationPolicyInputStreamModel{}
d:=stream.(types.Object).As(ctx, &streamModel, basetypes.ObjectAsOptions{})
fori, stream:=rangeinput.Streams.Elements(){
streamModel:=integrationPolicyInputStreamModel{}
obj, ok:=stream.(types.Object)
if!ok{
diags.AddError(
fmt.Sprintf("Unexpected stream type at index %d", i),
fmt.Sprintf("Expected types.Object, got %T", stream),
)
returnfalse, diags
}
d:=obj.As(ctx, &streamModel, basetypes.ObjectAsOptions{})

Copilot uses AI. Check for mistakes.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants

@tobio