Skip to content

Commit d5fe844

Browse files
Update resource SCC Mute Config with expiry time field (#12979) (#9273)
[upstream:df81d9001b56ac5a9a66a0c77e42e033562a70c2] Signed-off-by: Modular Magician <[email protected]>
1 parent ace951b commit d5fe844

6 files changed

+174
-0
lines changed

Diff for: .changelog/12979.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
securitycenter: added `type`, `expiry_time` field to `google_scc_mute_config` resource
3+
```

Diff for: google-beta/services/securitycenter/resource_scc_mute_config.go

+71
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
3232
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
33+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
3334
)
3435

3536
func ResourceSecurityCenterMuteConfig() *schema.Resource {
@@ -78,6 +79,22 @@ project = Y scope, it might not match any findings.`,
7879
Optional: true,
7980
Description: `A description of the mute config.`,
8081
},
82+
"expiry_time": {
83+
Type: schema.TypeString,
84+
Optional: true,
85+
Description: `Optional. The expiry of the mute config. Only applicable for dynamic configs.
86+
If the expiry is set, when the config expires, it is removed from all findings.
87+
88+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to
89+
nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`,
90+
},
91+
"type": {
92+
Type: schema.TypeString,
93+
Optional: true,
94+
ValidateFunc: verify.ValidateEnum([]string{"MUTE_CONFIG_TYPE_UNSPECIFIED", "STATIC", "DYNAMIC", ""}),
95+
Description: `The type of the mute config, which determines what type of mute state the config affects. Default value: "DYNAMIC" Possible values: ["MUTE_CONFIG_TYPE_UNSPECIFIED", "STATIC", "DYNAMIC"]`,
96+
Default: "DYNAMIC",
97+
},
8198
"create_time": {
8299
Type: schema.TypeString,
83100
Computed: true,
@@ -131,6 +148,18 @@ func resourceSecurityCenterMuteConfigCreate(d *schema.ResourceData, meta interfa
131148
} else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) {
132149
obj["filter"] = filterProp
133150
}
151+
typeProp, err := expandSecurityCenterMuteConfigType(d.Get("type"), d, config)
152+
if err != nil {
153+
return err
154+
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
155+
obj["type"] = typeProp
156+
}
157+
expiryTimeProp, err := expandSecurityCenterMuteConfigExpiryTime(d.Get("expiry_time"), d, config)
158+
if err != nil {
159+
return err
160+
} else if v, ok := d.GetOkExists("expiry_time"); !tpgresource.IsEmptyValue(reflect.ValueOf(expiryTimeProp)) && (ok || !reflect.DeepEqual(v, expiryTimeProp)) {
161+
obj["expiryTime"] = expiryTimeProp
162+
}
134163

135164
url, err := tpgresource.ReplaceVars(d, config, "{{SecurityCenterBasePath}}{{parent}}/muteConfigs?muteConfigId={{mute_config_id}}")
136165
if err != nil {
@@ -225,6 +254,12 @@ func resourceSecurityCenterMuteConfigRead(d *schema.ResourceData, meta interface
225254
if err := d.Set("most_recent_editor", flattenSecurityCenterMuteConfigMostRecentEditor(res["mostRecentEditor"], d, config)); err != nil {
226255
return fmt.Errorf("Error reading MuteConfig: %s", err)
227256
}
257+
if err := d.Set("type", flattenSecurityCenterMuteConfigType(res["type"], d, config)); err != nil {
258+
return fmt.Errorf("Error reading MuteConfig: %s", err)
259+
}
260+
if err := d.Set("expiry_time", flattenSecurityCenterMuteConfigExpiryTime(res["expiryTime"], d, config)); err != nil {
261+
return fmt.Errorf("Error reading MuteConfig: %s", err)
262+
}
228263

229264
return nil
230265
}
@@ -251,6 +286,18 @@ func resourceSecurityCenterMuteConfigUpdate(d *schema.ResourceData, meta interfa
251286
} else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, filterProp)) {
252287
obj["filter"] = filterProp
253288
}
289+
typeProp, err := expandSecurityCenterMuteConfigType(d.Get("type"), d, config)
290+
if err != nil {
291+
return err
292+
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, typeProp)) {
293+
obj["type"] = typeProp
294+
}
295+
expiryTimeProp, err := expandSecurityCenterMuteConfigExpiryTime(d.Get("expiry_time"), d, config)
296+
if err != nil {
297+
return err
298+
} else if v, ok := d.GetOkExists("expiry_time"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, expiryTimeProp)) {
299+
obj["expiryTime"] = expiryTimeProp
300+
}
254301

255302
url, err := tpgresource.ReplaceVars(d, config, "{{SecurityCenterBasePath}}{{name}}")
256303
if err != nil {
@@ -268,6 +315,14 @@ func resourceSecurityCenterMuteConfigUpdate(d *schema.ResourceData, meta interfa
268315
if d.HasChange("filter") {
269316
updateMask = append(updateMask, "filter")
270317
}
318+
319+
if d.HasChange("type") {
320+
updateMask = append(updateMask, "type")
321+
}
322+
323+
if d.HasChange("expiry_time") {
324+
updateMask = append(updateMask, "expiryTime")
325+
}
271326
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
272327
// won't set it
273328
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -407,10 +462,26 @@ func flattenSecurityCenterMuteConfigMostRecentEditor(v interface{}, d *schema.Re
407462
return v
408463
}
409464

465+
func flattenSecurityCenterMuteConfigType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
466+
return v
467+
}
468+
469+
func flattenSecurityCenterMuteConfigExpiryTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
470+
return v
471+
}
472+
410473
func expandSecurityCenterMuteConfigDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
411474
return v, nil
412475
}
413476

414477
func expandSecurityCenterMuteConfigFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
415478
return v, nil
416479
}
480+
481+
func expandSecurityCenterMuteConfigType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
482+
return v, nil
483+
}
484+
485+
func expandSecurityCenterMuteConfigExpiryTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
486+
return v, nil
487+
}

Diff for: google-beta/services/securitycenter/resource_scc_mute_config_generated_meta.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ api_resource_type_kind: 'MuteConfig'
77
fields:
88
- field: 'create_time'
99
- field: 'description'
10+
- field: 'expiry_time'
1011
- field: 'filter'
1112
- field: 'most_recent_editor'
1213
- field: 'mute_config_id'
1314
provider_only: true
1415
- field: 'name'
1516
- field: 'parent'
1617
provider_only: true
18+
- field: 'type'
1719
- field: 'update_time'

Diff for: google-beta/services/securitycenter/resource_scc_mute_config_generated_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ resource "google_scc_mute_config" "default" {
6464
parent = "organizations/%{org_id}"
6565
filter = "category: \"OS_VULNERABILITY\""
6666
description = "My Mute Config"
67+
type = "DYNAMIC"
68+
expiry_time = "2215-02-03T15:01:23Z"
6769
}
6870
`, context)
6971
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package securitycenter_test
4+
5+
import (
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
10+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
11+
)
12+
13+
func TestAccSecurityCenterMuteConfig(t *testing.T) {
14+
t.Parallel()
15+
16+
context := map[string]interface{}{
17+
"org_id": envvar.GetTestOrgFromEnv(t),
18+
"random_suffix": acctest.RandString(t, 10),
19+
}
20+
21+
acctest.VcrTest(t, resource.TestCase{
22+
PreCheck: func() { acctest.AccTestPreCheck(t) },
23+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
24+
ExternalProviders: map[string]resource.ExternalProvider{
25+
"random": {},
26+
"time": {},
27+
},
28+
Steps: []resource.TestStep{
29+
{
30+
Config: testAccSecurityCenterMuteConfig_basic(context),
31+
},
32+
{
33+
ResourceName: "google_scc_mute_config.default",
34+
ImportState: true,
35+
ImportStateVerify: true,
36+
ImportStateVerifyIgnore: []string{
37+
"mute_config_id",
38+
},
39+
},
40+
{
41+
Config: testAccSecurityCenterMuteConfig_update(context),
42+
},
43+
{
44+
ResourceName: "google_scc_mute_config.default",
45+
ImportState: true,
46+
ImportStateVerify: true,
47+
ImportStateVerifyIgnore: []string{
48+
"mute_config_id",
49+
},
50+
},
51+
},
52+
})
53+
}
54+
55+
func testAccSecurityCenterMuteConfig_basic(context map[string]interface{}) string {
56+
return acctest.Nprintf(`
57+
58+
resource "google_scc_mute_config" "default" {
59+
mute_config_id = "tf-test-mute-config-%{random_suffix}"
60+
parent = "organizations/%{org_id}"
61+
filter = "category: \"OS_VULNERABILITY\""
62+
description = "A Test Mute Config"
63+
type = "DYNAMIC"
64+
expiry_time = "2215-02-03T15:01:23Z"
65+
}
66+
`, context)
67+
}
68+
69+
func testAccSecurityCenterMuteConfig_update(context map[string]interface{}) string {
70+
return acctest.Nprintf(`
71+
72+
resource "google_scc_mute_config" "default" {
73+
mute_config_id = "tf-test-mute-config-%{random_suffix}"
74+
parent = "organizations/%{org_id}"
75+
filter = "category: \"OS_VULNERABILITY\""
76+
description = "An Updated Test Mute Config"
77+
type = "DYNAMIC"
78+
expiry_time = "2215-02-03T15:01:23Z"
79+
}
80+
`, context)
81+
}

Diff for: website/docs/r/scc_mute_config.html.markdown

+15
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ resource "google_scc_mute_config" "default" {
4141
parent = "organizations/123456789"
4242
filter = "category: \"OS_VULNERABILITY\""
4343
description = "My Mute Config"
44+
type = "DYNAMIC"
45+
expiry_time = "2215-02-03T15:01:23Z"
4446
}
4547
```
4648

@@ -75,6 +77,19 @@ The following arguments are supported:
7577
(Optional)
7678
A description of the mute config.
7779

80+
* `type` -
81+
(Optional)
82+
The type of the mute config, which determines what type of mute state the config affects.
83+
Default value is `DYNAMIC`.
84+
Possible values are: `MUTE_CONFIG_TYPE_UNSPECIFIED`, `STATIC`, `DYNAMIC`.
85+
86+
* `expiry_time` -
87+
(Optional)
88+
Optional. The expiry of the mute config. Only applicable for dynamic configs.
89+
If the expiry is set, when the config expires, it is removed from all findings.
90+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to
91+
nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
92+
7893

7994
## Attributes Reference
8095

0 commit comments

Comments
 (0)