-
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
New Resource: azurerm_scheduler_job
#1172
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f1c9ef6
Intial commit of scheduler_job
katbyte 020df2c
Merged master into f-r-scheduler_job
katbyte beb79b8
azurerm_scheduler_job todo & misc cleanup
katbyte 2c9a46a
travis CI fixes
katbyte 720eabc
azurerm_scheduler_job: removed populate function & other small changes
katbyte 6b7b924
aszurerm_schduler_job: update tests & validation
katbyte 61ea612
Updated example URLs
katbyte 9a76a4b
Merge branch 'master' into f-r-scheduler_job
katbyte ee60252
schduler jobs & collection: formatted examples
katbyte 218376a
azurerm_scheduler_job: schema adjustments
katbyte 5a50522
azurerm_scheduler_job: resolving PR comments
katbyte 878707c
azurerm_scheduler_job: First round of PR fixes
katbyte e404a92
azurerm_scheduler_job: Futher PR fixes
katbyte 93e318b
Merge branch 'master' into f-r-scheduler_job
katbyte c18fbfe
scheduler job: address PR comments
katbyte 9836428
scheduler job - minor fix to tests
katbyte 770beb3
Adding tests for the validation functions
tombuildsstuff f32ecc0
inline-ing the check methods
tombuildsstuff 184a879
Fixing the highlight in the sidebar
tombuildsstuff 00cfa00
Merge branch 'master' into f-r-scheduler_job
tombuildsstuff c1ae37e
Fixing merge issues
tombuildsstuff f0a0315
Fixing a crash when loading the environment
tombuildsstuff 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
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,35 @@ | ||
package set | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/hashcode" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func HashInt(v interface{}) int { | ||
return hashcode.String(strconv.Itoa(v.(int))) | ||
} | ||
|
||
func HashStringIgnoreCase(v interface{}) int { | ||
return hashcode.String(strings.ToLower(v.(string))) | ||
} | ||
|
||
func FromInt32Slice(slice []int32) *schema.Set { | ||
set := &schema.Set{F: HashInt} | ||
for _, v := range slice { | ||
set.Add(int(v)) | ||
} | ||
|
||
return set | ||
} | ||
|
||
func ToSliceInt32P(set *schema.Set) *[]int32 { | ||
var slice []int32 | ||
for _, m := range set.List() { | ||
slice = append(slice, int32(m.(int))) | ||
} | ||
|
||
return &slice | ||
} |
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,71 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func IntBetweenAndNot(min, max, not int) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(int) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be int", k)) | ||
return | ||
} | ||
|
||
if v < min || v > max { | ||
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) | ||
return | ||
} | ||
|
||
if v == not { | ||
errors = append(errors, fmt.Errorf("expected %s to not be %d, got %d", k, not, v)) | ||
return | ||
} | ||
|
||
return | ||
} | ||
} | ||
|
||
func UrlIsHttpOrHttps() schema.SchemaValidateFunc { | ||
return UrlWithScheme([]string{"http", "https"}) | ||
} | ||
|
||
func UrlWithScheme(validSchemes []string) 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 | ||
} | ||
|
||
url, err := url.Parse(v) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q url is in an invalid format: %q (%+v)", k, i, err)) | ||
return | ||
} | ||
|
||
if url.Host == "" { | ||
errors = append(errors, fmt.Errorf("%q url has no host: %q", k, url)) | ||
} | ||
|
||
found := false | ||
for _, s := range validSchemes { | ||
if strings.EqualFold(url.Scheme, s) { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
schemes := strings.Join(validSchemes, ",") | ||
errors = append(errors, fmt.Errorf("URL scheme %q isn't valid - supported scheme's are %q", url.Scheme, schemes)) | ||
} | ||
|
||
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,45 @@ | ||
package validate | ||
|
||
import "testing" | ||
|
||
func TestUrlWithScheme(t *testing.T) { | ||
validSchemes := []string{"example"} | ||
testCases := []struct { | ||
Url string | ||
ShouldHaveError bool | ||
}{ | ||
{ | ||
Url: "example://mysite.com", | ||
ShouldHaveError: false, | ||
}, | ||
{ | ||
Url: "http://mysite.com", | ||
ShouldHaveError: true, | ||
}, | ||
{ | ||
Url: "example://", | ||
ShouldHaveError: true, | ||
}, | ||
{ | ||
Url: "example://validhost", | ||
ShouldHaveError: false, | ||
}, | ||
} | ||
|
||
t.Run("TestUrlWithScheme", func(t *testing.T) { | ||
for _, v := range testCases { | ||
_, errors := UrlWithScheme(validSchemes)(v.Url, "field_name") | ||
|
||
hasErrors := len(errors) > 0 | ||
if v.ShouldHaveError && !hasErrors { | ||
t.Fatalf("Expected an error but didn't get one for %q", v.Url) | ||
return | ||
} | ||
|
||
if !v.ShouldHaveError && hasErrors { | ||
t.Fatalf("Expected %q to return no errors, but got some %+v", v.Url, errors) | ||
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
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.
can we add some basic tests covering the methods in the other file?