-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Various improvements to automation account & schedule (interval property for recurring) #1384
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
beeaed5
azurerm_automation_schedule: added interval property
katbyte feafd1c
Merge branch 'master' into b-automation_schedule_interval
katbyte bf6c579
automation: Added validate & suppress helper packages & cleaned up code
katbyte b4a6ebd
automation: recatored import tests & added schedule tests
katbyte 3ef04d6
automation: updates to make tests pass
katbyte f287c40
automation schedule: final PR updates
katbyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package suppress | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
) | ||
|
||
func CaseDifference(_, old, new string, _ *schema.ResourceData) bool { | ||
return strings.ToLower(old) == strings.ToLower(new) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package suppress | ||
|
||
import "testing" | ||
|
||
func TestHelper_Suppress_CaseDifference(t *testing.T) { | ||
cases := []struct { | ||
StringA string | ||
StringB string | ||
Suppress bool | ||
}{ | ||
{ | ||
StringA: "", | ||
StringB: "", | ||
Suppress: true, | ||
}, | ||
{ | ||
StringA: "ye old text", | ||
StringB: "", | ||
Suppress: false, | ||
}, | ||
{ | ||
StringA: "ye old text?", | ||
StringB: "ye different text", | ||
Suppress: false, | ||
}, | ||
{ | ||
StringA: "ye same text!", | ||
StringB: "ye same text!", | ||
Suppress: true, | ||
}, | ||
{ | ||
StringA: "ye old text?", | ||
StringB: "Ye OLD texT?", | ||
Suppress: true, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
if CaseDifference("test", tc.StringA, tc.StringB, nil) != tc.Suppress { | ||
t.Fatalf("Expected CaseDifference to return %t for '%q' == '%q'", tc.Suppress, tc.StringA, tc.StringB) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package suppress | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func Rfc3339Time(_, old, new string, _ *schema.ResourceData) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh this too! 👍 |
||
ot, oerr := time.Parse(time.RFC3339, old) | ||
nt, nerr := time.Parse(time.RFC3339, new) | ||
|
||
if oerr != nil || nerr != nil { | ||
return false | ||
} | ||
|
||
return nt.Equal(ot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package suppress | ||
|
||
import "testing" | ||
|
||
func TestHelper_Supress_Rfc3339Time(t *testing.T) { | ||
cases := []struct { | ||
TimeA string | ||
TimeB string | ||
Suppress bool | ||
}{ | ||
{ | ||
TimeA: "", | ||
TimeB: "", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "this is not a time", | ||
TimeB: "neither is this", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "that is a valid time", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "1984-07-07T01:23:45+00:00", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "2000-01-01T01:23:45Z", | ||
Suppress: true, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45-08:00", | ||
TimeB: "2000-01-01T09:23:45Z", | ||
Suppress: true, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
if Rfc3339Time("test", tc.TimeA, tc.TimeB, nil) != tc.Suppress { | ||
t.Fatalf("Expected Rfc3339Time to return %t for '%q' == '%q'", tc.Suppress, tc.TimeA, tc.TimeB) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
//todo, now in terraform helper, switch over once vended | ||
// -> https://github.com/hashicorp/terraform/blob/master/helper/validation/validation.go#L263 | ||
func Rfc3339Time(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := date.ParseTime(time.RFC3339, v); err != nil { | ||
errors = append(errors, fmt.Errorf("%q has the invalid RFC3339 date format %q: %+v", k, i, err)) | ||
} | ||
|
||
return | ||
} | ||
|
||
func Rfc3339DateInFutureBy(d time.Duration) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
t, err := date.ParseTime(time.RFC3339, v) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q has the invalid RFC3339 date format %q: %+v", k, i, err)) | ||
return | ||
} | ||
|
||
if time.Until(t) < d { | ||
errors = append(errors, fmt.Errorf("%q is %q and should be at least %q in the future", k, i, d)) | ||
} | ||
|
||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestHelper_Validate_RFC3339Time(t *testing.T) { | ||
cases := []struct { | ||
Time string | ||
Errors int | ||
}{ | ||
{ | ||
Time: "", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "this is not a date", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45Z", | ||
Errors: 0, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45+00:00", | ||
Errors: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := Rfc3339Time(tc.Time, "test") | ||
|
||
if len(errors) != tc.Errors { | ||
t.Fatalf("Expected Rfc3339Time to have an error for '%q'", tc.Time) | ||
} | ||
} | ||
} | ||
|
||
func TestHelper_Validate_Rfc3339DateInFutureBy(t *testing.T) { | ||
cases := []struct { | ||
Time string | ||
Duration time.Duration | ||
Errors int | ||
}{ | ||
{ | ||
Time: "", | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "not a time", | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().String(), | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().Add(time.Hour * 7).String(), | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().Add(time.Minute).String(), | ||
Duration: time.Minute * 7, | ||
Errors: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := Rfc3339DateInFutureBy(tc.Duration)(tc.Time, "test") | ||
|
||
if len(errors) < tc.Errors { | ||
t.Fatalf("Expected Rfc3339DateInFutureBy to have an error for '%q' in future by `%q`", tc.Time, tc.Duration.String()) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should get this added into helper/schema 😄