terraform-provider-time
terraform-provider-time copied to clipboard
[DRAFT] Rewrite Rotation Logic in `time_rotating`
The time_rotating
resource currently triggers a "rotation" by comparing the current time to rotation_rfc3339
and if the current time is after rotation_rfc3339
it will remove the resource in the read
method.
The rotation_rfc3339
is currently set in three different ways:
- Manually configured via the
rotation_rfc3339
attribute - Computed using the configured
rfc3339
and at least one configuredrotation_
attribute to be added to the baserfc3339
- Computed using at least one configured
rotation_
attribute to be added to therfc3339
which is computed to the current time
The current implementation has several issues:
- Removing the resource in the
read
method and creating it again increate
is a different behavior than triggering a recreate by settingrequiresReplace
. Use of thedepends_on
meta argument on thetime_rotating
resource or it's attributes does not properly trigger a replacement of another resource or data source - if the
rfc3339
orrotation_rfc3339
is set in the configuration and the time has expired and the resource is removed inread
and created again. Every subsequent plan will prompt a resource creation but the state does not change. - if the
rfc3339
orrotation_rfc3339
is set, then the "rotation" will only happen once. Once the time has expired for the first "rotation", therotation_rfc3339
will not change unless there is a configuration change.
As a rough implementation to solve these issues, this draft PR:
- Moved the time expiration logic outside of the
read
method and into theplanModifier
method. - Add logic to automatically recalculate the rotation values after the time has expired when
rfc3339
is set in the configuration. The recalculated rotation value will be set to the current time plus any additionalrotation_
values in the configuration. - Use the
id
to store any new rotation value and change the time expiration logic to compare against theid
attribute instead ofrotation_rfc3339
, to prevent errors when recalculating the rotation sincerotation_rfc3339
is aComputed
+Optional
attribute.
This is a very rough draft of an implementation as there are many edge case and further design decisions to be made, but this solution does solve the problems outlined above.