fix: expiration_timestamp of "stackit_objectstorage_credentials" cannot be parsed (#693)

* fix: expiration_timestamp of ```stackit_objectstorage_credentials```cannot be parsed

* implement review feedback
This commit is contained in:
Marcel Jacek 2025-02-24 14:19:16 +01:00 committed by GitHub
parent 6953724ddd
commit 380ff8c6d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -118,7 +118,7 @@ func (r *credentialResource) modifyPlanExpiration(ctx context.Context, req *reso
// replace the planned expiration time with the current state date, iff they represent
// the same point in time (but perhaps with different textual representation)
// this will prevent no-op updates
if stateDate.Equal(planDate) {
if stateDate.Equal(planDate) && !stateDate.IsZero() {
resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, p, types.StringValue(stateDate.Format(time.RFC3339)))...)
if resp.Diagnostics.HasError() {
return
@ -307,6 +307,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
return
}
if !utils.IsUndefined(model.ExpirationTimestamp) {
var (
actualDate time.Time
planDate time.Time
@ -324,6 +325,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
if actualDate.Equal(planDate) {
model.ExpirationTimestamp = types.StringValue(planDate.Format(time.RFC3339))
}
}
diags = resp.State.Set(ctx, model)
resp.Diagnostics.Append(diags...)
@ -369,6 +371,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
stateDate time.Time
)
if !utils.IsUndefined(model.ExpirationTimestamp) {
resp.Diagnostics.Append(utils.ToTime(ctx, time.RFC3339, model.ExpirationTimestamp, &currentApiDate)...)
if resp.Diagnostics.HasError() {
return
@ -384,6 +387,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
if currentApiDate.Equal(stateDate) {
model.ExpirationTimestamp = types.StringValue(stateDate.Format(time.RFC3339))
}
}
// Set refreshed state
diags = resp.State.Set(ctx, model)