@@ -20,6 +20,7 @@ import (
20
20
"github.com/hashicorp/terraform-plugin-log/tflog"
21
21
"log"
22
22
"strings"
23
+ "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
23
24
)
24
25
25
26
// Ensure provider defined types fully satisfy framework interfaces.
@@ -68,11 +69,11 @@ func (r *resourceTFEDataRetentionPolicy) Schema(ctx context.Context, req resourc
68
69
PlanModifiers : []planmodifier.String {
69
70
stringplanmodifier .RequiresReplace (),
70
71
},
71
- // Validators: []validator.String{
72
- // stringvalidator.ExactlyOneOf (
73
- // path.MatchRelative().AtParent().AtName("organization"),
74
- // ),
75
- // },
72
+ Validators : []validator.String {
73
+ stringvalidator .ConflictsWith (
74
+ path .MatchRelative ().AtParent ().AtName ("organization" ),
75
+ ),
76
+ },
76
77
},
77
78
},
78
79
Blocks : map [string ]schema.Block {
@@ -198,9 +199,6 @@ func (r *resourceTFEDataRetentionPolicy) createDeleteOlderThanRetentionPolicy(ct
198
199
return
199
200
}
200
201
201
- // set organization if it is still not known after creating the data retention policy
202
- r .ensureOrganizationSetAfterApply (& result , & resp .Diagnostics )
203
-
204
202
// Save data into Terraform state
205
203
diags = resp .State .Set (ctx , & result )
206
204
resp .Diagnostics .Append (diags ... )
@@ -232,25 +230,11 @@ func (r *resourceTFEDataRetentionPolicy) createDontDeleteRetentionPolicy(ctx con
232
230
233
231
result := modelFromTFEDataRetentionPolicyDontDelete (plan , dataRetentionPolicy )
234
232
235
- // set organization if it is still not known after creating the data retention policy
236
- r .ensureOrganizationSetAfterApply (& result , & resp .Diagnostics )
237
-
238
233
// Save data into Terraform state
239
234
diags = resp .State .Set (ctx , & result )
240
235
resp .Diagnostics .Append (diags ... )
241
236
}
242
237
243
- func (r * resourceTFEDataRetentionPolicy ) ensureOrganizationSetAfterApply (policy * modelTFEDataRetentionPolicy , diags * diag.Diagnostics ) {
244
- if policy .Organization .IsUnknown () {
245
- workspace , err := r .config .Client .Workspaces .ReadByID (ctx , policy .WorkspaceID .ValueString ())
246
- if err != nil {
247
- diags .AddError ("Unable to create data retention policy" , err .Error ())
248
- return
249
- }
250
- policy .Organization = types .StringValue (workspace .Organization .Name )
251
- }
252
- }
253
-
254
238
func (r * resourceTFEDataRetentionPolicy ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
255
239
var state modelTFEDataRetentionPolicy
256
240
@@ -353,7 +337,6 @@ func (r *resourceTFEDataRetentionPolicy) ImportState(ctx context.Context, req re
353
337
req .ID = r .getPolicyID (policy )
354
338
resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("id" ), r .getPolicyID (policy ))... )
355
339
resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("workspace_id" ), workspaceID )... )
356
- resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("organization" ), s [0 ])... )
357
340
return
358
341
}
359
342
0 commit comments