@@ -2,7 +2,6 @@ package monitor
2
2
3
3
import (
4
4
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5
- "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
6
5
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
7
6
8
7
"github.com/Azure/azure-sdk-for-go/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement"
@@ -28,109 +27,7 @@ var weekDayMap = map[string]int{
28
27
"Saturday" : 6 ,
29
28
}
30
29
31
- func schemaActionRuleAlertContextCondtion () * schema.Schema {
32
- return schemaActionRuleCondtion (
33
- validation .StringInSlice ([]string {
34
- string (alertsmanagement .Equals ),
35
- string (alertsmanagement .NotEquals ),
36
- string (alertsmanagement .Contains ),
37
- string (alertsmanagement .DoesNotContain ),
38
- }, false ),
39
- validation .StringIsNotEmpty ,
40
- )
41
- }
42
-
43
- func schemaActionRuleAlertRuleIDCondtion () * schema.Schema {
44
- return schemaActionRuleCondtion (
45
- validation .StringInSlice ([]string {
46
- string (alertsmanagement .Equals ),
47
- string (alertsmanagement .NotEquals ),
48
- string (alertsmanagement .Contains ),
49
- string (alertsmanagement .DoesNotContain ),
50
- }, false ),
51
- validation .StringIsNotEmpty ,
52
- )
53
- }
54
-
55
- func schemaActionRuleDescriptionCondtion () * schema.Schema {
56
- return schemaActionRuleCondtion (
57
- validation .StringInSlice ([]string {
58
- string (alertsmanagement .Equals ),
59
- string (alertsmanagement .NotEquals ),
60
- string (alertsmanagement .Contains ),
61
- string (alertsmanagement .DoesNotContain ),
62
- }, false ),
63
- validation .StringIsNotEmpty ,
64
- )
65
- }
66
-
67
- func schemaActionRuleMonitorCondtion () * schema.Schema {
68
- return schemaActionRuleCondtion (
69
- validation .StringInSlice ([]string {
70
- string (alertsmanagement .Equals ),
71
- string (alertsmanagement .NotEquals ),
72
- }, false ),
73
- validation .StringInSlice ([]string {
74
- string (alertsmanagement .Fired ),
75
- string (alertsmanagement .Resolved ),
76
- }, false ),
77
- )
78
- }
79
-
80
- func schemaActionRuleMonitorServiceCondtion () * schema.Schema {
81
- return schemaActionRuleCondtion (
82
- validation .StringInSlice ([]string {
83
- string (alertsmanagement .Equals ),
84
- string (alertsmanagement .NotEquals ),
85
- }, false ),
86
- // the supported type list is not consistent with the swagger and sdk
87
- // https://github.com/Azure/azure-rest-api-specs/issues/9076
88
- // directly use string constant
89
- validation .StringInSlice ([]string {
90
- "ActivityLog Administrative" ,
91
- "ActivityLog Autoscale" ,
92
- "ActivityLog Policy" ,
93
- "ActivityLog Recommendation" ,
94
- "ActivityLog Security" ,
95
- "Application Insights" ,
96
- "Azure Backup" ,
97
- "Data Box Edge" ,
98
- "Data Box Gateway" ,
99
- "Health Platform" ,
100
- "Log Analytics" ,
101
- "Platform" ,
102
- "Resource Health" ,
103
- }, false ),
104
- )
105
- }
106
-
107
- func schemaActionRuleSeverityCondtion () * schema.Schema {
108
- return schemaActionRuleCondtion (
109
- validation .StringInSlice ([]string {
110
- string (alertsmanagement .Equals ),
111
- string (alertsmanagement .NotEquals ),
112
- }, false ),
113
- validation .StringInSlice ([]string {
114
- string (alertsmanagement .Sev0 ),
115
- string (alertsmanagement .Sev1 ),
116
- string (alertsmanagement .Sev2 ),
117
- string (alertsmanagement .Sev3 ),
118
- string (alertsmanagement .Sev4 ),
119
- }, false ),
120
- )
121
- }
122
-
123
- func schemaActionRuleTargetResourceTypeCondtion () * schema.Schema {
124
- return schemaActionRuleCondtion (
125
- validation .StringInSlice ([]string {
126
- string (alertsmanagement .Equals ),
127
- string (alertsmanagement .NotEquals ),
128
- }, false ),
129
- validation .StringIsNotEmpty ,
130
- )
131
- }
132
-
133
- func schemaActionRuleCondtion (operatorValidateFunc , valuesValidateFunc schema.SchemaValidateFunc ) * schema.Schema {
30
+ func schemaActionRuleCondition (operatorValidateFunc , valuesValidateFunc schema.SchemaValidateFunc ) * schema.Schema {
134
31
return & schema.Schema {
135
32
Type : schema .TypeList ,
136
33
Optional : true ,
@@ -168,6 +65,35 @@ func expandArmActionRuleCondition(input []interface{}) *alertsmanagement.Conditi
168
65
}
169
66
}
170
67
68
+ func expandArmActionRuleScope (input []interface {}) * alertsmanagement.Scope {
69
+ if len (input ) == 0 {
70
+ return nil
71
+ }
72
+
73
+ v := input [0 ].(map [string ]interface {})
74
+ return & alertsmanagement.Scope {
75
+ ScopeType : alertsmanagement .ScopeType (v ["type" ].(string )),
76
+ Values : utils .ExpandStringSlice (v ["resource_ids" ].(* schema.Set ).List ()),
77
+ }
78
+ }
79
+
80
+ func expandArmActionRuleConditions (input []interface {}) * alertsmanagement.Conditions {
81
+ if len (input ) == 0 {
82
+ return nil
83
+ }
84
+ v := input [0 ].(map [string ]interface {})
85
+
86
+ return & alertsmanagement.Conditions {
87
+ AlertContext : expandArmActionRuleCondition (v ["alert_context" ].([]interface {})),
88
+ AlertRuleID : expandArmActionRuleCondition (v ["alert_rule_id" ].([]interface {})),
89
+ Description : expandArmActionRuleCondition (v ["description" ].([]interface {})),
90
+ MonitorCondition : expandArmActionRuleCondition (v ["monitor" ].([]interface {})),
91
+ MonitorService : expandArmActionRuleCondition (v ["monitor_service" ].([]interface {})),
92
+ Severity : expandArmActionRuleCondition (v ["severity" ].([]interface {})),
93
+ TargetResourceType : expandArmActionRuleCondition (v ["target_resource_type" ].([]interface {})),
94
+ }
95
+ }
96
+
171
97
func flattenArmActionRuleCondition (input * alertsmanagement.Condition ) []interface {} {
172
98
if input == nil {
173
99
return make ([]interface {}, 0 )
@@ -184,3 +110,47 @@ func flattenArmActionRuleCondition(input *alertsmanagement.Condition) []interfac
184
110
},
185
111
}
186
112
}
113
+
114
+ func flattenArmActionRuleScope (input * alertsmanagement.Scope ) []interface {} {
115
+ if input == nil {
116
+ return make ([]interface {}, 0 )
117
+ }
118
+
119
+ var scopeType alertsmanagement.ScopeType
120
+ if input .ScopeType != "" {
121
+ scopeType = input .ScopeType
122
+ }
123
+ return []interface {}{
124
+ map [string ]interface {}{
125
+ "type" : scopeType ,
126
+ "resource_ids" : utils .FlattenStringSlice (input .Values ),
127
+ },
128
+ }
129
+ }
130
+
131
+ func flattenArmActionRuleConditions (input * alertsmanagement.Conditions ) []interface {} {
132
+ if input == nil {
133
+ return make ([]interface {}, 0 )
134
+ }
135
+ return []interface {}{
136
+ map [string ]interface {}{
137
+ "alert_context" : flattenArmActionRuleCondition (input .AlertContext ),
138
+ "alert_rule_id" : flattenArmActionRuleCondition (input .AlertRuleID ),
139
+ "description" : flattenArmActionRuleCondition (input .Description ),
140
+ "monitor" : flattenArmActionRuleCondition (input .MonitorCondition ),
141
+ "monitor_service" : flattenArmActionRuleCondition (input .MonitorService ),
142
+ "severity" : flattenArmActionRuleCondition (input .Severity ),
143
+ "target_resource_type" : flattenArmActionRuleCondition (input .TargetResourceType ),
144
+ },
145
+ }
146
+ }
147
+
148
+ func FlattenInt32Slice (input * []int32 ) []interface {} {
149
+ result := make ([]interface {}, 0 )
150
+ if input != nil {
151
+ for _ , item := range * input {
152
+ result = append (result , item )
153
+ }
154
+ }
155
+ return result
156
+ }
0 commit comments