Skip to content

Commit a84e867

Browse files
committed
deref
1 parent edb3613 commit a84e867

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

internal/fleet/agent_policy/models.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package agent_policy
22

33
import (
44
"context"
5-
"reflect"
65
"slices"
76

87
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
@@ -32,18 +31,6 @@ func newGlobalDataTagModel(data struct {
3231
}
3332
}
3433

35-
func hasKey(s interface{}, key string) bool {
36-
val := reflect.ValueOf(s)
37-
if val.Kind() == reflect.Ptr {
38-
val = val.Elem()
39-
}
40-
if val.Kind() != reflect.Struct {
41-
return false
42-
}
43-
field := val.FieldByName(key)
44-
return field.IsValid()
45-
}
46-
4734
type agentPolicyModel struct {
4835
ID types.String `tfsdk:"id"`
4936
PolicyID types.String `tfsdk:"policy_id"`
@@ -91,20 +78,17 @@ func (model *agentPolicyModel) populateFromAPI(ctx context.Context, data *kbapi.
9178
model.MonitoringOutputId = types.StringPointerValue(data.MonitoringOutputId)
9279
model.Name = types.StringValue(data.Name)
9380
model.Namespace = types.StringValue(data.Namespace)
94-
if serverVersion.GreaterThanOrEqual(MinVersionGlobalDataTags) && hasKey(data, "GlobalDataTags") {
95-
var diag diag.Diagnostics
81+
if serverVersion.GreaterThanOrEqual(MinVersionGlobalDataTags) && utils.Deref(data.GlobalDataTags) != nil {
82+
9683
gdt := []globalDataTagModel{}
97-
for _, val := range *data.GlobalDataTags {
84+
for _, val := range utils.Deref(data.GlobalDataTags) {
9885
gdt = append(gdt, newGlobalDataTagModel(val))
9986
}
10087
gdtList, diags := types.ListValueFrom(ctx, getGlobalDataTagsType(), gdt)
10188
if diags.HasError() {
10289
return
10390
}
10491
model.GlobalDataTags = gdtList
105-
if diag.HasError() {
106-
return
107-
}
10892
}
10993
}
11094

0 commit comments

Comments
 (0)