@@ -18,6 +18,7 @@ type integrationPolicyModel struct {
1818 Name types.String `tfsdk:"name"`
1919 Namespace types.String `tfsdk:"namespace"`
2020 AgentPolicyID types.String `tfsdk:"agent_policy_id"`
21+ AgentPolicyIDs types.List `tfsdk:"agent_policy_ids"`
2122 Description types.String `tfsdk:"description"`
2223 Enabled types.Bool `tfsdk:"enabled"`
2324 Force types.Bool `tfsdk:"force"`
@@ -45,7 +46,38 @@ func (model *integrationPolicyModel) populateFromAPI(ctx context.Context, data *
4546 model .PolicyID = types .StringValue (data .Id )
4647 model .Name = types .StringValue (data .Name )
4748 model .Namespace = types .StringPointerValue (data .Namespace )
48- model .AgentPolicyID = types .StringPointerValue (data .PolicyId )
49+
50+ // Only populate the agent policy field that was originally configured
51+ // to avoid Terraform detecting inconsistent state
52+ originallyUsedAgentPolicyID := ! model .AgentPolicyID .IsNull () && ! model .AgentPolicyID .IsUnknown ()
53+ originallyUsedAgentPolicyIDs := ! model .AgentPolicyIDs .IsNull () && ! model .AgentPolicyIDs .IsUnknown ()
54+
55+ if originallyUsedAgentPolicyID && ! originallyUsedAgentPolicyIDs {
56+ // Only set agent_policy_id if it was originally used
57+ model .AgentPolicyID = types .StringPointerValue (data .PolicyId )
58+ } else if originallyUsedAgentPolicyIDs && ! originallyUsedAgentPolicyID {
59+ // Only set agent_policy_ids if it was originally used
60+ if data .PolicyIds != nil {
61+ agentPolicyIDs , d := types .ListValueFrom (ctx , types .StringType , * data .PolicyIds )
62+ diags .Append (d ... )
63+ model .AgentPolicyIDs = agentPolicyIDs
64+ } else {
65+ model .AgentPolicyIDs = types .ListNull (types .StringType )
66+ }
67+ } else {
68+ // Handle edge cases: both fields configured or neither configured
69+ // Default to the behavior based on API response structure
70+ if data .PolicyIds != nil && len (* data .PolicyIds ) > 1 {
71+ // Multiple policy IDs, use agent_policy_ids
72+ agentPolicyIDs , d := types .ListValueFrom (ctx , types .StringType , * data .PolicyIds )
73+ diags .Append (d ... )
74+ model .AgentPolicyIDs = agentPolicyIDs
75+ } else {
76+ // Single policy ID, use agent_policy_id
77+ model .AgentPolicyID = types .StringPointerValue (data .PolicyId )
78+ }
79+ }
80+
4981 model .Description = types .StringPointerValue (data .Description )
5082 model .Enabled = types .BoolValue (data .Enabled )
5183 model .IntegrationName = types .StringValue (data .Package .Name )
@@ -94,7 +126,18 @@ func (model integrationPolicyModel) toAPIModel(ctx context.Context, isUpdate boo
94126 Version : model .IntegrationVersion .ValueString (),
95127 },
96128 PolicyId : model .AgentPolicyID .ValueStringPointer (),
97- Vars : utils .MapRef (utils .NormalizedTypeToMap [any ](model .VarsJson , path .Root ("vars_json" ), & diags )),
129+ PolicyIds : func () * []string {
130+ if ! model .AgentPolicyIDs .IsNull () && ! model .AgentPolicyIDs .IsUnknown () {
131+ var policyIDs []string
132+ d := model .AgentPolicyIDs .ElementsAs (ctx , & policyIDs , false )
133+ diags .Append (d ... )
134+ return & policyIDs
135+ }
136+ // Return empty array instead of nil when agent_policy_ids is not defined
137+ emptyArray := []string {}
138+ return & emptyArray
139+ }(),
140+ Vars : utils .MapRef (utils .NormalizedTypeToMap [any ](model .VarsJson , path .Root ("vars_json" ), & diags )),
98141 }
99142
100143 if isUpdate {
0 commit comments