Skip to content

Commit 07992d3

Browse files
kenchan0130Tadayuki Onishi
authored andcommitted
debug
Signed-off-by: kenchan0130 <1155067+kenchan0130@users.noreply.github.com>
1 parent 9b3424e commit 07992d3

File tree

1 file changed

+61
-54
lines changed

1 file changed

+61
-54
lines changed

internal/services/phone/emergencyaddress/emergency_address_resource.go

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
var (
2323
_ resource.Resource = &tfResource{}
2424
_ resource.ResourceWithImportState = &tfResource{}
25-
_ resource.ResourceWithModifyPlan = &tfResource{}
25+
// _ resource.ResourceWithModifyPlan = &tfResource{}
2626
)
2727

2828
func NewEmergencyAddressResource() resource.Resource {
@@ -112,6 +112,7 @@ This resource requires the ` + strings.Join([]string{
112112
},
113113
"is_default": schema.BoolAttribute{
114114
Optional: true,
115+
Computed: true,
115116
MarkdownDescription: "Indicates whether the emergency address is default or not.",
116117
},
117118
"site_id": schema.StringAttribute{
@@ -136,12 +137,12 @@ This resource requires the ` + strings.Join([]string{
136137
},
137138
"status": schema.Int32Attribute{
138139
Computed: true,
139-
Validators: []validator.Int32{
140-
int32validator.Between(1, 6),
141-
},
142140
PlanModifiers: []planmodifier.Int32{
143141
int32planmodifier.UseStateForUnknown(),
144142
},
143+
Validators: []validator.Int32{
144+
int32validator.Between(1, 6),
145+
},
145146
MarkdownDescription: "The emergency address verification status." + strings.Join([]string{
146147
"",
147148
"- `1`: Verification not required.",
@@ -154,12 +155,12 @@ This resource requires the ` + strings.Join([]string{
154155
},
155156
"level": schema.Int32Attribute{
156157
Computed: true,
157-
Validators: []validator.Int32{
158-
int32validator.Between(0, 2),
159-
},
160158
PlanModifiers: []planmodifier.Int32{
161159
int32planmodifier.UseStateForUnknown(),
162160
},
161+
Validators: []validator.Int32{
162+
int32validator.Between(0, 2),
163+
},
163164
MarkdownDescription: "The emergency address owner level." + strings.Join([]string{
164165
"",
165166
"- `0`: Account/Company-level emergency address.",
@@ -345,50 +346,56 @@ func (r *tfResource) ImportState(ctx context.Context, req resource.ImportStateRe
345346
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
346347
}
347348

348-
func (r *tfResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
349-
var state resourceModel
350-
351-
// For delete operations, plan will be null
352-
if req.Plan.Raw.IsNull() {
353-
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
354-
if resp.Diagnostics.HasError() {
355-
return
356-
}
357-
358-
// Check if the resource is default and linked to a site
359-
if !state.SiteID.IsNull() && !state.IsDefault.IsNull() && state.IsDefault.ValueBool() {
360-
existing, err := r.crud.read(ctx, state.ID)
361-
if err != nil {
362-
resp.Diagnostics.AddError(
363-
"Error reading phone emergency address",
364-
fmt.Sprintf(
365-
"Could not read phone emergency address %s, unexpected error: %s",
366-
state.ID.ValueString(),
367-
err.Error(),
368-
),
369-
)
370-
return
371-
}
372-
373-
// If the resource is already deleted, allow the operation
374-
if existing == nil {
375-
return
376-
}
377-
378-
resp.Diagnostics.AddError(
379-
"Cannot delete linked to a site and default emergency address",
380-
"The emergency address is set as default and cannot be deleted. If this emergency address is linked to a site, it will be automatically deleted when the site itself is deleted.",
381-
)
382-
return
383-
}
384-
return
385-
}
386-
387-
// For non-delete operations, get both plan and state
388-
var plan resourceModel
389-
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
390-
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
391-
if resp.Diagnostics.HasError() {
392-
return
393-
}
394-
}
349+
// func (r *tfResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
350+
// // For delete operations, plan will be null
351+
// if req.Plan.Raw.IsNull() {
352+
// // Get the current state
353+
// var state resourceModel
354+
// resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
355+
// if resp.Diagnostics.HasError() {
356+
// return
357+
// }
358+
359+
// // If state is empty (no current resource), allow the operation
360+
// if state.ID.IsNull() {
361+
// return
362+
// }
363+
364+
// // Check if the resource is default and linked to a site
365+
// if !state.SiteID.IsNull() && !state.IsDefault.IsNull() && state.IsDefault.ValueBool() {
366+
// existing, err := r.crud.read(ctx, state.ID)
367+
// if err != nil {
368+
// resp.Diagnostics.AddError(
369+
// "Error reading phone emergency address",
370+
// fmt.Sprintf(
371+
// "Could not read phone emergency address %s, unexpected error: %s",
372+
// state.ID.ValueString(),
373+
// err.Error(),
374+
// ),
375+
// )
376+
// return
377+
// }
378+
379+
// // If the resource is already deleted, allow the operation
380+
// if existing == nil {
381+
// return
382+
// }
383+
384+
// resp.Diagnostics.AddError(
385+
// "Cannot delete linked to a site and default emergency address",
386+
// "The emergency address is set as default and cannot be deleted. If this emergency address is linked to a site, it will be automatically deleted when the site itself is deleted.",
387+
// )
388+
// }
389+
// return
390+
// }
391+
392+
// // For non-delete operations
393+
// var plan, state resourceModel
394+
// resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
395+
// resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
396+
// if resp.Diagnostics.HasError() {
397+
// return
398+
// }
399+
400+
// // Add any additional plan modifications for non-delete operations here if needed
401+
// }

0 commit comments

Comments
 (0)