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

New Resource: azurerm_scheduler_job #1172

Merged
merged 22 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f1c9ef6
Intial commit of scheduler_job
katbyte Mar 16, 2018
020df2c
Merged master into f-r-scheduler_job
katbyte Apr 27, 2018
beb79b8
azurerm_scheduler_job todo & misc cleanup
katbyte Apr 27, 2018
2c9a46a
travis CI fixes
katbyte Apr 28, 2018
720eabc
azurerm_scheduler_job: removed populate function & other small changes
katbyte May 13, 2018
6b7b924
aszurerm_schduler_job: update tests & validation
katbyte May 16, 2018
61ea612
Updated example URLs
katbyte May 17, 2018
9a76a4b
Merge branch 'master' into f-r-scheduler_job
katbyte May 17, 2018
ee60252
schduler jobs & collection: formatted examples
katbyte May 17, 2018
218376a
azurerm_scheduler_job: schema adjustments
katbyte May 21, 2018
5a50522
azurerm_scheduler_job: resolving PR comments
katbyte May 25, 2018
878707c
azurerm_scheduler_job: First round of PR fixes
katbyte Jun 1, 2018
e404a92
azurerm_scheduler_job: Futher PR fixes
katbyte Jun 4, 2018
93e318b
Merge branch 'master' into f-r-scheduler_job
katbyte Jun 21, 2018
c18fbfe
scheduler job: address PR comments
katbyte Jun 22, 2018
9836428
scheduler job - minor fix to tests
katbyte Jun 25, 2018
770beb3
Adding tests for the validation functions
tombuildsstuff Jul 3, 2018
f32ecc0
inline-ing the check methods
tombuildsstuff Jul 3, 2018
184a879
Fixing the highlight in the sidebar
tombuildsstuff Jul 3, 2018
00cfa00
Merge branch 'master' into f-r-scheduler_job
tombuildsstuff Jul 3, 2018
c1ae37e
Fixing merge issues
tombuildsstuff Jul 3, 2018
f0a0315
Fixing a crash when loading the environment
tombuildsstuff Jul 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ type ArmClient struct {
resourceGroupsClient resources.GroupsClient
subscriptionsClient subscriptions.Client

//Scheduler
schedulerJobCollectionsClient scheduler.JobCollectionsClient
schedulerJobsClient scheduler.JobsClient

// Search
searchServicesClient search.ServicesClient

Expand All @@ -192,9 +196,6 @@ type ArmClient struct {
serviceBusSubscriptionsClient servicebus.SubscriptionsClient
serviceBusSubscriptionRulesClient servicebus.RulesClient

//Scheduler
schedulerJobCollectionsClient scheduler.JobCollectionsClient

// Storage
storageServiceClient storage.AccountsClient
storageUsageClient storage.UsageClient
Expand Down Expand Up @@ -849,6 +850,16 @@ func (c *ArmClient) registerResourcesClients(endpoint, subscriptionId string, au
c.subscriptionsClient = subscriptionsClient
}

func (c *ArmClient) registerSchedulerClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
jobCollectionsClient := scheduler.NewJobCollectionsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&jobCollectionsClient.Client, auth)
c.schedulerJobCollectionsClient = jobCollectionsClient

jobsClient := scheduler.NewJobsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&jobsClient.Client, auth)
c.schedulerJobsClient = jobsClient
}

func (c *ArmClient) registerSearchClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
searchClient := search.NewServicesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&searchClient.Client, auth)
Expand Down Expand Up @@ -877,12 +888,6 @@ func (c *ArmClient) registerServiceBusClients(endpoint, subscriptionId string, a
c.serviceBusSubscriptionRulesClient = subscriptionRulesClient
}

func (c *ArmClient) registerSchedulerClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
jobsClient := scheduler.NewJobCollectionsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&jobsClient.Client, auth)
c.schedulerJobCollectionsClient = jobsClient
}

func (c *ArmClient) registerStorageClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
accountsClient := storage.NewAccountsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&accountsClient.Client, auth)
Expand Down
16 changes: 16 additions & 0 deletions azurerm/helpers/set/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package set

import (
"strconv"
"strings"

"github.com/hashicorp/terraform/helper/hashcode"
)

func HashInt(v interface{}) int {
return hashcode.String(strconv.Itoa(v.(int)))
}

func HashStringIgnoreCase(v interface{}) int {
return hashcode.String(strings.ToLower(v.(string)))
}
23 changes: 23 additions & 0 deletions azurerm/helpers/supress/suppress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package supress
Copy link
Contributor

Choose a reason for hiding this comment

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

supress -> suppress


import (
"time"

"github.com/hashicorp/terraform/helper/schema"
"strings"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor can we sort these?

)

func CaseDifference(_, old, new string, _ *schema.ResourceData) bool {
return strings.ToLower(old) == strings.ToLower(new)
}

func Rfc3339Time(_, old, new string, _ *schema.ResourceData) bool {
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)
}
90 changes: 90 additions & 0 deletions azurerm/helpers/supress/suppress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package supress

import (
"testing"
)

func TestInternal_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 '%s' == '%s'", tc.Suppress, tc.StringA, tc.StringB)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor you can use %q in place of '%s' (or "%s")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we be using %q everywhere instead of %s?

}
}
}

func TestInternal_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 '%s' == '%s'", tc.Suppress, tc.TimeA, tc.TimeB)
}
}
}
66 changes: 66 additions & 0 deletions azurerm/helpers/validate/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package validate

import (
"fmt"
"net/url"
"time"

"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/terraform/helper/schema"
)

//todo, now in terraform helper, switch over once vended,
func Rfc3339Time(i interface{}, k string) (ws []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s 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 IntBetweenAndNot(min, max, not int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(int)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be int", k))
return
}

if v < min || v > max {
es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v))
return
}

if v == not {
es = append(es, fmt.Errorf("expected %s to not be %d, got %d", k, not, v))
return
}

return
}
}

func Url(i interface{}, k string) (ws []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
return
Copy link
Contributor

Choose a reason for hiding this comment

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

should we be adding a couldn't find it error here?

}

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))
} else if url.Scheme != "http" && url.Scheme != "https" {
Copy link
Contributor

Choose a reason for hiding this comment

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

that's a bit of an assumption given the name of the function - perhaps it's worth renaming this to WebUrl?

errors = append(errors, fmt.Errorf("%q url is neither an http or https uri: %q", k, url.Scheme))
} else if url.Host == "" {
errors = append(errors, fmt.Errorf("%q url has no host: %q", k, url))
}

return
}
43 changes: 43 additions & 0 deletions azurerm/helpers/validate/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package validate
Copy link
Contributor

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?


import "testing"

func TestInternal_ValidateRFC3339Time(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 '%s'", tc.Time)
}
}
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(),
"azurerm_snapshot": resourceArmSnapshot(),
"azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(),
"azurerm_scheduler_job": resourceArmSchedulerJob(),
"azurerm_sql_database": resourceArmSqlDatabase(),
"azurerm_sql_elasticpool": resourceArmSqlElasticPool(),
"azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(),
Expand Down
Loading