@@ -20,6 +20,7 @@ import (
2020 "github.com/hashicorp/terraform-plugin-log/tflog"
2121 "log"
2222 "strings"
23+ "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
2324)
2425
2526// Ensure provider defined types fully satisfy framework interfaces.
@@ -68,11 +69,11 @@ func (r *resourceTFEDataRetentionPolicy) Schema(ctx context.Context, req resourc
6869 PlanModifiers : []planmodifier.String {
6970 stringplanmodifier .RequiresReplace (),
7071 },
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+ },
7677 },
7778 },
7879 Blocks : map [string ]schema.Block {
@@ -198,9 +199,6 @@ func (r *resourceTFEDataRetentionPolicy) createDeleteOlderThanRetentionPolicy(ct
198199 return
199200 }
200201
201- // set organization if it is still not known after creating the data retention policy
202- r .ensureOrganizationSetAfterApply (& result , & resp .Diagnostics )
203-
204202 // Save data into Terraform state
205203 diags = resp .State .Set (ctx , & result )
206204 resp .Diagnostics .Append (diags ... )
@@ -232,25 +230,11 @@ func (r *resourceTFEDataRetentionPolicy) createDontDeleteRetentionPolicy(ctx con
232230
233231 result := modelFromTFEDataRetentionPolicyDontDelete (plan , dataRetentionPolicy )
234232
235- // set organization if it is still not known after creating the data retention policy
236- r .ensureOrganizationSetAfterApply (& result , & resp .Diagnostics )
237-
238233 // Save data into Terraform state
239234 diags = resp .State .Set (ctx , & result )
240235 resp .Diagnostics .Append (diags ... )
241236}
242237
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-
254238func (r * resourceTFEDataRetentionPolicy ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
255239 var state modelTFEDataRetentionPolicy
256240
@@ -353,7 +337,6 @@ func (r *resourceTFEDataRetentionPolicy) ImportState(ctx context.Context, req re
353337 req .ID = r .getPolicyID (policy )
354338 resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("id" ), r .getPolicyID (policy ))... )
355339 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 ])... )
357340 return
358341 }
359342
0 commit comments