Skip to content

Commit dfd0252

Browse files
masterleroslomegft
andauthored
fix: dry-run egress ingress operations (#83)
* Fix dry-run egress ingress operations * fixed policies operations type and documented Co-authored-by: Leonardo Morales <leonardo.morales@gft.com>
1 parent ed9deda commit dfd0252

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

modules/regular_service_perimeter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ module "regular_service_perimeter_1" {
9898
| access\_levels | A list of AccessLevel resource names that allow resources within the ServicePerimeter to be accessed from the internet. AccessLevels listed must be in the same policy as this ServicePerimeter. Referencing a nonexistent AccessLevel is a syntax error. If no AccessLevel names are listed, resources within the perimeter can only be accessed via GCP calls with request origins within the perimeter. Example: 'accessPolicies/MY\_POLICY/accessLevels/MY\_LEVEL'. For Service Perimeter Bridge, must be empty. | `list(string)` | `[]` | no |
9999
| access\_levels\_dry\_run | (Dry-run) A list of AccessLevel resource names that allow resources within the ServicePerimeter to be accessed from the internet. AccessLevels listed must be in the same policy as this ServicePerimeter. Referencing a nonexistent AccessLevel is a syntax error. If no AccessLevel names are listed, resources within the perimeter can only be accessed via GCP calls with request origins within the perimeter. Example: 'accessPolicies/MY\_POLICY/accessLevels/MY\_LEVEL'. For Service Perimeter Bridge, must be empty. If set, a dry-run policy will be set. | `list(string)` | `[]` | no |
100100
| description | Description of the regular perimeter | `string` | n/a | yes |
101-
| egress\_policies | A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress\_from and egress\_to. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
102-
| egress\_policies\_dry\_run | A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress\_from and egress\_to. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
103-
| ingress\_policies | A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress\_from and ingress\_to. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
104-
| ingress\_policies\_dry\_run | A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress\_from and ingress\_to. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
101+
| egress\_policies | A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress\_from and egress\_to.<br><br>Example: `[{ from={ identities=[], identity_type="ID_TYPE" }, to={ resources=[], operations={ "SRV_NAME"={ OP_TYPE=[] }}}}]`<br><br>Valid Values:<br>`ID_TYPE` = `null` or `IDENTITY_TYPE_UNSPECIFIED` (only allow indentities from list); `ANY_IDENTITY`; `ANY_USER_ACCOUNT`; `ANY_SERVICE_ACCOUNT`<br>`SRV_NAME` = "`*`" (allow all services) or [Specific Services](https://cloud.google.com/vpc-service-controls/docs/supported-products#supported_products)<br>`OP_TYPE` = [methods](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) or [permissions](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
102+
| egress\_policies\_dry\_run | A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress\_from and egress\_to. Use same formatting as `egress_policies`. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
103+
| ingress\_policies | A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress\_from and ingress\_to.<br><br>Example: `[{ from={ sources={ resources=[], access_levels=[] }, identities=[], identity_type="ID_TYPE" }, to={ resources=[], operations={ "SRV_NAME"={ OP_TYPE=[] }}}}]`<br><br>Valid Values:<br>`ID_TYPE` = `null` or `IDENTITY_TYPE_UNSPECIFIED` (only allow indentities from list); `ANY_IDENTITY`; `ANY_USER_ACCOUNT`; `ANY_SERVICE_ACCOUNT`<br>`SRV_NAME` = "`*`" (allow all services) or [Specific Services](https://cloud.google.com/vpc-service-controls/docs/supported-products#supported_products)<br>`OP_TYPE` = [methods](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) or [permissions](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
104+
| ingress\_policies\_dry\_run | A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress\_from and ingress\_to. Use same formatting as `ingress_policies`. | <pre>list(object({<br> from = any<br> to = any<br> }))</pre> | `[]` | no |
105105
| perimeter\_name | Name of the perimeter. Should be one unified string. Must only be letters, numbers and underscores | `any` | n/a | yes |
106106
| policy | Name of the parent policy | `string` | n/a | yes |
107107
| resource\_keys | A list of keys to use for the Terraform state. The order should correspond to var.resources and the keys must not be dynamically computed. If `null`, var.resources will be used as keys. | `list(string)` | `null` | no |

modules/regular_service_perimeter/main.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
5858
service_name = operations.key
5959
dynamic "method_selectors" {
6060
for_each = operations.key != "*" ? merge(
61-
{ for k, v in lookup(operations.value, "methods", {}) : v => "method" },
62-
{ for k, v in lookup(operations.value, "permissions", {}) : v => "permission" }) : {}
61+
{ for v in lookup(operations.value, "methods", []) : v => "method" },
62+
{ for v in lookup(operations.value, "permissions", []) : v => "permission" }) : {}
6363
content {
6464
method = method_selectors.value == "method" ? method_selectors.key : null
65-
permission = method_selectors.value == "permission" ? method_selectors.key : ""
65+
permission = method_selectors.value == "permission" ? method_selectors.key : null
6666
}
6767
}
6868
}
@@ -85,11 +85,11 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
8585
service_name = operations.key
8686
dynamic "method_selectors" {
8787
for_each = operations.key != "*" ? merge(
88-
{ for k, v in lookup(operations.value, "methods", {}) : v => "method" },
89-
{ for k, v in lookup(operations.value, "permissions", {}) : v => "permission" }) : {}
88+
{ for v in lookup(operations.value, "methods", []) : v => "method" },
89+
{ for v in lookup(operations.value, "permissions", []) : v => "permission" }) : {}
9090
content {
91-
method = method_selectors.value == "method" ? method_selectors.key : ""
92-
permission = method_selectors.value == "permission" ? method_selectors.key : ""
91+
method = method_selectors.value == "method" ? method_selectors.key : null
92+
permission = method_selectors.value == "permission" ? method_selectors.key : null
9393
}
9494
}
9595
}
@@ -134,12 +134,12 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
134134
content {
135135
service_name = operations.key
136136
dynamic "method_selectors" {
137-
for_each = merge(
138-
{ for k, v in lookup(operations.value, "methods", {}) : v => "method" },
139-
{ for k, v in lookup(operations.value, "permissions", {}) : v => "permission" })
137+
for_each = operations.key != "*" ? merge(
138+
{ for v in lookup(operations.value, "methods", []) : v => "method" },
139+
{ for v in lookup(operations.value, "permissions", []) : v => "permission" }) : {}
140140
content {
141-
method = method_selectors.value == "method" ? method_selectors.key : ""
142-
permission = method_selectors.value == "permission" ? method_selectors.key : ""
141+
method = method_selectors.value == "method" ? method_selectors.key : null
142+
permission = method_selectors.value == "permission" ? method_selectors.key : null
143143
}
144144
}
145145
}
@@ -161,12 +161,12 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
161161
content {
162162
service_name = operations.key
163163
dynamic "method_selectors" {
164-
for_each = merge(
165-
{ for k, v in lookup(operations.value, "methods", {}) : v => "method" },
166-
{ for k, v in lookup(operations.value, "permissions", {}) : v => "permission" })
164+
for_each = operations.key != "*" ? merge(
165+
{ for v in lookup(operations.value, "methods", []) : v => "method" },
166+
{ for v in lookup(operations.value, "permissions", []) : v => "permission" }) : {}
167167
content {
168-
method = method_selectors.value == "method" ? method_selectors.key : ""
169-
permission = method_selectors.value == "permission" ? method_selectors.key : ""
168+
method = method_selectors.value == "method" ? method_selectors.key : null
169+
permission = method_selectors.value == "permission" ? method_selectors.key : null
170170
}
171171
}
172172
}

modules/regular_service_perimeter/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ variable "shared_resources" {
7979

8080
## Have to solve it like this don't want use optional flag because is still experimental
8181
variable "egress_policies" {
82-
description = "A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress_from and egress_to."
82+
description = "A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress_from and egress_to.\n\nExample: `[{ from={ identities=[], identity_type=\"ID_TYPE\" }, to={ resources=[], operations={ \"SRV_NAME\"={ OP_TYPE=[] }}}}]`\n\nValid Values:\n`ID_TYPE` = `null` or `IDENTITY_TYPE_UNSPECIFIED` (only allow indentities from list); `ANY_IDENTITY`; `ANY_USER_ACCOUNT`; `ANY_SERVICE_ACCOUNT`\n`SRV_NAME` = \"`*`\" (allow all services) or [Specific Services](https://cloud.google.com/vpc-service-controls/docs/supported-products#supported_products)\n`OP_TYPE` = [methods](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) or [permissions](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions)"
8383
type = list(object({
8484
from = any
8585
to = any
@@ -89,7 +89,7 @@ variable "egress_policies" {
8989

9090
## Have to solve it like this don't want use optional flag because is still experimental
9191
variable "ingress_policies" {
92-
description = "A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress_from and ingress_to."
92+
description = "A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress_from and ingress_to.\n\nExample: `[{ from={ sources={ resources=[], access_levels=[] }, identities=[], identity_type=\"ID_TYPE\" }, to={ resources=[], operations={ \"SRV_NAME\"={ OP_TYPE=[] }}}}]`\n\nValid Values:\n`ID_TYPE` = `null` or `IDENTITY_TYPE_UNSPECIFIED` (only allow indentities from list); `ANY_IDENTITY`; `ANY_USER_ACCOUNT`; `ANY_SERVICE_ACCOUNT`\n`SRV_NAME` = \"`*`\" (allow all services) or [Specific Services](https://cloud.google.com/vpc-service-controls/docs/supported-products#supported_products)\n`OP_TYPE` = [methods](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions) or [permissions](https://cloud.google.com/vpc-service-controls/docs/supported-method-restrictions)"
9393
type = list(object({
9494
from = any
9595
to = any
@@ -100,7 +100,7 @@ variable "ingress_policies" {
100100

101101
## Have to solve it like this don't want use optional flag because is still experimental
102102
variable "egress_policies_dry_run" {
103-
description = "A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress_from and egress_to."
103+
description = "A list of all [egress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#egress-rules-reference), each list object has a `from` and `to` value that describes egress_from and egress_to. Use same formatting as `egress_policies`."
104104
type = list(object({
105105
from = any
106106
to = any
@@ -110,7 +110,7 @@ variable "egress_policies_dry_run" {
110110

111111
## Have to solve it like this don't want use optional flag because is still experimental
112112
variable "ingress_policies_dry_run" {
113-
description = "A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress_from and ingress_to."
113+
description = "A list of all [ingress policies](https://cloud.google.com/vpc-service-controls/docs/ingress-egress-rules#ingress-rules-reference), each list object has a `from` and `to` value that describes ingress_from and ingress_to. Use same formatting as `ingress_policies`."
114114
type = list(object({
115115
from = any
116116
to = any

0 commit comments

Comments
 (0)