-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
var hours int = number | ||
|
||
switch rangeType := match[2]; rangeType { | ||
case "M": |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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.
env0/resource_project_policy.go
Outdated
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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
Issue & Steps to Reproduce / Feature Request
resolves #572
Solution
env0_organization_policy
andenv0_project_policy
to support custom TTL values.