diff --git a/azurerm/data_source_scheduler_job_collection.go b/azurerm/data_source_scheduler_job_collection.go new file mode 100644 index 000000000000..ce1bfe1ef8fc --- /dev/null +++ b/azurerm/data_source_scheduler_job_collection.go @@ -0,0 +1,108 @@ +package azurerm + +import ( + "fmt" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmSchedulerJobCollection() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmSchedulerJobCollectionRead, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "location": locationForDataSourceSchema(), + + "resource_group_name": resourceGroupNameForDataSourceSchema(), + + "tags": tagsForDataSourceSchema(), + + "sku": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { + Type: schema.TypeString, + Computed: true, + }, + + "quota": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + + //max_job_occurrence doesn't seem to do anything and always remains empty + + "max_job_count": { + Type: schema.TypeInt, + Computed: true, + }, + + "max_recurrence_frequency": { + Type: schema.TypeString, + Computed: true, + }, + + //this is MaxRecurrance.Interval, property is named this as the documentation in the api states: + // Gets or sets the interval between retries. + "max_retry_interval": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceArmSchedulerJobCollectionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).schedulerJobCollectionsClient + ctx := meta.(*ArmClient).StopContext + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + collection, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(collection.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on Scheduler Job Collection %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*collection.ID) + + //standard properties + d.Set("name", collection.Name) + d.Set("location", azureRMNormalizeLocation(*collection.Location)) + d.Set("resource_group_name", resourceGroup) + flattenAndSetTags(d, collection.Tags) + + //resource specific + if properties := collection.Properties; properties != nil { + if sku := properties.Sku; sku != nil { + d.Set("sku", sku.Name) + } + d.Set("state", string(properties.State)) + + if err := d.Set("quota", flattenAzureArmSchedulerJobCollectionQuota(properties.Quota)); err != nil { + return fmt.Errorf("Error flattening quota for Job Collection %q (Resource Group %q): %+v", collection.Name, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/data_source_scheduler_job_collection_test.go b/azurerm/data_source_scheduler_job_collection_test.go new file mode 100644 index 000000000000..aebffec1377c --- /dev/null +++ b/azurerm/data_source_scheduler_job_collection_test.go @@ -0,0 +1,63 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccDataSourceAzureRMSchedulerJobCollection_basic(t *testing.T) { + dataSourceName := "data.azurerm_scheduler_job_collection.test" + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSchedulerJobCollection_basic(ri, testLocation()), + Check: checkAccAzureRMSchedulerJobCollection_basic(dataSourceName), + }, + }, + }) +} + +func TestAccDataSourceAzureRMSchedulerJobCollection_complete(t *testing.T) { + dataSourceName := "data.azurerm_scheduler_job_collection.test" + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSchedulerJobCollection_complete(ri, testLocation()), + Check: checkAccAzureRMSchedulerJobCollection_complete(dataSourceName), + }, + }, + }) +} + +func testAccDataSourceSchedulerJobCollection_basic(rInt int, location string) string { + return fmt.Sprintf(` +%s + +data "azurerm_scheduler_job_collection" "test" { + name = "${azurerm_scheduler_job_collection.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMSchedulerJobCollection_basic(rInt, location, "")) +} + +func testAccDataSourceSchedulerJobCollection_complete(rInt int, location string) string { + return fmt.Sprintf(` +%s + +data "azurerm_scheduler_job_collection" "test" { + name = "${azurerm_scheduler_job_collection.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMSchedulerJobCollection_complete(rInt, location)) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 0330b7b0a76e..55bfae9685c9 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -94,8 +94,9 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ips": dataSourceArmPublicIPs(), "azurerm_resource_group": dataSourceArmResourceGroup(), "azurerm_role_definition": dataSourceArmRoleDefinition(), - "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), "azurerm_snapshot": dataSourceArmSnapshot(), + "azurerm_storage_account": dataSourceArmStorageAccount(), "azurerm_subnet": dataSourceArmSubnet(), "azurerm_subscription": dataSourceArmSubscription(), "azurerm_subscriptions": dataSourceArmSubscriptions(), diff --git a/azurerm/resource_arm_scheduler_job_collection.go b/azurerm/resource_arm_scheduler_job_collection.go index f668e496c8ee..bdcd61a103c1 100644 --- a/azurerm/resource_arm_scheduler_job_collection.go +++ b/azurerm/resource_arm_scheduler_job_collection.go @@ -3,6 +3,7 @@ package azurerm import ( "fmt" "log" + "regexp" "github.com/Azure/azure-sdk-for-go/services/scheduler/mgmt/2016-03-01/scheduler" @@ -28,6 +29,10 @@ func resourceArmSchedulerJobCollection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile("^[a-zA-Z][-_a-zA-Z0-9]{0,99}$"), + "Job Collection Name name must be 1 - 100 characters long, start with a letter and contain only letters, numbers, hyphens and underscores.", + ), }, "location": locationSchema(), @@ -89,7 +94,7 @@ func resourceArmSchedulerJobCollection() *schema.Resource { }, true), }, - //this sets MaxRecurrance.Interval, and the documentation in the api states: + //this is MaxRecurrance.Interval, property is named this as the documentation in the api states: // Gets or sets the interval between retries. "max_retry_interval": { Type: schema.TypeInt, diff --git a/azurerm/resource_arm_scheduler_job_collection_test.go b/azurerm/resource_arm_scheduler_job_collection_test.go index a18e5e05fcdf..8da692f6e334 100644 --- a/azurerm/resource_arm_scheduler_job_collection_test.go +++ b/azurerm/resource_arm_scheduler_job_collection_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/scheduler/mgmt/2016-03-01/scheduler" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -23,11 +24,7 @@ func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSchedulerJobCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Enabled)), - ), + Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName), }, }, }) @@ -46,22 +43,11 @@ func TestAccAzureRMSchedulerJobCollection_complete(t *testing.T) { Steps: []resource.TestStep{ { Config: preConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSchedulerJobCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Enabled)), - ), + Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName), }, { Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSchedulerJobCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Disabled)), - resource.TestCheckResourceAttr(resourceName, "quota.0.max_job_count", "10"), - resource.TestCheckResourceAttr(resourceName, "quota.0.max_retry_interval", "10"), - resource.TestCheckResourceAttr(resourceName, "quota.0.max_recurrence_frequency", "hour"), - ), + Check: checkAccAzureRMSchedulerJobCollection_complete(resourceName), }, }, }) @@ -152,3 +138,28 @@ func testAccAzureRMSchedulerJobCollection_complete(rInt int, location string) st } `) } + +func checkAccAzureRMSchedulerJobCollection_basic(resourceName string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testCheckAzureRMSchedulerJobCollectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "location"), + resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Enabled)), + ) +} + +func checkAccAzureRMSchedulerJobCollection_complete(resourceName string) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMSchedulerJobCollectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "location"), + resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Disabled)), + resource.TestCheckResourceAttr(resourceName, "quota.0.max_job_count", "10"), + resource.TestCheckResourceAttr(resourceName, "quota.0.max_retry_interval", "10"), + resource.TestCheckResourceAttr(resourceName, "quota.0.max_recurrence_frequency", "hour"), + ) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 4d9ca33c17d5..009d3583e01f 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -95,6 +95,10 @@ azurerm_role_definition + > + azurerm_scheduler_job_collection + + > azurerm_storage_account diff --git a/website/docs/d/scheduler_job_collection.html.markdown b/website/docs/d/scheduler_job_collection.html.markdown new file mode 100644 index 000000000000..83727ba78864 --- /dev/null +++ b/website/docs/d/scheduler_job_collection.html.markdown @@ -0,0 +1,56 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_scheduler_job_collection" +sidebar_current: "docs-azurerm-datasource-scheduler_job_collection" +description: |- + Get information about the specified scheduler job collection. +--- + +# Data Source: azurerm_scheduler_job_collection + +Use this data source to access the properties of an Azure scheduler job collection. + +## Example Usage + +```hcl +data "azurerm_scheduler_job_collection" "test" { + name = "tfex-job-collection" + resource_group_name = "tfex-job-collection-rg" +} + +output "job_collection_state" { + value = "${data.azurerm_scheduler_job_collection.jobs.state}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Scheduler Job Collection. + +* `resource_group_name` - (Required) Specifies the name of the resource group in which the Scheduler Job Collection resides. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Scheduler Job Collection. + +* `location` - The Azure location where the resource exists. + +* `tags` - A mapping of tags assigned to the resource. + +* `sku` - The Job Collection's pricing level's SKU. + +* `state` - The Job Collection's state. + +* `quota` - The Job collection quotas as documented in the `quota` block below. + +The `quota` block supports: + +* `max_job_count` - Sets the maximum number of jobs in the collection. + +* `max_recurrence_frequency` - The maximum frequency of recurrence. + +* `max_retry_interval` - The maximum interval between retries.