Skip to content

Commit 7fd434b

Browse files
Support new Network Security Integration security profile types (#12816) (#9110)
[upstream:db31db4510175885374eaa1b051f64396103a02a] Signed-off-by: Modular Magician <[email protected]>
1 parent 5f92f81 commit 7fd434b

9 files changed

+687
-3
lines changed

.changelog/12816.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networksecurity: added `customMirroringProfile` and `customInterceptProfile` fields to `google_network_security_security_profile` and `google_network_security_security_profile_group` resources
3+
```

google-beta/services/networksecurity/resource_network_security_security_profile.go

+157-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,44 @@ func ResourceNetworkSecuritySecurityProfile() *schema.Resource {
6565
Type: schema.TypeString,
6666
Required: true,
6767
ForceNew: true,
68-
ValidateFunc: verify.ValidateEnum([]string{"THREAT_PREVENTION"}),
69-
Description: `The type of security profile. Possible values: ["THREAT_PREVENTION"]`,
68+
ValidateFunc: verify.ValidateEnum([]string{"THREAT_PREVENTION", "CUSTOM_MIRRORING", "CUSTOM_INTERCEPT"}),
69+
Description: `The type of security profile. Possible values: ["THREAT_PREVENTION", "CUSTOM_MIRRORING", "CUSTOM_INTERCEPT"]`,
70+
},
71+
"custom_intercept_profile": {
72+
Type: schema.TypeList,
73+
Optional: true,
74+
Description: `The configuration for defining the Intercept Endpoint Group used to
75+
intercept traffic to third-party firewall appliances.`,
76+
MaxItems: 1,
77+
Elem: &schema.Resource{
78+
Schema: map[string]*schema.Schema{
79+
"intercept_endpoint_group": {
80+
Type: schema.TypeString,
81+
Required: true,
82+
Description: `The Intercept Endpoint Group to which matching traffic should be intercepted.
83+
Format: projects/{project_id}/locations/global/interceptEndpointGroups/{endpoint_group_id}`,
84+
},
85+
},
86+
},
87+
ConflictsWith: []string{"threat_prevention_profile", "custom_mirroring_profile"},
88+
},
89+
"custom_mirroring_profile": {
90+
Type: schema.TypeList,
91+
Optional: true,
92+
Description: `The configuration for defining the Mirroring Endpoint Group used to
93+
mirror traffic to third-party collectors.`,
94+
MaxItems: 1,
95+
Elem: &schema.Resource{
96+
Schema: map[string]*schema.Schema{
97+
"mirroring_endpoint_group": {
98+
Type: schema.TypeString,
99+
Required: true,
100+
Description: `The Mirroring Endpoint Group to which matching traffic should be mirrored.
101+
Format: projects/{project_id}/locations/global/mirroringEndpointGroups/{endpoint_group_id}`,
102+
},
103+
},
104+
},
105+
ConflictsWith: []string{"threat_prevention_profile", "custom_intercept_profile"},
70106
},
71107
"description": {
72108
Type: schema.TypeString,
@@ -155,6 +191,7 @@ and threat overrides, the threat overrides action is applied.`,
155191
},
156192
},
157193
},
194+
ConflictsWith: []string{"custom_mirroring_profile", "custom_intercept_profile"},
158195
},
159196
"create_time": {
160197
Type: schema.TypeString,
@@ -217,6 +254,18 @@ func resourceNetworkSecuritySecurityProfileCreate(d *schema.ResourceData, meta i
217254
} else if v, ok := d.GetOkExists("threat_prevention_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(threatPreventionProfileProp)) && (ok || !reflect.DeepEqual(v, threatPreventionProfileProp)) {
218255
obj["threatPreventionProfile"] = threatPreventionProfileProp
219256
}
257+
customMirroringProfileProp, err := expandNetworkSecuritySecurityProfileCustomMirroringProfile(d.Get("custom_mirroring_profile"), d, config)
258+
if err != nil {
259+
return err
260+
} else if v, ok := d.GetOkExists("custom_mirroring_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(customMirroringProfileProp)) && (ok || !reflect.DeepEqual(v, customMirroringProfileProp)) {
261+
obj["customMirroringProfile"] = customMirroringProfileProp
262+
}
263+
customInterceptProfileProp, err := expandNetworkSecuritySecurityProfileCustomInterceptProfile(d.Get("custom_intercept_profile"), d, config)
264+
if err != nil {
265+
return err
266+
} else if v, ok := d.GetOkExists("custom_intercept_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(customInterceptProfileProp)) && (ok || !reflect.DeepEqual(v, customInterceptProfileProp)) {
267+
obj["customInterceptProfile"] = customInterceptProfileProp
268+
}
220269
typeProp, err := expandNetworkSecuritySecurityProfileType(d.Get("type"), d, config)
221270
if err != nil {
222271
return err
@@ -333,6 +382,12 @@ func resourceNetworkSecuritySecurityProfileRead(d *schema.ResourceData, meta int
333382
if err := d.Set("threat_prevention_profile", flattenNetworkSecuritySecurityProfileThreatPreventionProfile(res["threatPreventionProfile"], d, config)); err != nil {
334383
return fmt.Errorf("Error reading SecurityProfile: %s", err)
335384
}
385+
if err := d.Set("custom_mirroring_profile", flattenNetworkSecuritySecurityProfileCustomMirroringProfile(res["customMirroringProfile"], d, config)); err != nil {
386+
return fmt.Errorf("Error reading SecurityProfile: %s", err)
387+
}
388+
if err := d.Set("custom_intercept_profile", flattenNetworkSecuritySecurityProfileCustomInterceptProfile(res["customInterceptProfile"], d, config)); err != nil {
389+
return fmt.Errorf("Error reading SecurityProfile: %s", err)
390+
}
336391
if err := d.Set("type", flattenNetworkSecuritySecurityProfileType(res["type"], d, config)); err != nil {
337392
return fmt.Errorf("Error reading SecurityProfile: %s", err)
338393
}
@@ -369,6 +424,18 @@ func resourceNetworkSecuritySecurityProfileUpdate(d *schema.ResourceData, meta i
369424
} else if v, ok := d.GetOkExists("threat_prevention_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, threatPreventionProfileProp)) {
370425
obj["threatPreventionProfile"] = threatPreventionProfileProp
371426
}
427+
customMirroringProfileProp, err := expandNetworkSecuritySecurityProfileCustomMirroringProfile(d.Get("custom_mirroring_profile"), d, config)
428+
if err != nil {
429+
return err
430+
} else if v, ok := d.GetOkExists("custom_mirroring_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, customMirroringProfileProp)) {
431+
obj["customMirroringProfile"] = customMirroringProfileProp
432+
}
433+
customInterceptProfileProp, err := expandNetworkSecuritySecurityProfileCustomInterceptProfile(d.Get("custom_intercept_profile"), d, config)
434+
if err != nil {
435+
return err
436+
} else if v, ok := d.GetOkExists("custom_intercept_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, customInterceptProfileProp)) {
437+
obj["customInterceptProfile"] = customInterceptProfileProp
438+
}
372439
labelsProp, err := expandNetworkSecuritySecurityProfileEffectiveLabels(d.Get("effective_labels"), d, config)
373440
if err != nil {
374441
return err
@@ -393,6 +460,14 @@ func resourceNetworkSecuritySecurityProfileUpdate(d *schema.ResourceData, meta i
393460
updateMask = append(updateMask, "threatPreventionProfile")
394461
}
395462

463+
if d.HasChange("custom_mirroring_profile") {
464+
updateMask = append(updateMask, "customMirroringProfile")
465+
}
466+
467+
if d.HasChange("custom_intercept_profile") {
468+
updateMask = append(updateMask, "customInterceptProfile")
469+
}
470+
396471
if d.HasChange("effective_labels") {
397472
updateMask = append(updateMask, "labels")
398473
}
@@ -617,6 +692,40 @@ func flattenNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverrides
617692
return v
618693
}
619694

695+
func flattenNetworkSecuritySecurityProfileCustomMirroringProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
696+
if v == nil {
697+
return nil
698+
}
699+
original := v.(map[string]interface{})
700+
if len(original) == 0 {
701+
return nil
702+
}
703+
transformed := make(map[string]interface{})
704+
transformed["mirroring_endpoint_group"] =
705+
flattenNetworkSecuritySecurityProfileCustomMirroringProfileMirroringEndpointGroup(original["mirroringEndpointGroup"], d, config)
706+
return []interface{}{transformed}
707+
}
708+
func flattenNetworkSecuritySecurityProfileCustomMirroringProfileMirroringEndpointGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
709+
return v
710+
}
711+
712+
func flattenNetworkSecuritySecurityProfileCustomInterceptProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
713+
if v == nil {
714+
return nil
715+
}
716+
original := v.(map[string]interface{})
717+
if len(original) == 0 {
718+
return nil
719+
}
720+
transformed := make(map[string]interface{})
721+
transformed["intercept_endpoint_group"] =
722+
flattenNetworkSecuritySecurityProfileCustomInterceptProfileInterceptEndpointGroup(original["interceptEndpointGroup"], d, config)
723+
return []interface{}{transformed}
724+
}
725+
func flattenNetworkSecuritySecurityProfileCustomInterceptProfileInterceptEndpointGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
726+
return v
727+
}
728+
620729
func flattenNetworkSecuritySecurityProfileType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
621730
return v
622731
}
@@ -755,6 +864,52 @@ func expandNetworkSecuritySecurityProfileThreatPreventionProfileThreatOverridesT
755864
return v, nil
756865
}
757866

867+
func expandNetworkSecuritySecurityProfileCustomMirroringProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
868+
l := v.([]interface{})
869+
if len(l) == 0 || l[0] == nil {
870+
return nil, nil
871+
}
872+
raw := l[0]
873+
original := raw.(map[string]interface{})
874+
transformed := make(map[string]interface{})
875+
876+
transformedMirroringEndpointGroup, err := expandNetworkSecuritySecurityProfileCustomMirroringProfileMirroringEndpointGroup(original["mirroring_endpoint_group"], d, config)
877+
if err != nil {
878+
return nil, err
879+
} else if val := reflect.ValueOf(transformedMirroringEndpointGroup); val.IsValid() && !tpgresource.IsEmptyValue(val) {
880+
transformed["mirroringEndpointGroup"] = transformedMirroringEndpointGroup
881+
}
882+
883+
return transformed, nil
884+
}
885+
886+
func expandNetworkSecuritySecurityProfileCustomMirroringProfileMirroringEndpointGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
887+
return v, nil
888+
}
889+
890+
func expandNetworkSecuritySecurityProfileCustomInterceptProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
891+
l := v.([]interface{})
892+
if len(l) == 0 || l[0] == nil {
893+
return nil, nil
894+
}
895+
raw := l[0]
896+
original := raw.(map[string]interface{})
897+
transformed := make(map[string]interface{})
898+
899+
transformedInterceptEndpointGroup, err := expandNetworkSecuritySecurityProfileCustomInterceptProfileInterceptEndpointGroup(original["intercept_endpoint_group"], d, config)
900+
if err != nil {
901+
return nil, err
902+
} else if val := reflect.ValueOf(transformedInterceptEndpointGroup); val.IsValid() && !tpgresource.IsEmptyValue(val) {
903+
transformed["interceptEndpointGroup"] = transformedInterceptEndpointGroup
904+
}
905+
906+
return transformed, nil
907+
}
908+
909+
func expandNetworkSecuritySecurityProfileCustomInterceptProfileInterceptEndpointGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
910+
return v, nil
911+
}
912+
758913
func expandNetworkSecuritySecurityProfileType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
759914
return v, nil
760915
}

google-beta/services/networksecurity/resource_network_security_security_profile_generated_meta.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ api_version: 'v1beta1'
55
api_resource_type_kind: 'SecurityProfile'
66
fields:
77
- field: 'create_time'
8+
- field: 'custom_intercept_profile.intercept_endpoint_group'
9+
- field: 'custom_mirroring_profile.mirroring_endpoint_group'
810
- field: 'description'
911
- field: 'effective_labels'
1012
provider_only: true

google-beta/services/networksecurity/resource_network_security_security_profile_generated_test.go

+124
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,130 @@ resource "google_network_security_security_profile" "default" {
126126
`, context)
127127
}
128128

129+
func TestAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileMirroringExample(t *testing.T) {
130+
t.Parallel()
131+
132+
context := map[string]interface{}{
133+
"org_id": envvar.GetTestOrgFromEnv(t),
134+
"random_suffix": acctest.RandString(t, 10),
135+
}
136+
137+
acctest.VcrTest(t, resource.TestCase{
138+
PreCheck: func() { acctest.AccTestPreCheck(t) },
139+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
140+
CheckDestroy: testAccCheckNetworkSecuritySecurityProfileDestroyProducer(t),
141+
Steps: []resource.TestStep{
142+
{
143+
Config: testAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileMirroringExample(context),
144+
},
145+
{
146+
ResourceName: "google_network_security_security_profile.default",
147+
ImportState: true,
148+
ImportStateVerify: true,
149+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "parent", "terraform_labels"},
150+
},
151+
},
152+
})
153+
}
154+
155+
func testAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileMirroringExample(context map[string]interface{}) string {
156+
return acctest.Nprintf(`
157+
resource "google_compute_network" "default" {
158+
provider = google-beta
159+
name = "tf-test-my-network%{random_suffix}"
160+
auto_create_subnetworks = false
161+
}
162+
163+
resource "google_network_security_mirroring_deployment_group" "default" {
164+
provider = google-beta
165+
mirroring_deployment_group_id = "tf-test-my-dg%{random_suffix}"
166+
location = "global"
167+
network = google_compute_network.default.id
168+
}
169+
170+
resource "google_network_security_mirroring_endpoint_group" "default" {
171+
provider = google-beta
172+
mirroring_endpoint_group_id = "tf-test-my-eg%{random_suffix}"
173+
location = "global"
174+
mirroring_deployment_group = google_network_security_mirroring_deployment_group.default.id
175+
}
176+
177+
resource "google_network_security_security_profile" "default" {
178+
provider = google-beta
179+
name = "tf-test-my-security-profile%{random_suffix}"
180+
parent = "organizations/%{org_id}"
181+
description = "my description"
182+
type = "CUSTOM_MIRRORING"
183+
184+
custom_mirroring_profile {
185+
mirroring_endpoint_group = google_network_security_mirroring_endpoint_group.default.id
186+
}
187+
}
188+
`, context)
189+
}
190+
191+
func TestAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileInterceptExample(t *testing.T) {
192+
t.Parallel()
193+
194+
context := map[string]interface{}{
195+
"org_id": envvar.GetTestOrgFromEnv(t),
196+
"random_suffix": acctest.RandString(t, 10),
197+
}
198+
199+
acctest.VcrTest(t, resource.TestCase{
200+
PreCheck: func() { acctest.AccTestPreCheck(t) },
201+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
202+
CheckDestroy: testAccCheckNetworkSecuritySecurityProfileDestroyProducer(t),
203+
Steps: []resource.TestStep{
204+
{
205+
Config: testAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileInterceptExample(context),
206+
},
207+
{
208+
ResourceName: "google_network_security_security_profile.default",
209+
ImportState: true,
210+
ImportStateVerify: true,
211+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "parent", "terraform_labels"},
212+
},
213+
},
214+
})
215+
}
216+
217+
func testAccNetworkSecuritySecurityProfile_networkSecuritySecurityProfileInterceptExample(context map[string]interface{}) string {
218+
return acctest.Nprintf(`
219+
resource "google_compute_network" "default" {
220+
provider = google-beta
221+
name = "tf-test-my-network%{random_suffix}"
222+
auto_create_subnetworks = false
223+
}
224+
225+
resource "google_network_security_intercept_deployment_group" "default" {
226+
provider = google-beta
227+
intercept_deployment_group_id = "tf-test-my-dg%{random_suffix}"
228+
location = "global"
229+
network = google_compute_network.default.id
230+
}
231+
232+
resource "google_network_security_intercept_endpoint_group" "default" {
233+
provider = google-beta
234+
intercept_endpoint_group_id = "tf-test-my-eg%{random_suffix}"
235+
location = "global"
236+
intercept_deployment_group = google_network_security_intercept_deployment_group.default.id
237+
}
238+
239+
resource "google_network_security_security_profile" "default" {
240+
provider = google-beta
241+
name = "tf-test-my-security-profile%{random_suffix}"
242+
parent = "organizations/%{org_id}"
243+
description = "my description"
244+
type = "CUSTOM_INTERCEPT"
245+
246+
custom_intercept_profile {
247+
intercept_endpoint_group = google_network_security_intercept_endpoint_group.default.id
248+
}
249+
}
250+
`, context)
251+
}
252+
129253
func testAccCheckNetworkSecuritySecurityProfileDestroyProducer(t *testing.T) func(s *terraform.State) error {
130254
return func(s *terraform.State) error {
131255
for name, rs := range s.RootModule().Resources {

0 commit comments

Comments
 (0)