Skip to content

Add Terraform support for antivirus threat override #13444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions mmv1/products/networksecurity/SecurityProfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ properties:
- 'UNKNOWN'
- 'VULNERABILITY'
- 'SPYWARE'
- name: 'antivirusOverrides'
type: Array
is_set: true
description: |
Defines what action to take for antivirus threats per protocol.
item_type:
type: NestedObject
properties:
- name: 'protocol'
type: Enum
description: Required protocol to match.
required: true
enum_values:
- 'SMTP'
- 'SMB'
- 'POP3'
- 'IMAP'
- 'HTTP2'
- 'HTTP'
- 'FTP'
- name: 'action'
type: Enum
description: Threat action override. For some threat types, only a subset of actions applies.
required: true
enum_values:
- 'ALERT'
- 'ALLOW'
- 'DEFAULT_ACTION'
- 'DENY'
conflicts:
- 'customMirroringProfile'
- 'customInterceptProfile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ resource "google_network_security_security_profile" "{{$.PrimaryResourceId}}" {
action = "ALLOW"
threat_id = "280647"
}

antivirus_overrides {
protocol = "SMTP"
action = "ALLOW"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@ func TestAccNetworkSecuritySecurityProfiles_update(t *testing.T) {
})
}

func TestAccNetworkSecuritySecurityProfiles_antivirusOverrides(t *testing.T) {
t.Parallel()

orgId := envvar.GetTestOrgFromEnv(t)
randomSuffix := acctest.RandString(t, 10)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckNetworkSecuritySecurityProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNetworkSecuritySecurityProfiles_basic(orgId, randomSuffix),
},
{
ResourceName: "google_network_security_security_profile.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
},
{
Config: testAccNetworkSecuritySecurityProfiles_antivirusOverrides(orgId, randomSuffix),
},
{
ResourceName: "google_network_security_security_profile.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
},
},
})
}

func testAccNetworkSecuritySecurityProfiles_basic(orgId string, randomSuffix string) string {
return fmt.Sprintf(`
resource "google_network_security_security_profile" "foobar" {
Expand Down Expand Up @@ -85,3 +118,36 @@ resource "google_network_security_security_profile" "foobar" {
}
`, randomSuffix, orgId)
}

func testAccNetworkSecuritySecurityProfiles_antivirusOverrides(orgId string, randomSuffix string) string {
return fmt.Sprintf(`
resource "google_network_security_security_profile" "foobar" {
name = "tf-test-my-security-profile%s"
parent = "organizations/%s"
location = "global"
description = "My security profile. Update"
type = "THREAT_PREVENTION"

labels = {
foo = "foo"
}

threat_prevention_profile {
antivirus_overrides {
action = "ALLOW"
protocol = "FTP"
}

antivirus_overrides {
action = "DENY"
protocol = "HTTP"
}

antivirus_overrides {
action = "ALERT"
protocol = "HTTP2"
}
}
}
`, randomSuffix, orgId)
}
Loading