mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucket.git
synced 2026-05-23 08:07:12 +02:00
Update condition if token is closed to expiry will create new one
This commit is contained in:
+6
-2
@@ -347,16 +347,20 @@ func (r *BitbucketTokenResource) Read(ctx context.Context, req resource.ReadRequ
|
|||||||
}
|
}
|
||||||
|
|
||||||
nowMs := time.Now().UnixMilli()
|
nowMs := time.Now().UnixMilli()
|
||||||
|
thresholdMs := int64(30 * 24 * time.Hour / time.Millisecond)
|
||||||
|
|
||||||
stateName := data.CurrentTokenName.ValueString()
|
stateName := data.CurrentTokenName.ValueString()
|
||||||
var valid bool
|
var valid bool
|
||||||
|
|
||||||
if stateName != "" {
|
if stateName != "" {
|
||||||
if t := getTokenByName(tokens, stateName); t != nil && t.ExpiryMs > nowMs {
|
if t := getTokenByName(tokens, stateName); t != nil {
|
||||||
// keep state as-is
|
timeLeft := t.ExpiryMs - nowMs
|
||||||
|
if timeLeft > thresholdMs {
|
||||||
data.CurrentTokenExpiry = types.Int64Value(t.ExpiryMs)
|
data.CurrentTokenExpiry = types.Int64Value(t.ExpiryMs)
|
||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !valid {
|
if !valid {
|
||||||
// Not present or expired -> remove from state; next Apply will create a new one in Create/Update paths.
|
// Not present or expired -> remove from state; next Apply will create a new one in Create/Update paths.
|
||||||
|
|||||||
Reference in New Issue
Block a user