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 all 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 @@ -190,6 +190,10 @@ type ArmClient struct {
resourceGroupsClient resources.GroupsClient
subscriptionsClient subscriptions.Client

//Scheduler
schedulerJobCollectionsClient scheduler.JobCollectionsClient
schedulerJobsClient scheduler.JobsClient

// Search
searchServicesClient search.ServicesClient

Expand All @@ -200,9 +204,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 @@ -868,6 +869,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 @@ -896,12 +907,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
35 changes: 35 additions & 0 deletions azurerm/helpers/set/set.go
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
}
71 changes: 71 additions & 0 deletions azurerm/helpers/validate/validate.go
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
}
}
45 changes: 45 additions & 0 deletions azurerm/helpers/validate/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 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
}
}
})
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_servicebus_topic": resourceArmServiceBusTopic(),
"azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(),
"azurerm_snapshot": resourceArmSnapshot(),
"azurerm_scheduler_job": resourceArmSchedulerJob(),
"azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(),
"azurerm_sql_database": resourceArmSqlDatabase(),
"azurerm_sql_elasticpool": resourceArmSqlElasticPool(),
Expand Down
Loading