Skip to content

Commit fbc4b0c

Browse files
Create region security policies rules (#8477) (#15523)
* creating first version of region security policy and adding ddos protection config * adding rules field in region security policy * creating resource network_edge_security_service and their scenarios of test * adding patch operation and fixing id, import_format and self_link * added fields in the region_security_policy, and fixed the scenario tests for network_edge_security_service * removed duplicated field for region_security_policy * adding ddos_protection_config field in region_security_policy * cleanups * adding self_link field back and removing uncessary fields * adding docs for ddosProtection * making new resources only availabe in beta downstream * fixing eof * adding region security policy rule and basic scenario * code experiments cleanups * adding preconfiguredWafConfig object and some inner fields in region security policy rule * adding mapping for network_match object in region security policy rule * adding rateLimitOptions mapping * adding ruleNumber field to region security policy * adding basic update for region security policy rule * adding network_match and preconfigured_waf scenarios for region sec policy rules * wip - adding user_defined_fields in region security policy * fixing yaml linter issues * fixing review comments * removing validate_only field * fixing comments in region_security_policy_rule test * fixing userDefinedFields and adding tests for regionSecPolicyRule * adding user_defined_fields update test for regionSecPolicy * removing rule_number from regionSecPolicyRule * removing preconfiguredWaf from regionSecPolicyRule because it is not finished yet * removing rateLimitOptions from RegionSecPolicyRule because it is not finished yet * small cleanups * fixing yamllint issues on the worked resources * prevent that netwrokt_match test fails due paralellism * adding new test for multiple rules * fixing code review comments * removing harcoded project from tests * moving network_edge_security_service basic test to another region * fixing code review issues * fixing import cycle issue in downstream repo * updating with upstream and change regions --------- Signed-off-by: Modular Magician <[email protected]> Co-authored-by: diogoEsteves <[email protected]>
1 parent 67c2ca7 commit fbc4b0c

5 files changed

+419
-1
lines changed

.changelog/8477.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:new-resource
2+
`google_compute_region_security_policy_rule`
3+
```
4+
```release-note:enhancement
5+
compute: added support for `user_defined_fields` to `google_compute_region_security_policy`
6+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package compute_test

website/docs/r/compute_network_edge_security_service.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resource "google_compute_network_edge_security_service" "default" {
3838
provider = google-beta
3939
4040
name = "my-edge-security-service"
41-
region = "asia-southeast1"
41+
region = "us-east1"
4242
description = "My basic resource"
4343
}
4444
```

website/docs/r/compute_region_security_policy.html.markdown

+67
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ resource "google_compute_region_security_policy" "region-sec-policy-ddos-protect
6868
}
6969
}
7070
```
71+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
72+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_security_policy_with_user_defined_fields&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
73+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
74+
</a>
75+
</div>
76+
## Example Usage - Region Security Policy With User Defined Fields
77+
78+
79+
```hcl
80+
resource "google_compute_region_security_policy" "region-sec-policy-user-defined-fields" {
81+
provider = google-beta
82+
83+
name = "my-sec-policy-user-defined-fields"
84+
description = "with user defined fields"
85+
type = "CLOUD_ARMOR_NETWORK"
86+
user_defined_fields {
87+
name = "SIG1_AT_0"
88+
base = "UDP"
89+
offset = 8
90+
size = 2
91+
mask = "0x8F00"
92+
}
93+
user_defined_fields {
94+
name = "SIG2_AT_8"
95+
base = "UDP"
96+
offset = 16
97+
size = 4
98+
mask = "0xFFFFFFFF"
99+
}
100+
}
101+
```
71102

72103
## Argument Reference
73104

@@ -101,6 +132,13 @@ The following arguments are supported:
101132
Configuration for Google Cloud Armor DDOS Proctection Config.
102133
Structure is [documented below](#nested_ddos_protection_config).
103134

135+
* `user_defined_fields` -
136+
(Optional)
137+
Definitions of user-defined fields for CLOUD_ARMOR_NETWORK policies.
138+
A user-defined field consists of up to 4 bytes extracted from a fixed offset in the packet, relative to the IPv4, IPv6, TCP, or UDP header, with an optional mask to select certain bits.
139+
Rules may then specify matching values for these fields.
140+
Structure is [documented below](#nested_user_defined_fields).
141+
104142
* `region` -
105143
(Optional)
106144
The Region in which the created Region Security Policy should reside.
@@ -120,6 +158,35 @@ The following arguments are supported:
120158
- ADVANCED_PREVIEW: flag to enable the security policy in preview mode.
121159
Possible values are: `ADVANCED`, `ADVANCED_PREVIEW`, `STANDARD`.
122160

161+
<a name="nested_user_defined_fields"></a>The `user_defined_fields` block supports:
162+
163+
* `name` -
164+
(Optional)
165+
The name of this field. Must be unique within the policy.
166+
167+
* `base` -
168+
(Required)
169+
The base relative to which 'offset' is measured. Possible values are:
170+
- IPV4: Points to the beginning of the IPv4 header.
171+
- IPV6: Points to the beginning of the IPv6 header.
172+
- TCP: Points to the beginning of the TCP header, skipping over any IPv4 options or IPv6 extension headers. Not present for non-first fragments.
173+
- UDP: Points to the beginning of the UDP header, skipping over any IPv4 options or IPv6 extension headers. Not present for non-first fragments.
174+
Possible values are: `IPV4`, `IPV6`, `TCP`, `UDP`.
175+
176+
* `offset` -
177+
(Optional)
178+
Offset of the first byte of the field (in network byte order) relative to 'base'.
179+
180+
* `size` -
181+
(Optional)
182+
Size of the field in bytes. Valid values: 1-4.
183+
184+
* `mask` -
185+
(Optional)
186+
If specified, apply this mask (bitwise AND) to the field to ignore bits before matching.
187+
Encoded as a hexadecimal number (starting with "0x").
188+
The last byte of the field (in network byte order) corresponds to the least significant byte of the mask.
189+
123190
## Attributes Reference
124191

125192
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)