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

function/rfc3339_parse: Add RFC3339 parsing function #280

Merged
merged 24 commits into from
Mar 11, 2024

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Jan 13, 2024

Ref: #217
Terraform core refs: hashicorp/terraform#29694, hashicorp/terraform#31751, hashicorp/terraform#25802, hashicorp/terraform#33538

This PR introduces a new provider-defined function for parsing RFC3339 timestamps:

terraform {
  required_providers {
    time = {
      source = "hashicorp/time"
    }
  }
}

output "example_output" {
  value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z")
}
 $ terraform plan        

Changes to Outputs:
  + example_output = {
      + day          = 25
      + hour         = 23
      + iso_week     = 30
      + iso_year     = 2023
      + minute       = 43
      + month        = 7
      + month_name   = "July"
      + second       = 16
      + unix         = 1690328596
      + weekday      = 2
      + weekday_name = "Tuesday"
      + year         = 2023
      + year_day     = 206
    }

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Notes

  • I purposefully did not include output from (time).Zone()
    • zone_name is not directly related to zone_offset, and would always be "UTC" or ""
    • zone_offset is valid and a part of the RFC3339 string. The time.Time package returns this offset in seconds east of UTC, which may be confusing to users (but potentially necessary in this format, since time zone offsets aren't necessarily in whole hours 😖 ).
    • I think if we want to return TZ name or offset info about a timestamp, we should treat it as a separate function and use (time).ParseInLocation
  • I named the files function_ to follow the convention of the repository. I can also refactor all the files in this provider to match the other accepted pattern of:
    • *_function.go
    • *_resource.go

@austinvalle austinvalle added the enhancement New feature or request label Jan 13, 2024
@austinvalle austinvalle added this to the v0.10.0 milestone Jan 13, 2024
@github-actions github-actions bot added dependencies Pull requests that update a dependency file size/L labels Jan 13, 2024
@austinvalle austinvalle changed the title function/rfc3339_parse: Add RFC3339 parsing provider defined function function/rfc3339_parse: Add RFC3339 parsing provider defined function Jan 13, 2024
@austinvalle austinvalle changed the title function/rfc3339_parse: Add RFC3339 parsing provider defined function function/rfc3339_parse: Add RFC3339 parsing function Jan 13, 2024
@github-actions github-actions bot added size/XL and removed size/L labels Jan 23, 2024
@bflad
Copy link
Contributor

bflad commented Jan 25, 2024

terraform-plugin-docs has been updated on main 👍

@austinvalle austinvalle marked this pull request as ready for review March 6, 2024 16:54
@austinvalle austinvalle requested a review from a team as a code owner March 6, 2024 16:54
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🚀

examples/functions/rfc3339_parse/function.tf Outdated Show resolved Hide resolved
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

internal/provider/function_rfc3339_parse.go Show resolved Hide resolved
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants