@@ -2,6 +2,7 @@ package agent_policy
22
33import (
44 "context"
5+ "fmt"
56 "slices"
67
78 "github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
@@ -36,7 +37,7 @@ type agentPolicyModel struct {
3637 GlobalDataTags types.Map `tfsdk:"global_data_tags"` //> globalDataTagsModel
3738}
3839
39- func (model * agentPolicyModel ) populateFromAPI (ctx context.Context , data * kbapi.AgentPolicy , serverVersion * version. Version ) diag.Diagnostics {
40+ func (model * agentPolicyModel ) populateFromAPI (ctx context.Context , data * kbapi.AgentPolicy ) diag.Diagnostics {
4041 if data == nil {
4142 return nil
4243 }
@@ -121,18 +122,12 @@ func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersi
121122 if len (model .GlobalDataTags .Elements ()) > 0 {
122123 var diags diag.Diagnostics
123124 if serverVersion .LessThan (MinVersionGlobalDataTags ) {
124- diags .AddError ("global_data_tags ES version error" , "Global data tags are only supported in Elastic Stack 8.15.0 and above" )
125+ diags .AddError ("global_data_tags ES version error" , fmt . Sprintf ( "Global data tags are only supported in Elastic Stack %s and above" , MinVersionGlobalDataTags ) )
125126 return kbapi.PostFleetAgentPoliciesJSONRequestBody {}, diags
126127 }
127128
128129 items := utils .MapTypeToMap (ctx , model .GlobalDataTags , path .Root ("global_data_tags" ), & diags ,
129130 func (item globalDataTagsItemModel , meta utils.MapMeta ) kbapi.AgentPolicyGlobalDataTagsItem {
130- // do some checks
131- if item .StringValue .ValueStringPointer () == nil && item .NumberValue .ValueFloat32Pointer () == nil || item .StringValue .ValueStringPointer () != nil && item .NumberValue .ValueFloat32Pointer () != nil {
132- diags .AddError ("global_data_tags validation_error" , "Global data tags must have exactly one of string_value or number_value" )
133- return kbapi.AgentPolicyGlobalDataTagsItem {}
134- }
135-
136131 var value kbapi.AgentPolicyGlobalDataTagsItem_Value
137132 var err error
138133 if item .StringValue .ValueStringPointer () != nil {
@@ -187,17 +182,12 @@ func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, serverVersi
187182 if len (model .GlobalDataTags .Elements ()) > 0 {
188183 var diags diag.Diagnostics
189184 if serverVersion .LessThan (MinVersionGlobalDataTags ) {
190- diags .AddError ("global_data_tags ES version error" , "Global data tags are only supported in Elastic Stack 8.15.0 and above" )
185+ diags .AddError ("global_data_tags ES version error" , fmt . Sprintf ( "Global data tags are only supported in Elastic Stack %s and above" , MinVersionGlobalDataTags ) )
191186 return kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody {}, diags
192187 }
193188
194189 items := utils .MapTypeToMap (ctx , model .GlobalDataTags , path .Root ("global_data_tags" ), & diags ,
195190 func (item globalDataTagsItemModel , meta utils.MapMeta ) kbapi.AgentPolicyGlobalDataTagsItem {
196- // do some checks
197- if item .StringValue .ValueStringPointer () == nil && item .NumberValue .ValueFloat32Pointer () == nil || item .StringValue .ValueStringPointer () != nil && item .NumberValue .ValueFloat32Pointer () != nil {
198- diags .AddError ("global_data_tags validation_error" , "Global data tags must have exactly one of string_value or number_value" )
199- return kbapi.AgentPolicyGlobalDataTagsItem {}
200- }
201191
202192 var value kbapi.AgentPolicyGlobalDataTagsItem_Value
203193 var err error
0 commit comments