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/parse_duration: Add duration parsing function #350

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ricardbejarano
Copy link

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment 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 pull request followers and do not help prioritize the request

@ricardbejarano ricardbejarano requested a review from a team as a code owner September 4, 2024 11:18
@ricardbejarano
Copy link
Author

First contribution to this provider, so apologies if there are any errors of form.

This brings Go's time.ParseDuration function to Terraform, allowing users to define durations as "1h30m" instead of 60*90, which is much more readable.

Most of the code has been adapted from the rfc3339_parse function.

If it only goes up to hours in resolution is because that's what Rob Pike said makes sense.

@ricardbejarano
Copy link
Author

@austinvalle ping!

@ricardbejarano
Copy link
Author

Any updates? Can we get this merged?

@rainkwan
Copy link

rainkwan commented Jan 2, 2025

Hi @ricardbejarano!

Thank you for submitting this PR.

We understand why duration parsing like "3h10m" may seem more intuitive, however we would also like to see if there are more situations/use cases in which adding this function may be helpful. Providing more examples that showcase how to use this function would be great.

@ricardbejarano
Copy link
Author

So... drawing from the aws_sqs_queue resource docs, for example:

This:

resource "aws_sqs_queue" "terraform_queue" {
  name                      = "terraform-example-queue"
  delay_seconds             = 90
  message_retention_seconds = 86400
  receive_wait_time_seconds = 10
  // [...]
}

Becomes this:

resource "aws_sqs_queue" "terraform_queue" {
  name                      = "terraform-example-queue"
  delay_seconds             = provider::time::parse_duration("1m30s")
  message_retention_seconds = provider::time::parse_duration("24h")
  receive_wait_time_seconds = provider::time::parse_duration("10s")
  // [...]
}

Can you point me to what's not clear?

Copy link

@rainkwan rainkwan left a comment

Choose a reason for hiding this comment

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

I met with the maintainers of this repository and we decided that we will go ahead and accept this feature. Upon review, most of the code looks good with a few minor comments on some changes we would like that are mentioned in the suggestions. Most notably we would like to rename this function to duration_parse to match our existing naming conventions. This change will subsequently require the renaming of the function, files and tests as well. Additionally, we require a changelog, there are instructions on how you can add one in the contributors guide. Once the changes have been made we can work on getting this PR merged, thank you again for your contribution.

examples/functions/parse_duration/function.tf Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
templates/functions/parse_duration.md.tmpl Outdated Show resolved Hide resolved
internal/provider/provider.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
internal/provider/function_parse_duration_test.go Outdated Show resolved Hide resolved
@ricardbejarano
Copy link
Author

Sounds good, I'll push the changes and write the changelog!

@ricardbejarano
Copy link
Author

I think this is all @rainkwan, let me know otherwise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants