Skip to content

Commit 0a69683

Browse files
Change Threat Prevention Profile's properties to sets. (#12814) (#21070)
[upstream:f66cabc0b5c9ba853237f9f387d318b9c35b7638] Signed-off-by: Modular Magician <[email protected]>
1 parent 34754b4 commit 0a69683

File tree

2 files changed

+57
-42
lines changed

2 files changed

+57
-42
lines changed

.changelog/12814.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
networksecurity: fixed sporadic-diff in `google_network_security_security_profile`
3+
```

google/services/networksecurity/resource_network_security_security_profile.go

+54-42
Original file line numberDiff line numberDiff line change
@@ -142,52 +142,20 @@ Format: organizations/{organization_id}.`,
142142
Elem: &schema.Resource{
143143
Schema: map[string]*schema.Schema{
144144
"severity_overrides": {
145-
Type: schema.TypeList,
145+
Type: schema.TypeSet,
146146
Optional: true,
147147
Description: `The configuration for overriding threats actions by severity match.`,
148-
Elem: &schema.Resource{
149-
Schema: map[string]*schema.Schema{
150-
"action": {
151-
Type: schema.TypeString,
152-
Required: true,
153-
ValidateFunc: verify.ValidateEnum([]string{"ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"}),
154-
Description: `Threat action override. Possible values: ["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"]`,
155-
},
156-
"severity": {
157-
Type: schema.TypeString,
158-
Required: true,
159-
ValidateFunc: verify.ValidateEnum([]string{"CRITICAL", "HIGH", "INFORMATIONAL", "LOW", "MEDIUM"}),
160-
Description: `Severity level to match. Possible values: ["CRITICAL", "HIGH", "INFORMATIONAL", "LOW", "MEDIUM"]`,
161-
},
162-
},
163-
},
148+
Elem: networksecuritySecurityProfileThreatPreventionProfileSeverityOverridesSchema(),
149+
// Default schema.HashSchema is used.
164150
},
165151
"threat_overrides": {
166-
Type: schema.TypeList,
152+
Type: schema.TypeSet,
167153
Optional: true,
168154
Description: `The configuration for overriding threats actions by threat id match.
169155
If a threat is matched both by configuration provided in severity overrides
170156
and threat overrides, the threat overrides action is applied.`,
171-
Elem: &schema.Resource{
172-
Schema: map[string]*schema.Schema{
173-
"action": {
174-
Type: schema.TypeString,
175-
Required: true,
176-
ValidateFunc: verify.ValidateEnum([]string{"ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"}),
177-
Description: `Threat action. Possible values: ["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"]`,
178-
},
179-
"threat_id": {
180-
Type: schema.TypeString,
181-
Required: true,
182-
Description: `Vendor-specific ID of a threat to override.`,
183-
},
184-
"type": {
185-
Type: schema.TypeString,
186-
Computed: true,
187-
Description: `Type of threat.`,
188-
},
189-
},
190-
},
157+
Elem: networksecuritySecurityProfileThreatPreventionProfileThreatOverridesSchema(),
158+
// Default schema.HashSchema is used.
191159
},
192160
},
193161
},
@@ -233,6 +201,48 @@ value before proceeding.`,
233201
}
234202
}
235203

204+
func networksecuritySecurityProfileThreatPreventionProfileSeverityOverridesSchema() *schema.Resource {
205+
return &schema.Resource{
206+
Schema: map[string]*schema.Schema{
207+
"action": {
208+
Type: schema.TypeString,
209+
Required: true,
210+
ValidateFunc: verify.ValidateEnum([]string{"ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"}),
211+
Description: `Threat action override. Possible values: ["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"]`,
212+
},
213+
"severity": {
214+
Type: schema.TypeString,
215+
Required: true,
216+
ValidateFunc: verify.ValidateEnum([]string{"CRITICAL", "HIGH", "INFORMATIONAL", "LOW", "MEDIUM"}),
217+
Description: `Severity level to match. Possible values: ["CRITICAL", "HIGH", "INFORMATIONAL", "LOW", "MEDIUM"]`,
218+
},
219+
},
220+
}
221+
}
222+
223+
func networksecuritySecurityProfileThreatPreventionProfileThreatOverridesSchema() *schema.Resource {
224+
return &schema.Resource{
225+
Schema: map[string]*schema.Schema{
226+
"action": {
227+
Type: schema.TypeString,
228+
Required: true,
229+
ValidateFunc: verify.ValidateEnum([]string{"ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"}),
230+
Description: `Threat action. Possible values: ["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"]`,
231+
},
232+
"threat_id": {
233+
Type: schema.TypeString,
234+
Required: true,
235+
Description: `Vendor-specific ID of a threat to override.`,
236+
},
237+
"type": {
238+
Type: schema.TypeString,
239+
Computed: true,
240+
Description: `Type of threat.`,
241+
},
242+
},
243+
}
244+
}
245+
236246
func resourceNetworkSecuritySecurityProfileCreate(d *schema.ResourceData, meta interface{}) error {
237247
var project string
238248
config := meta.(*transport_tpg.Config)
@@ -638,14 +648,14 @@ func flattenNetworkSecuritySecurityProfileThreatPreventionProfileSeverityOverrid
638648
return v
639649
}
640650
l := v.([]interface{})
641-
transformed := make([]interface{}, 0, len(l))
651+
transformed := schema.NewSet(schema.HashResource(networksecuritySecurityProfileThreatPreventionProfileSeverityOverridesSchema()), []interface{}{})
642652
for _, raw := range l {
643653
original := raw.(map[string]interface{})
644654
if len(original) < 1 {
645655
// Do not include empty json objects coming back from the api
646656
continue
647657
}
648-
transformed = append(transformed, map[string]interface{}{
658+
transformed.Add(map[string]interface{}{
649659
"action": flattenNetworkSecuritySecurityProfileThreatPreventionProfileSeverityOverridesAction(original["action"], d, config),
650660
"severity": flattenNetworkSecuritySecurityProfileThreatPreventionProfileSeverityOverridesSeverity(original["severity"], d, config),
651661
})
@@ -665,14 +675,14 @@ func flattenNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverrides
665675
return v
666676
}
667677
l := v.([]interface{})
668-
transformed := make([]interface{}, 0, len(l))
678+
transformed := schema.NewSet(schema.HashResource(networksecuritySecurityProfileThreatPreventionProfileThreatOverridesSchema()), []interface{}{})
669679
for _, raw := range l {
670680
original := raw.(map[string]interface{})
671681
if len(original) < 1 {
672682
// Do not include empty json objects coming back from the api
673683
continue
674684
}
675-
transformed = append(transformed, map[string]interface{}{
685+
transformed.Add(map[string]interface{}{
676686
"action": flattenNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverridesAction(original["action"], d, config),
677687
"threat_id": flattenNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverridesThreatId(original["threatId"], d, config),
678688
"type": flattenNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverridesType(original["type"], d, config),
@@ -780,6 +790,7 @@ func expandNetworkSecuritySecurityProfileThreatPreventionProfile(v interface{},
780790
}
781791

782792
func expandNetworkSecuritySecurityProfileThreatPreventionProfileSeverityOverrides(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
793+
v = v.(*schema.Set).List()
783794
l := v.([]interface{})
784795
req := make([]interface{}, 0, len(l))
785796
for _, raw := range l {
@@ -817,6 +828,7 @@ func expandNetworkSecuritySecurityProfileThreatPreventionProfileSeverityOverride
817828
}
818829

819830
func expandNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverrides(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
831+
v = v.(*schema.Set).List()
820832
l := v.([]interface{})
821833
req := make([]interface{}, 0, len(l))
822834
for _, raw := range l {

0 commit comments

Comments
 (0)