@@ -3,6 +3,9 @@ package provider
3
3
import (
4
4
"context"
5
5
6
+ "github.com/hashicorp/terraform-plugin-framework/path"
7
+ "github.com/hashicorp/terraform-plugin-framework/resource"
8
+ "github.com/hashicorp/terraform-plugin-framework/types"
6
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7
10
)
8
11
@@ -13,11 +16,30 @@ func customizeDiffIfProviderDefaultOrganizationChanged(c context.Context, diff *
13
16
plannedOrg := diff .Get ("organization" ).(string )
14
17
15
18
if configOrg .IsNull () && config .Organization != plannedOrg {
16
- // There is no organization configured on the resource, yet it is different from
17
- // the state organization. We must conclude that the provider default organization changed.
19
+ // There is no organization configured on the resource, yet the provider org is different from
20
+ // the planned organization. We must conclude that the provider default organization changed.
18
21
if err := diff .SetNew ("organization" , config .Organization ); err != nil {
19
22
return err
20
23
}
21
24
}
22
25
return nil
23
26
}
27
+
28
+ func modifyPlanForDefaultOrganizationChange (ctx context.Context , providerDefaultOrg string , req resource.ModifyPlanRequest , resp * resource.ModifyPlanResponse ) {
29
+ if req .State .Raw .IsNull () {
30
+ return
31
+ }
32
+
33
+ orgPath := path .Root ("organization" )
34
+
35
+ var configOrg , plannedOrg * string
36
+ resp .Diagnostics .Append (req .Config .GetAttribute (ctx , orgPath , & configOrg )... )
37
+ resp .Diagnostics .Append (req .Plan .GetAttribute (ctx , orgPath , & plannedOrg )... )
38
+
39
+ if configOrg == nil && plannedOrg != nil && providerDefaultOrg != * plannedOrg {
40
+ // There is no organization configured on the resource, yet the provider org is different from
41
+ // the planned organization value. We must conclude that the provider default organization changed.
42
+ resp .Plan .SetAttribute (ctx , orgPath , types .StringValue (providerDefaultOrg ))
43
+ resp .RequiresReplace .Append (orgPath )
44
+ }
45
+ }
0 commit comments