Skip to content

Commit

Permalink
fix: tf - bs - create volume from snapshot id (#1291)
Browse files Browse the repository at this point in the history
* fix: tf - bs - create volume from snapshot id
  • Loading branch information
geffersonFerraz authored Dec 10, 2024
1 parent f2cf103 commit 935723a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions mgc/terraform-provider-mgc/mgc/resources/mgc_bs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (r *bsVolumes) Schema(_ context.Context, _ resource.SchemaRequest, resp *re
Description: "The unique identifier of the snapshot used to create the block storage.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
},
Optional: true,
},
Expand Down Expand Up @@ -184,8 +185,7 @@ func (r *bsVolumes) Schema(_ context.Context, _ resource.SchemaRequest, resp *re

}

func convertToState(result sdkBlockStorageVolumes.GetResult, originalName string, originalIsPrefix bool) *bsVolumesResourceModel {
state := bsVolumesResourceModel{}
func convertToState(state *bsVolumesResourceModel, result sdkBlockStorageVolumes.GetResult, originalName string, originalIsPrefix bool) {
state.ID = types.StringValue(result.Id)
state.FinalName = types.StringValue(result.Name)
state.NameIsPrefix = types.BoolValue(originalIsPrefix)
Expand All @@ -201,7 +201,10 @@ func convertToState(result sdkBlockStorageVolumes.GetResult, originalName string
}
state.AvailabilityZone = types.StringValue(result.AvailabilityZone)
state.CreatedAt = types.StringValue(result.CreatedAt)
return &state
state.UpdatedAt = types.StringValue(result.CreatedAt)
if result.UpdatedAt != "" {
state.UpdatedAt = types.StringValue(result.UpdatedAt)
}
}

func (r *bsVolumes) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
Expand All @@ -220,7 +223,7 @@ func (r *bsVolumes) Read(ctx context.Context, req resource.ReadRequest, resp *re
)
return
}
plan = convertToState(getResult, plan.Name.ValueString(), plan.NameIsPrefix.ValueBool())
convertToState(plan, getResult, plan.Name.ValueString(), plan.NameIsPrefix.ValueBool())
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down Expand Up @@ -264,10 +267,7 @@ func (r *bsVolumes) Create(ctx context.Context, req resource.CreateRequest, resp
return
}

state = convertToState(*getCreatedResource, state.Name.ValueString(), state.NameIsPrefix.ValueBool())
if createParam.Snapshot != nil && createParam.Snapshot.Id != "" {
state.SnapshotID = types.StringValue(createParam.Snapshot.Id)
}
convertToState(state, *getCreatedResource, state.Name.ValueString(), state.NameIsPrefix.ValueBool())
resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
}

Expand Down Expand Up @@ -332,7 +332,7 @@ func (r *bsVolumes) Update(ctx context.Context, req resource.UpdateRequest, resp
return
}

planData = convertToState(*getResult, planData.Name.ValueString(), state.NameIsPrefix.ValueBool())
convertToState(planData, *getResult, planData.Name.ValueString(), state.NameIsPrefix.ValueBool())
resp.Diagnostics.Append(resp.State.Set(ctx, &planData)...)
}

Expand Down

0 comments on commit 935723a

Please sign in to comment.