Skip to content

Commit 20d4ce5

Browse files
authored
feat: add regions and require_corp_owned to access level module (#40)
* add regions and require_corp_owned to access level module * add test for regions in access levels * fix policy_id value in output * add regions to expect path in test * use a single region for expect include
1 parent 5bd3b8a commit 20d4ce5

File tree

12 files changed

+82
-1
lines changed

12 files changed

+82
-1
lines changed

.kitchen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ suites:
3838
controls:
3939
- big_query_vpc_positive_test
4040
- big_query_vpc_negative_test
41+
- access_level_regions_test
4142
provisioner:
4243
name: terraform
4344
- name: "simple_example_bridge"

examples/simple_example/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ You may use the following gcloud commands:
3131
| perimeter\_name | Perimeter name of the Access Policy.. | string | `"regular_perimeter_1"` | no |
3232
| policy\_name | The policy's name. | string | n/a | yes |
3333
| protected\_project\_ids | Project id and number of the project INSIDE the regular service perimeter. This map variable expects an "id" for the project id and "number" key for the project number. | object | n/a | yes |
34+
| regions | The request must originate from one of the provided countries/regions. Format: A valid ISO 3166-1 alpha-2 code. | list(string) | `<list>` | no |
3435

3536
## Outputs
3637

3738
| Name | Description |
3839
|------|-------------|
40+
| access\_level\_name | Access level name of the Access Policy. |
3941
| dataset\_id | Unique id for the BigQuery dataset being provisioned |
4042
| dataset\_name | Name of dataset being provisioned |
43+
| policy\_id | Resource name of the AccessPolicy. |
4144
| policy\_name | Name of the parent policy |
4245
| protected\_project\_id | Project id of the project INSIDE the regular service perimeter |
4346
| table\_id | Unique id for the BigQuery table being provisioned |

examples/simple_example/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module "access_level_members" {
3030
policy = module.access_context_manager_policy.policy_id
3131
name = var.access_level_name
3232
members = var.members
33+
regions = var.regions
3334
}
3435

3536
resource "null_resource" "wait_for_members" {

examples/simple_example/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17+
output "policy_id" {
18+
description = "Resource name of the AccessPolicy."
19+
value = module.access_context_manager_policy.policy_id
20+
}
21+
1722
output "policy_name" {
1823
description = "Name of the parent policy"
1924
value = var.policy_name
2025
}
2126

27+
output "access_level_name" {
28+
description = "Access level name of the Access Policy."
29+
value = var.access_level_name
30+
}
31+
2232
output "protected_project_id" {
2333
description = "Project id of the project INSIDE the regular service perimeter"
2434
value = var.protected_project_ids["id"]

examples/simple_example/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ variable "members" {
3434
type = list(string)
3535
}
3636

37+
variable "regions" {
38+
description = "The request must originate from one of the provided countries/regions. Format: A valid ISO 3166-1 alpha-2 code."
39+
type = list(string)
40+
default = []
41+
}
42+
3743
variable "access_level_name" {
3844
description = "Access level name of the Access Policy."
3945
type = string

modules/access_level/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module "access_level_members" {
3838
| negate | Whether to negate the Condition. If true, the Condition becomes a NAND over its non-empty fields, each field must be false for the Condition overall to be satisfied. | bool | `"false"` | no |
3939
| os\_type | The operating system type of the device. | string | `"OS_UNSPECIFIED"` | no |
4040
| policy | Name of the parent policy | string | n/a | yes |
41+
| regions | Condition - The request must originate from one of the provided countries/regions. Format: A valid ISO 3166-1 alpha-2 code. | list(string) | `<list>` | no |
42+
| require\_corp\_owned | Condition - Whether the device needs to be corp owned. | bool | `"false"` | no |
4143
| require\_screen\_lock | Condition - Whether or not screenlock is required for the DevicePolicy to be true. | bool | `"false"` | no |
4244
| required\_access\_levels | Condition - A list of other access levels defined in the same Policy, referenced by resource name. Referencing an AccessLevel which does not exist is an error. All access levels listed must be granted for the Condition to be true. | list(string) | `<list>` | no |
4345

modules/access_level/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ resource "google_access_context_manager_access_level" "access_level" {
3131
required_access_levels = var.required_access_levels
3232
members = var.members
3333
negate = var.negate
34+
regions = var.regions
3435

3536
dynamic "device_policy" {
36-
for_each = var.require_screen_lock || length(var.allowed_encryption_statuses) > 0 || length(var.allowed_device_management_levels) > 0 || var.minimum_version != "" || var.os_type != "OS_UNSPECIFIED" ? [{}] : []
37+
for_each = var.require_corp_owned || var.require_screen_lock || length(var.allowed_encryption_statuses) > 0 || length(var.allowed_device_management_levels) > 0 || var.minimum_version != "" || var.os_type != "OS_UNSPECIFIED" ? [{}] : []
3738

3839
content {
3940
require_screen_lock = var.require_screen_lock
4041
allowed_encryption_statuses = var.allowed_encryption_statuses
4142
allowed_device_management_levels = var.allowed_device_management_levels
43+
require_corp_owned = var.require_corp_owned
4244

4345
os_constraints {
4446
minimum_version = var.minimum_version

modules/access_level/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ variable "members" {
5454
default = []
5555
}
5656

57+
variable "regions" {
58+
description = "Condition - The request must originate from one of the provided countries/regions. Format: A valid ISO 3166-1 alpha-2 code."
59+
type = list(string)
60+
default = []
61+
}
62+
5763
variable "negate" {
5864
description = "Whether to negate the Condition. If true, the Condition becomes a NAND over its non-empty fields, each field must be false for the Condition overall to be satisfied."
5965
type = bool
@@ -66,6 +72,12 @@ variable "require_screen_lock" {
6672
default = false
6773
}
6874

75+
variable "require_corp_owned" {
76+
description = "Condition - Whether the device needs to be corp owned."
77+
type = bool
78+
default = false
79+
}
80+
6981
variable "allowed_encryption_statuses" {
7082
description = "Condition - A list of allowed encryptions statuses. An empty list allows all statuses."
7183
type = list(string)

test/fixtures/shared/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ output "parent_id" {
1818
value = var.parent_id
1919
}
2020

21+
output "policy_id" {
22+
value = module.example.policy_id
23+
}
24+
2125
output "policy_name" {
2226
value = module.example.policy_name
2327
}
2428

29+
output "access_level_name" {
30+
value = module.example.access_level_name
31+
}
32+
2533
output "protected_project_id" {
2634
value = var.protected_project_ids["id"]
2735
}

test/fixtures/simple_example/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module "example" {
2424
policy_name = "int_test_vpc_sc_policy_${random_id.random_suffix.hex}"
2525
protected_project_ids = var.protected_project_ids
2626
members = var.members
27+
regions = ["US", "CA"]
2728
access_level_name = "vpc_sc_members_test_${random_id.random_suffix.hex}"
2829
perimeter_name = "perimeter_vpc_sc_test_${random_id.random_suffix.hex}"
2930
dataset_id = "dataset_vpc_sc_test_${random_id.random_suffix.hex}"

0 commit comments

Comments
 (0)