Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plantimestamp() function producing invalid value (0001-01-01T00:00:00Z) #35898

Closed
SunTrustDev opened this issue Oct 24, 2024 · 2 comments · Fixed by #35902
Closed

plantimestamp() function producing invalid value (0001-01-01T00:00:00Z) #35898

SunTrustDev opened this issue Oct 24, 2024 · 2 comments · Fixed by #35902
Labels
bug confirmed a Terraform Core team member has reproduced this issue

Comments

@SunTrustDev
Copy link

SunTrustDev commented Oct 24, 2024

Terraform Version

1.9.8

Terraform Configuration Files

locals {
  first_year = 2023
  current_timestamp = plantimestamp()
  current_year = formatdate("YYYY", local.current_timestamp)
  current_year_number = tonumber(local.current_year)
  table_years = toset(range(local.first_year, local.current_year_number + 2))
}
output "table_years" {
  value = toset(
    [ 
      for year in range(local.first_year, tonumber(formatdate("YYYY", local.current_timestamp)) + 2) : tostring(year)
    ]
  )
}

Debug Output

Can't find related debug traces

Expected Behavior

The output shows the current date at plan time (2024-10-24.T11:58:00Z).

Actual Behavior

The output being shown is "0001-01-01T00:00:00Z".
It causes the range function to fail with the following error:

Error: Error in function call
│ 
│   on ../../../../component/trip-shared/terraform/constants/outputs.tf line 19, in output "trip_iceberg_table_years":
│   19:       for year in range(local.first_year, tonumber(formatdate("YYYY", local.current_timestamp)) + 2) : tostring(year)
│     ├────────────────
│     │ while calling range(params...)
│     │ local.current_timestamp is "0001-01-01T00:00:00Z"
│     │ local.first_year is 2023

Steps to Reproduce

terraform plan

cannot directly reproduce in terraform console as planterraform does not exists there, but its output can be visualized with it.

(terraform console -> local.current_timestamp)

Additional Context

No response

References

No response

@SunTrustDev SunTrustDev added bug new new issue not yet triaged labels Oct 24, 2024
@jbardin
Copy link
Member

jbardin commented Oct 24, 2024

Thanks @SunTrustDev!

This is a validation error, which happens before the plan. The timestamp should be unknown at that point, however the implementation is using time.Time directly so cannot take the unknown value into account.

@jbardin jbardin added confirmed a Terraform Core team member has reproduced this issue and removed new new issue not yet triaged labels Oct 24, 2024
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants