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

Feat: custom project and organization TTL policy #588

Merged
merged 6 commits into from
Feb 20, 2023

Conversation

TomerHeber
Copy link
Collaborator

Issue & Steps to Reproduce / Feature Request

resolves #572

Solution

  1. Updated both resources env0_organization_policy and env0_project_policy to support custom TTL values.
  2. updated acceptance tests.
  3. added conversion functions and unit tests.
  4. updated integration tests.

var hours int = number

switch rangeType := match[2]; rangeType {
case "M":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Assumed that 1 Month equals 30 days.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a way to calc a "real" month using https://pkg.go.dev/time?
This will create problems

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

1-M would mean something different every month.
In other words, 1-M isn't well-defined when it's configured.

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, just keep it

env0/utils.go Outdated
@@ -453,3 +457,34 @@ func writeResourceDataEx(prefix string, i interface{}, d *schema.ResourceData) e
}
return writeResourceDataSlice([]interface{}{i}, prefix, d)
}

func ttlToDuration(ttl string) (time.Duration, error) {
if ttl == "Infinite" || ttl == "inherit" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Inherit is hard to predict.
Worst case scenario, the backend call will fail.

Comment on lines 161 to 172
defaultTtl, err := getPolicyTtl(payload.DefaultTtl)
if err != nil {
return diag.Errorf("invalid default ttl: %v", err)
}

maxTtl, err := getPolicyTtl(payload.MaxTtl)
if err != nil {
return diag.Errorf("invalid max ttl: %v", err)
}

if maxTtl < defaultTtl {
return diag.Errorf("default ttl must not be larger than max ttl: %d %d", defaultTtl, maxTtl)
Copy link
Contributor

Choose a reason for hiding this comment

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

anyway to avoid the code duplication here and in organization?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there is. I'll check...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored and removed code duplication.
d12f08e

env0/utils.go Outdated
@@ -453,3 +457,34 @@ func writeResourceDataEx(prefix string, i interface{}, d *schema.ResourceData) e
}
return writeResourceDataSlice([]interface{}{i}, prefix, d)
}

func ttlToDuration(ttl string) (time.Duration, error) {
if ttl == "Infinite" || ttl == "inherit" {
Copy link
Contributor

Choose a reason for hiding this comment

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

In case of infinite user will omit the ttl, so it will be nil and not Infinite

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Generally not an issue, but made some refactoring.
d12f08e

var hours int = number

switch rangeType := match[2]; rangeType {
case "M":
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a way to calc a "real" month using https://pkg.go.dev/time?
This will create problems

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Feb 20, 2023
@TomerHeber TomerHeber merged commit 6a2af26 into main Feb 20, 2023
@TomerHeber TomerHeber deleted the feat-custom-ttl-policy-#572 branch February 20, 2023 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature integration-tests provider ready to merge PR approved - can be merged once the PR owner is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Project and Organization TTL Policy
3 participants