Skip to content

Commit c6df326

Browse files
authored
fix(TPG >= 4.68)!: added missing features for egress policies (#131)
1 parent d68b4d6 commit c6df326

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
This module handles opinionated VPC Service Controls and Access Context Manager configuration and deployments.
44

55
## Compatibility
6-
This module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+. If you find incompatibilities using Terraform >=0.13, please open an issue.
7-
If you haven't
8-
[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform
9-
0.12.x-compatible version of this module, the last released version
10-
intended for Terraform 0.12.x is [v2.1.0](https://registry.terraform.io/modules/terraform-google-modules/-vpc-service-controls/google/v2.1.0).
6+
This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue.
7+
8+
## Version
9+
10+
Current version is 5.X. Upgrade guides:
11+
12+
- [3.X -> 4.0.](/docs/upgrading_to_v4.0.md)
13+
- [4.X -> 6.0.](/docs/upgrading_to_v6.0.md)
1114

1215
## Usage
1316
The root module only handles the configuration of the [access_context_manager_policy resource](https://www.terraform.io/docs/providers/google/r/access_context_manager_access_policy.html). For examples on how to use the root module with along with other submodules to configure all of VPC Service Controls and Access Context Manager resources, see the [examples](./examples/) folder and the [modules](./modules/) folder

docs/upgrading_to_v6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Upgrading to v6.x
2+
3+
The v6.x release contains backwards-incompatible changes.
4+
5+
This update requires upgrading the minimum provider version to `4.68`.

modules/regular_service_perimeter/main.tf

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
3535

3636
dynamic "ingress_policies" {
3737
for_each = var.ingress_policies
38+
iterator = ingress_policies
3839
content {
3940
ingress_from {
4041
dynamic "sources" {
@@ -72,10 +73,18 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
7273
}
7374
dynamic "egress_policies" {
7475
for_each = var.egress_policies
76+
iterator = egress_policies
7577
content {
7678
egress_from {
7779
identity_type = lookup(egress_policies.value["from"], "identity_type", null)
7880
identities = lookup(egress_policies.value["from"], "identities", null)
81+
dynamic "sources" {
82+
for_each = { for k, v in lookup(egress_policies.value["from"]["sources"], "access_levels", []) : v => "access_level" }
83+
content {
84+
access_level = sources.value == "access_level" ? sources.key != "*" ? "accessPolicies/${var.policy}/accessLevels/${sources.key}" : "*" : null
85+
}
86+
}
87+
source_restriction = egress_policies.value["from"]["sources"] != null ? "SOURCE_RESTRICTION_ENABLED" : null
7988
}
8089
egress_to {
8190
resources = lookup(egress_policies.value["to"], "resources", ["*"])
@@ -120,25 +129,26 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
120129

121130
dynamic "ingress_policies" {
122131
for_each = var.ingress_policies_dry_run
132+
iterator = ingress_policies_dry_run
123133
content {
124134
ingress_from {
125135
dynamic "sources" {
126136
for_each = merge(
127-
{ for k, v in lookup(ingress_policies.value["from"]["sources"], "resources", []) : v => "resource" },
128-
{ for k, v in lookup(ingress_policies.value["from"]["sources"], "access_levels", []) : v => "access_level" })
137+
{ for k, v in lookup(ingress_policies_dry_run.value["from"]["sources"], "resources", []) : v => "resource" },
138+
{ for k, v in lookup(ingress_policies_dry_run.value["from"]["sources"], "access_levels", []) : v => "access_level" })
129139
content {
130140
resource = sources.value == "resource" ? sources.key : null
131141
access_level = sources.value == "access_level" ? sources.key != "*" ? "accessPolicies/${var.policy}/accessLevels/${sources.key}" : "*" : null
132142
}
133143
}
134-
identity_type = lookup(ingress_policies.value["from"], "identity_type", null)
135-
identities = lookup(ingress_policies.value["from"], "identities", null)
144+
identity_type = lookup(ingress_policies_dry_run.value["from"], "identity_type", null)
145+
identities = lookup(ingress_policies_dry_run.value["from"], "identities", null)
136146
}
137147

138148
ingress_to {
139-
resources = lookup(ingress_policies.value["to"], "resources", ["*"])
149+
resources = lookup(ingress_policies_dry_run.value["to"], "resources", ["*"])
140150
dynamic "operations" {
141-
for_each = ingress_policies.value["to"]["operations"]
151+
for_each = ingress_policies_dry_run.value["to"]["operations"]
142152
content {
143153
service_name = operations.key
144154
dynamic "method_selectors" {
@@ -157,15 +167,23 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri
157167
}
158168
dynamic "egress_policies" {
159169
for_each = var.egress_policies_dry_run
170+
iterator = egress_policies_dry_run
160171
content {
161172
egress_from {
162-
identity_type = lookup(egress_policies.value["from"], "identity_type", null)
163-
identities = lookup(egress_policies.value["from"], "identities", null)
173+
identity_type = lookup(egress_policies_dry_run.value["from"], "identity_type", null)
174+
identities = lookup(egress_policies_dry_run.value["from"], "identities", null)
175+
dynamic "sources" {
176+
for_each = { for k, v in lookup(egress_policies_dry_run.value["from"]["sources"], "access_levels", []) : v => "access_level" }
177+
content {
178+
access_level = sources.value == "access_level" ? sources.key != "*" ? "accessPolicies/${var.policy}/accessLevels/${sources.key}" : "*" : null
179+
}
180+
}
181+
source_restriction = egress_policies_dry_run.value["from"]["sources"] != null ? "SOURCE_RESTRICTION_ENABLED" : null
164182
}
165183
egress_to {
166-
resources = lookup(egress_policies.value["to"], "resources", ["*"])
184+
resources = lookup(egress_policies_dry_run.value["to"], "resources", ["*"])
167185
dynamic "operations" {
168-
for_each = lookup(egress_policies.value["to"], "operations", [])
186+
for_each = lookup(egress_policies_dry_run.value["to"], "operations", [])
169187
content {
170188
service_name = operations.key
171189
dynamic "method_selectors" {

modules/regular_service_perimeter/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616

1717
terraform {
18-
required_version = ">= 0.13"
18+
required_version = ">= 1.3.0"
1919
required_providers {
2020

2121
google = {
2222
source = "hashicorp/google"
23-
version = ">= 3.50, < 6"
23+
version = ">= 4.68, < 6"
2424
}
2525
}
2626

0 commit comments

Comments
 (0)