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

Merged
merged 8 commits into from
Feb 13, 2025

Conversation

ricardbejarano
Copy link
Contributor

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
Contributor 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
Contributor Author

@austinvalle ping!

@ricardbejarano
Copy link
Contributor Author

Any updates? Can we get this merged?

@rainkwan
Copy link
Contributor

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
Contributor 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
Contributor

@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.

@ricardbejarano
Copy link
Contributor Author

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

@ricardbejarano
Copy link
Contributor Author

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

@ricardbejarano
Copy link
Contributor Author

😅

@rainkwan rainkwan mentioned this pull request Feb 13, 2025
Copy link
Contributor

@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.

Thank you for contributing, looks like all checks are passing so we are good to merge.

@rainkwan rainkwan requested a review from SBGoods February 13, 2025 16:56
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

🚀

@rainkwan rainkwan merged commit f73bd87 into hashicorp:main Feb 13, 2025
5 checks passed
@rainkwan
Copy link
Contributor

This PR has been merged and will be added to the next release in the coming weeks, thank you.

@ricardbejarano
Copy link
Contributor Author

Thank you!

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.

3 participants