Skip to content

Commit 12de912

Browse files
maxi-citmelinath
authored andcommitted
Add Terraform support for antivirus threat override (GoogleCloudPlatform#13444)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 9a139e9 commit 12de912

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

mmv1/products/networksecurity/SecurityProfile.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ properties:
188188
- 'UNKNOWN'
189189
- 'VULNERABILITY'
190190
- 'SPYWARE'
191+
- name: 'antivirusOverrides'
192+
type: Array
193+
is_set: true
194+
description: |
195+
Defines what action to take for antivirus threats per protocol.
196+
item_type:
197+
type: NestedObject
198+
properties:
199+
- name: 'protocol'
200+
type: Enum
201+
description: Required protocol to match.
202+
required: true
203+
enum_values:
204+
- 'SMTP'
205+
- 'SMB'
206+
- 'POP3'
207+
- 'IMAP'
208+
- 'HTTP2'
209+
- 'HTTP'
210+
- 'FTP'
211+
- name: 'action'
212+
type: Enum
213+
description: Threat action override. For some threat types, only a subset of actions applies.
214+
required: true
215+
enum_values:
216+
- 'ALERT'
217+
- 'ALLOW'
218+
- 'DEFAULT_ACTION'
219+
- 'DENY'
191220
conflicts:
192221
- 'customMirroringProfile'
193222
- 'customInterceptProfile'

mmv1/templates/terraform/examples/network_security_security_profile_overrides.tf.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ resource "google_network_security_security_profile" "{{$.PrimaryResourceId}}" {
1919
action = "ALLOW"
2020
threat_id = "280647"
2121
}
22+
23+
antivirus_overrides {
24+
protocol = "SMTP"
25+
action = "ALLOW"
26+
}
2227
}
2328
}

mmv1/third_party/terraform/services/networksecurity/resource_network_security_security_profile_test.go.tmpl

+86
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
89
"github.com/hashicorp/terraform-provider-google/google/acctest"
910
"github.com/hashicorp/terraform-provider-google/google/envvar"
@@ -42,6 +43,58 @@ func TestAccNetworkSecuritySecurityProfiles_update(t *testing.T) {
4243
})
4344
}
4445

46+
func TestAccNetworkSecuritySecurityProfiles_antivirusOverrides(t *testing.T) {
47+
t.Parallel()
48+
49+
orgId := envvar.GetTestOrgFromEnv(t)
50+
randomSuffix := acctest.RandString(t, 10)
51+
52+
acctest.VcrTest(t, resource.TestCase{
53+
PreCheck: func() { acctest.AccTestPreCheck(t) },
54+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
55+
CheckDestroy: testAccCheckNetworkSecuritySecurityProfileDestroyProducer(t),
56+
Steps: []resource.TestStep{
57+
{
58+
Config: testAccNetworkSecuritySecurityProfiles_basic(orgId, randomSuffix),
59+
},
60+
{
61+
ResourceName: "google_network_security_security_profile.foobar",
62+
ImportState: true,
63+
ImportStateVerify: true,
64+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
65+
},
66+
{
67+
Config: testAccNetworkSecuritySecurityProfiles_antivirusOverrides(orgId, randomSuffix),
68+
ConfigPlanChecks: resource.ConfigPlanChecks{
69+
PreApply: []plancheck.PlanCheck{
70+
plancheck.ExpectResourceAction("google_network_security_security_profile.foobar", plancheck.ResourceActionUpdate),
71+
},
72+
},
73+
},
74+
{
75+
ResourceName: "google_network_security_security_profile.foobar",
76+
ImportState: true,
77+
ImportStateVerify: true,
78+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
79+
},
80+
{
81+
Config: testAccNetworkSecuritySecurityProfiles_basic(orgId, randomSuffix),
82+
ConfigPlanChecks: resource.ConfigPlanChecks{
83+
PreApply: []plancheck.PlanCheck{
84+
plancheck.ExpectResourceAction("google_network_security_security_profile.foobar", plancheck.ResourceActionUpdate),
85+
},
86+
},
87+
},
88+
{
89+
ResourceName: "google_network_security_security_profile.foobar",
90+
ImportState: true,
91+
ImportStateVerify: true,
92+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
93+
},
94+
},
95+
})
96+
}
97+
4598
func testAccNetworkSecuritySecurityProfiles_basic(orgId string, randomSuffix string) string {
4699
return fmt.Sprintf(`
47100
resource "google_network_security_security_profile" "foobar" {
@@ -85,3 +138,36 @@ resource "google_network_security_security_profile" "foobar" {
85138
}
86139
`, randomSuffix, orgId)
87140
}
141+
142+
func testAccNetworkSecuritySecurityProfiles_antivirusOverrides(orgId string, randomSuffix string) string {
143+
return fmt.Sprintf(`
144+
resource "google_network_security_security_profile" "foobar" {
145+
name = "tf-test-my-security-profile%s"
146+
parent = "organizations/%s"
147+
location = "global"
148+
description = "My security profile. Update"
149+
type = "THREAT_PREVENTION"
150+
151+
labels = {
152+
foo = "foo"
153+
}
154+
155+
threat_prevention_profile {
156+
antivirus_overrides {
157+
action = "ALLOW"
158+
protocol = "FTP"
159+
}
160+
161+
antivirus_overrides {
162+
action = "DENY"
163+
protocol = "HTTP"
164+
}
165+
166+
antivirus_overrides {
167+
action = "ALERT"
168+
protocol = "HTTP2"
169+
}
170+
}
171+
}
172+
`, randomSuffix, orgId)
173+
}

0 commit comments

Comments
 (0)