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:
parent
6953724ddd
commit
380ff8c6d8
1 changed files with 33 additions and 29 deletions
|
|
@ -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
|
// replace the planned expiration time with the current state date, iff they represent
|
||||||
// the same point in time (but perhaps with different textual representation)
|
// the same point in time (but perhaps with different textual representation)
|
||||||
// this will prevent no-op updates
|
// 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)))...)
|
resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, p, types.StringValue(stateDate.Format(time.RFC3339)))...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
|
|
@ -307,22 +307,24 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
if !utils.IsUndefined(model.ExpirationTimestamp) {
|
||||||
actualDate time.Time
|
var (
|
||||||
planDate time.Time
|
actualDate time.Time
|
||||||
)
|
planDate time.Time
|
||||||
resp.Diagnostics.Append(utils.ToTime(ctx, time.RFC3339, model.ExpirationTimestamp, &actualDate)...)
|
)
|
||||||
if resp.Diagnostics.HasError() {
|
resp.Diagnostics.Append(utils.ToTime(ctx, time.RFC3339, model.ExpirationTimestamp, &actualDate)...)
|
||||||
return
|
if resp.Diagnostics.HasError() {
|
||||||
}
|
return
|
||||||
resp.Diagnostics.Append(utils.GetTimeFromStringAttribute(ctx, path.Root("expiration_timestamp"), req.Plan, time.RFC3339, &planDate)...)
|
}
|
||||||
if resp.Diagnostics.HasError() {
|
resp.Diagnostics.Append(utils.GetTimeFromStringAttribute(ctx, path.Root("expiration_timestamp"), req.Plan, time.RFC3339, &planDate)...)
|
||||||
return
|
if resp.Diagnostics.HasError() {
|
||||||
}
|
return
|
||||||
// replace the planned expiration date with the original date, iff
|
}
|
||||||
// they represent the same point in time, (perhaps with different textual representations)
|
// replace the planned expiration date with the original date, iff
|
||||||
if actualDate.Equal(planDate) {
|
// they represent the same point in time, (perhaps with different textual representations)
|
||||||
model.ExpirationTimestamp = types.StringValue(planDate.Format(time.RFC3339))
|
if actualDate.Equal(planDate) {
|
||||||
|
model.ExpirationTimestamp = types.StringValue(planDate.Format(time.RFC3339))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diags = resp.State.Set(ctx, model)
|
diags = resp.State.Set(ctx, model)
|
||||||
|
|
@ -369,20 +371,22 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
|
||||||
stateDate time.Time
|
stateDate time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
resp.Diagnostics.Append(utils.ToTime(ctx, time.RFC3339, model.ExpirationTimestamp, ¤tApiDate)...)
|
if !utils.IsUndefined(model.ExpirationTimestamp) {
|
||||||
if resp.Diagnostics.HasError() {
|
resp.Diagnostics.Append(utils.ToTime(ctx, time.RFC3339, model.ExpirationTimestamp, ¤tApiDate)...)
|
||||||
return
|
if resp.Diagnostics.HasError() {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
resp.Diagnostics.Append(utils.GetTimeFromStringAttribute(ctx, path.Root("expiration_timestamp"), req.State, time.RFC3339, &stateDate)...)
|
resp.Diagnostics.Append(utils.GetTimeFromStringAttribute(ctx, path.Root("expiration_timestamp"), req.State, time.RFC3339, &stateDate)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace the resulting expiration date with the original date, iff
|
// replace the resulting expiration date with the original date, iff
|
||||||
// they represent the same point in time, (perhaps with different textual representations)
|
// they represent the same point in time, (perhaps with different textual representations)
|
||||||
if currentApiDate.Equal(stateDate) {
|
if currentApiDate.Equal(stateDate) {
|
||||||
model.ExpirationTimestamp = types.StringValue(stateDate.Format(time.RFC3339))
|
model.ExpirationTimestamp = types.StringValue(stateDate.Format(time.RFC3339))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set refreshed state
|
// Set refreshed state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue