-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #990 from terraform-providers/f-ds-scheduler_job_c…
…ollection New Data Source: `azurerm_scheduler_job_collection`
- Loading branch information
Showing
7 changed files
with
268 additions
and
20 deletions.
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,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 | ||
} |
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,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)) | ||
} |
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
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
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,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. |