-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
data_source_scheduler_job_collection.go
122 lines (96 loc) · 3.57 KB
/
data_source_scheduler_job_collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package azurerm
import (
"fmt"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmSchedulerJobCollection() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSchedulerJobCollectionRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
DeprecationMessage: "Scheduler Job Collection has been deprecated in favour of Logic Apps - more information can be found at https://docs.microsoft.com/en-us/azure/scheduler/migrate-from-scheduler-to-logic-apps",
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"location": azure.SchemaLocationForDataSource(),
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"tags": tags.SchemaDataSource(),
"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,
},
// API documentation states the MaxRecurrence.Interval "Gets or sets the interval between retries."
// however it does appear it is the max interval allowed for recurrences
"max_retry_interval": {
Type: schema.TypeInt,
Deprecated: "Renamed to `max_recurrence_interval` to match azure",
Computed: true,
},
"max_recurrence_interval": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
}
}
func dataSourceArmSchedulerJobCollectionRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Scheduler.JobCollectionsClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
collection, err := client.Get(ctx, resourceGroup, name) //nolint: megacheck
if err != nil {
if utils.ResponseWasNotFound(collection.Response) {
return fmt.Errorf("Error: Scheduler Job Collection %q (Resource Group %q) was not found", name, resourceGroup)
}
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("resource_group_name", resourceGroup)
if location := collection.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
//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 setting quota for Job Collection %q (Resource Group %q): %+v", *collection.Name, resourceGroup, err)
}
}
return tags.FlattenAndSet(d, collection.Tags)
}