terraform-provider-time icon indicating copy to clipboard operation
terraform-provider-time copied to clipboard

Provider produced inconsistent final plan when using data sources as parameters

Open TobiTh opened this issue 2 years ago • 2 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v1.3.6 on windows_386

  • provider registry.terraform.io/hashicorp/local v2.2.3
  • provider registry.terraform.io/hashicorp/null v3.2.1
  • provider registry.terraform.io/hashicorp/time v0.9.1

Affected Resource(s)

  • time_rotating

Terraform Configuration Files

resource "null_resource" "calculate_minutes" {
  triggers = {
    timestamp = timestamp() # trigger always
  }

  provisioner "local-exec" {
    command     = <<COMMAND
  $minutes = 5
  $minutes | Out-File -FilePath "minutes" -Encoding UTF8NoBOM -NoNewline
COMMAND
    working_dir = path.module
    interpreter = ["pwsh.exe", "-Command"]
  }
}

data "local_file" "minutes" {
    filename = "${path.module}/minutes"
    depends_on = [ null_resource.calculate_minutes ]
}

resource "time_rotating" "time1" {
  rotation_minutes = data.local_file.minutes.content
}

Panic Output

│ Error: Provider produced inconsistent final plan │ │ When expanding the plan for time_rotating.time1 to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/time" produced an invalid new value for │ .rotation_rfc3339: was cty.StringVal("0001-01-01T00:00:00Z"), but now cty.StringVal("2022-12-22T12:13:38Z"). │ │ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected Behavior

The actual value of rotation_minutes has not changed, so the resource should not be changed. The actual value has to be calculated outside of terraform, because terraform's abilities to calculate days between timestamps (or minutes in this minimal example) is limited.

Actual Behavior

The apply produced an inconsistent final plan and will fail with the panic message. The original plan wants to change the time resource to a unix timestamp:

  # time_rotating.time1 will be updated in-place
  ~ resource "time_rotating" "time1" {
      ~ day              = 22 -> 1
      ~ hour             = 12 -> 0
        id               = "2022-12-22T12:08:38Z"
      ~ minute           = 13 -> 0
      ~ month            = 12 -> 1
      ~ rotation_minutes = 5 -> (known after apply)
      ~ rotation_rfc3339 = "2022-12-22T12:13:38Z" -> "0001-01-01T00:00:00Z"
      ~ second           = 38 -> 0
      ~ unix             = 1671711218 -> -62135596800
      ~ year             = 2022 -> 1
        # (1 unchanged attribute hidden)
    }

Steps to Reproduce

  1. terraform plan --out tf_plan.out
  2. terraform apply .\tf_plan.out

Important Factoids

No. Running everything locally in a local state.

TobiTh avatar Dec 22 '22 12:12 TobiTh

Hi @TobiTh, Sorry that you are running into this issue here. This issue likely stems from the rotation_minutes attribute being updated with an Unknown value during planning. Unfortunately, due to the nature of this resource, we cannot fix this issue as it would cause preemptive rotations to occur.

In terms of your particular configuration, I would suggest removing the depends_on clause from data.local_file.minutes, normally data sources are read during planning but the depends_on clause causes the value of data.local_file.minutes.content to be Unknown during planning. If you can change the value of the minutes file outside of Terraform, then you can circumvent this error.

SBGoods avatar Aug 02 '23 19:08 SBGoods

Hi @SBGoods, thank you for your suggestion. Sadly the depends_on is necessary as we need to calculate the minutes (via powershell as terraform cannot calculate minutes between dates) and write the result into the file to be consumed via the time_rotating resource.

TobiTh avatar Aug 10 '23 09:08 TobiTh