@@ -65,35 +65,21 @@ func modelFromTFETeamNotificationConfiguration(v *tfe.NotificationConfiguration)
65
65
TeamID : types .StringValue (v .SubscribableChoice .Team .ID ),
66
66
}
67
67
68
- emailAddresses := make ([]attr.Value , len (v .EmailAddresses ))
69
- for i , emailAddress := range v .EmailAddresses {
70
- emailAddresses [i ] = types .StringValue (emailAddress )
68
+ if emailAddresses , err := types .SetValueFrom (ctx , types .StringType , v .EmailAddresses ); err == nil {
69
+ result .EmailAddresses = emailAddresses
71
70
}
72
- if len (emailAddresses ) > 0 {
73
- result .EmailAddresses = types .SetValueMust (types .StringType , emailAddresses )
74
- } else {
75
- result .EmailAddresses = types .SetNull (types .StringType )
71
+
72
+ if len (v .Triggers ) == 0 {
73
+ result .Triggers = types .SetNull (types .StringType )
74
+ } else if triggers , err := types .SetValueFrom (ctx , types .StringType , v .Triggers ); err == nil {
75
+ result .Triggers = triggers
76
76
}
77
77
78
78
emailUserIDs := make ([]attr.Value , len (v .EmailUsers ))
79
79
for i , emailUser := range v .EmailUsers {
80
80
emailUserIDs [i ] = types .StringValue (emailUser .ID )
81
81
}
82
- if len (emailUserIDs ) > 0 {
83
- result .EmailUserIDs = types .SetValueMust (types .StringType , emailUserIDs )
84
- } else {
85
- result .EmailUserIDs = types .SetNull (types .StringType )
86
- }
87
-
88
- triggers := make ([]attr.Value , len (v .Triggers ))
89
- for i , trigger := range v .Triggers {
90
- triggers [i ] = types .StringValue (trigger )
91
- }
92
- if len (v .Triggers ) > 0 {
93
- result .Triggers = types .SetValueMust (types .StringType , triggers )
94
- } else {
95
- result .Triggers = types .SetNull (types .StringType )
96
- }
82
+ result .EmailUserIDs = types .SetValueMust (types .StringType , emailUserIDs )
97
83
98
84
if v .Token != "" {
99
85
result .Token = types .StringValue (v .Token )
@@ -147,14 +133,10 @@ func (r *resourceTFETeamNotificationConfiguration) Schema(ctx context.Context, r
147
133
Computed : true ,
148
134
ElementType : types .StringType ,
149
135
Validators : []validator.Set {
150
- validators .AttributeValueConflictSetValidator (
136
+ validators .AttributeValueConflictValidator (
151
137
"destination_type" ,
152
138
[]string {"generic" , "microsoft-teams" , "slack" },
153
139
),
154
- setvalidator .ConflictsWith (
155
- path .MatchRelative ().AtParent ().AtName ("token" ),
156
- path .MatchRelative ().AtParent ().AtName ("url" ),
157
- ),
158
140
},
159
141
},
160
142
@@ -164,14 +146,10 @@ func (r *resourceTFETeamNotificationConfiguration) Schema(ctx context.Context, r
164
146
Computed : true ,
165
147
ElementType : types .StringType ,
166
148
Validators : []validator.Set {
167
- validators .AttributeValueConflictSetValidator (
149
+ validators .AttributeValueConflictValidator (
168
150
"destination_type" ,
169
151
[]string {"generic" , "microsoft-teams" , "slack" },
170
152
),
171
- setvalidator .ConflictsWith (
172
- path .MatchRelative ().AtParent ().AtName ("token" ),
173
- path .MatchRelative ().AtParent ().AtName ("url" ),
174
- ),
175
153
},
176
154
},
177
155
@@ -187,7 +165,7 @@ func (r *resourceTFETeamNotificationConfiguration) Schema(ctx context.Context, r
187
165
Optional : true ,
188
166
Sensitive : true ,
189
167
Validators : []validator.String {
190
- validators .AttributeValueConflictStringValidator (
168
+ validators .AttributeValueConflictValidator (
191
169
"destination_type" ,
192
170
[]string {"email" , "microsoft-teams" , "slack" },
193
171
),
@@ -215,7 +193,7 @@ func (r *resourceTFETeamNotificationConfiguration) Schema(ctx context.Context, r
215
193
"destination_type" ,
216
194
[]string {"generic" , "microsoft-teams" , "slack" },
217
195
),
218
- validators .AttributeValueConflictStringValidator (
196
+ validators .AttributeValueConflictValidator (
219
197
"destination_type" ,
220
198
[]string {"email" },
221
199
),
@@ -264,10 +242,6 @@ func (r *resourceTFETeamNotificationConfiguration) Create(ctx context.Context, r
264
242
return
265
243
}
266
244
267
- if resp .Diagnostics .HasError () {
268
- return
269
- }
270
-
271
245
// Get team
272
246
teamID := plan .TeamID .ValueString ()
273
247
@@ -295,11 +269,12 @@ func (r *resourceTFETeamNotificationConfiguration) Create(ctx context.Context, r
295
269
}
296
270
297
271
// Add email_addresses set to the options struct
298
- emailAddresses := make ([]types.String , len ( plan . EmailAddresses . Elements ()) )
272
+ emailAddresses := make ([]types.String , 0 )
299
273
if diags := plan .EmailAddresses .ElementsAs (ctx , & emailAddresses , true ); diags != nil && diags .HasError () {
300
274
resp .Diagnostics .Append (diags ... )
301
275
return
302
276
}
277
+
303
278
options .EmailAddresses = []string {}
304
279
for _ , emailAddress := range emailAddresses {
305
280
options .EmailAddresses = append (options .EmailAddresses , emailAddress .ValueString ())
@@ -321,6 +296,8 @@ func (r *resourceTFETeamNotificationConfiguration) Create(ctx context.Context, r
321
296
if err != nil {
322
297
resp .Diagnostics .AddError ("Unable to create team notification configuration" , err .Error ())
323
298
return
299
+ } else if len (tnc .EmailUsers ) != len (plan .EmailUserIDs .Elements ()) {
300
+ resp .Diagnostics .AddError ("Email user IDs produced an inconsistent result" , "API returned a different number of email user IDs than were provided in the plan." )
324
301
}
325
302
326
303
// Restore token from plan because it is write only
@@ -385,7 +362,7 @@ func (r *resourceTFETeamNotificationConfiguration) Update(ctx context.Context, r
385
362
}
386
363
387
364
// Add triggers set to the options struct
388
- triggers := make ([]types.String , len ( plan . Triggers . Elements ()) )
365
+ triggers := make ([]types.String , 0 )
389
366
if diags := plan .Triggers .ElementsAs (ctx , & triggers , true ); diags != nil && diags .HasError () {
390
367
resp .Diagnostics .Append (diags ... )
391
368
return
@@ -396,7 +373,7 @@ func (r *resourceTFETeamNotificationConfiguration) Update(ctx context.Context, r
396
373
}
397
374
398
375
// Add email_addresses set to the options struct
399
- emailAddresses := make ([]types.String , len ( plan . EmailAddresses . Elements ()) )
376
+ emailAddresses := make ([]types.String , 0 )
400
377
if diags := plan .EmailAddresses .ElementsAs (ctx , & emailAddresses , true ); diags != nil && diags .HasError () {
401
378
resp .Diagnostics .Append (diags ... )
402
379
return
@@ -407,7 +384,7 @@ func (r *resourceTFETeamNotificationConfiguration) Update(ctx context.Context, r
407
384
}
408
385
409
386
// Add email_user_ids set to the options struct
410
- emailUserIDs := make ([]types.String , len ( plan . EmailUserIDs . Elements ()) )
387
+ emailUserIDs := make ([]types.String , 0 )
411
388
if diags := plan .EmailUserIDs .ElementsAs (ctx , & emailUserIDs , true ); diags != nil && diags .HasError () {
412
389
resp .Diagnostics .Append (diags ... )
413
390
return
@@ -422,6 +399,8 @@ func (r *resourceTFETeamNotificationConfiguration) Update(ctx context.Context, r
422
399
if err != nil {
423
400
resp .Diagnostics .AddError ("Unable to update team notification configuration" , err .Error ())
424
401
return
402
+ } else if len (tnc .EmailUsers ) != len (plan .EmailUserIDs .Elements ()) {
403
+ resp .Diagnostics .AddError ("Email user IDs produced an inconsistent result" , "API returned a different number of email user IDs than were provided in the plan." )
425
404
}
426
405
427
406
// Restore token from plan because it is write only
0 commit comments