forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_scheduler_job_collection.go
113 lines (88 loc) · 2.96 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
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,
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,
},
// 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).schedulerJobCollectionsClient
ctx := meta.(*ArmClient).StopContext
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", azureRMNormalizeLocation(*location))
}
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
}