hashicorp / terraform-provider-time

Utility provider that provides Time-Based Resources
https://registry.terraform.io/providers/hashicorp/time/latest
Mozilla Public License 2.0
104 stars 30 forks source link

Provider produced invalid plan #146

Open sam701 opened 1 year ago

sam701 commented 1 year ago

Terraform Version

Terraform v1.3.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/time v0.9.1

Affected Resource(s)

Terraform Configuration Files

resource "time_rotating" "main" {
  count            = 2
  rotation_rfc3339 = timeadd(timestamp(), "10m")
}

Expected Behavior

terraform plan produces a plan without errors.

Actual Behavior

╷
│ Error: Provider produced invalid plan
│
│ Provider "registry.terraform.io/hashicorp/time" planned an invalid value for module.sp_grafana.time_rotating.main[1].rotation_rfc3339: planned value cty.StringVal("0001-01-01T00:00:00Z") does not match config value
│ cty.UnknownVal(cty.String) nor prior value cty.StringVal("2022-12-19T09:36:47Z").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Steps to Reproduce

Changes of an existing resource on the field rotation_rfc3339 lead this this error:

terraform apply # resources created
terraform plan # resources exist but must be modified
jskirde commented 1 year ago

This issue seems to affect all time resources where the value on update is known after apply. Create doesn't appear to be affected. An example of another time resource that can be created but not updated with a known after apply:

resource "time_offset" "example" {
  offset_days = formatdate("s", timestamp())
}
SBGoods commented 1 year ago

Hi @sam701, Sorry that you are running into this issue here. As @jskirde mentioned, this issue stems from the rotation_rfc3339 attribute being updated with a value that is known after apply (timestamp() is calculated during the apply step). Unfortunately due to the nature of this resource, we cannot fix this issue as it would cause preemptive rotations to occur. If you are using Terraform v1.5.0 and above, you can use plantimestamp(), which calculates the time stamp during planning, instead to avoid this error.