2021-12-31 04:29:22 -08:00
|
|
|
/**
|
2022-01-01 06:52:31 -08:00
|
|
|
* Copyright 2022 Google LLC
|
2021-12-31 04:29:22 -08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-11-10 10:34:45 -08:00
|
|
|
# tfdoc:file:description Regular service perimeter resources.
|
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
# this code implements "additive" service perimeters, if "authoritative"
|
|
|
|
# service perimeters are needed, switch to the
|
|
|
|
# google_access_context_manager_service_perimeters resource
|
|
|
|
|
|
|
|
resource "google_access_context_manager_service_perimeter" "regular" {
|
|
|
|
for_each = var.service_perimeters_regular
|
|
|
|
parent = "accessPolicies/${local.access_policy}"
|
|
|
|
name = "accessPolicies/${local.access_policy}/servicePerimeters/${each.key}"
|
|
|
|
title = each.key
|
|
|
|
perimeter_type = "PERIMETER_TYPE_REGULAR"
|
|
|
|
use_explicit_dry_run_spec = each.value.use_explicit_dry_run_spec
|
|
|
|
dynamic "spec" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = each.value.spec == null ? [] : [each.value.spec]
|
|
|
|
iterator = spec
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-01-04 04:02:38 -08:00
|
|
|
access_levels = (
|
2022-12-05 00:00:00 -08:00
|
|
|
spec.value.access_levels == null ? null : [
|
|
|
|
for k in spec.value.access_levels :
|
2022-01-04 04:02:38 -08:00
|
|
|
try(google_access_context_manager_access_level.basic[k].id, k)
|
|
|
|
]
|
|
|
|
)
|
2022-12-05 00:00:00 -08:00
|
|
|
resources = spec.value.resources
|
|
|
|
restricted_services = spec.value.restricted_services
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "egress_policies" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = spec.value.egress_policies == null ? {} : {
|
|
|
|
for k in spec.value.egress_policies :
|
2022-11-10 10:34:45 -08:00
|
|
|
k => lookup(var.egress_policies, k, null)
|
|
|
|
if contains(keys(var.egress_policies), k)
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
iterator = policy
|
|
|
|
content {
|
|
|
|
dynamic "egress_from" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.from == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
identity_type = policy.value.from.identity_type
|
|
|
|
identities = policy.value.from.identities
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "egress_to" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.to == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
resources = policy.value.to.resources
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "operations" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.to.operations)
|
|
|
|
iterator = o
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
service_name = o.value.service_name
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "method_selectors" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(coalesce(o.value.method_selectors, []))
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
|
|
|
method = method_selectors.key
|
|
|
|
}
|
|
|
|
}
|
2023-06-24 23:45:37 -07:00
|
|
|
dynamic "method_selectors" {
|
|
|
|
for_each = toset(coalesce(o.value.permission_selectors, []))
|
|
|
|
content {
|
|
|
|
permission = method_selectors.key
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "ingress_policies" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = spec.value.ingress_policies == null ? {} : {
|
|
|
|
for k in spec.value.ingress_policies :
|
2022-11-10 10:34:45 -08:00
|
|
|
k => lookup(var.ingress_policies, k, null)
|
|
|
|
if contains(keys(var.ingress_policies), k)
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
iterator = policy
|
|
|
|
content {
|
|
|
|
dynamic "ingress_from" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.from == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
identity_type = policy.value.from.identity_type
|
|
|
|
identities = policy.value.from.identities
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "sources" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.from.access_levels)
|
|
|
|
iterator = s
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
access_level = try(
|
|
|
|
google_access_context_manager_access_level.basic[s.value].id, s.value
|
|
|
|
)
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "sources" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.from.resources)
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
|
|
|
resource = sources.key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "ingress_to" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.to == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
resources = policy.value.to.resources
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "operations" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.to.operations)
|
|
|
|
iterator = o
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
service_name = o.value.service_name
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "method_selectors" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(coalesce(o.value.method_selectors, []))
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
method = method_selectors.value
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2023-06-24 23:45:37 -07:00
|
|
|
dynamic "method_selectors" {
|
|
|
|
for_each = toset(coalesce(o.value.permission_selectors, []))
|
|
|
|
content {
|
|
|
|
permission = method_selectors.value
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "vpc_accessible_services" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = spec.value.vpc_accessible_services == null ? {} : { 1 = 1 }
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-12-05 00:00:00 -08:00
|
|
|
allowed_services = spec.value.vpc_accessible_services.allowed_services
|
|
|
|
enable_restriction = spec.value.vpc_accessible_services.enable_restriction
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "status" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = each.value.status == null ? [] : [each.value.status]
|
|
|
|
iterator = status
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-01-04 04:02:38 -08:00
|
|
|
access_levels = (
|
2022-12-05 00:00:00 -08:00
|
|
|
status.value.access_levels == null ? null : [
|
|
|
|
for k in status.value.access_levels :
|
2022-01-04 04:02:38 -08:00
|
|
|
try(google_access_context_manager_access_level.basic[k].id, k)
|
|
|
|
]
|
|
|
|
)
|
2022-12-05 00:00:00 -08:00
|
|
|
resources = status.value.resources
|
|
|
|
restricted_services = status.value.restricted_services
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "egress_policies" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = status.value.egress_policies == null ? {} : {
|
|
|
|
for k in status.value.egress_policies :
|
2022-11-10 10:34:45 -08:00
|
|
|
k => lookup(var.egress_policies, k, null)
|
|
|
|
if contains(keys(var.egress_policies), k)
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
iterator = policy
|
|
|
|
content {
|
|
|
|
dynamic "egress_from" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.from == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
identity_type = policy.value.from.identity_type
|
|
|
|
identities = policy.value.from.identities
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "egress_to" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.to == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
resources = policy.value.to.resources
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "operations" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.to.operations)
|
|
|
|
iterator = o
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
service_name = o.value.service_name
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "method_selectors" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(coalesce(o.value.method_selectors, []))
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
|
|
|
method = method_selectors.key
|
|
|
|
}
|
|
|
|
}
|
2023-06-24 23:45:37 -07:00
|
|
|
dynamic "method_selectors" {
|
|
|
|
for_each = toset(coalesce(o.value.permission_selectors, []))
|
|
|
|
content {
|
|
|
|
permission = method_selectors.key
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "ingress_policies" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = status.value.ingress_policies == null ? {} : {
|
|
|
|
for k in status.value.ingress_policies :
|
2022-11-10 10:34:45 -08:00
|
|
|
k => lookup(var.ingress_policies, k, null)
|
|
|
|
if contains(keys(var.ingress_policies), k)
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
iterator = policy
|
|
|
|
content {
|
|
|
|
dynamic "ingress_from" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.from == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
identity_type = policy.value.from.identity_type
|
|
|
|
identities = policy.value.from.identities
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "sources" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.from.access_levels)
|
|
|
|
iterator = s
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
access_level = try(
|
2022-12-05 00:00:00 -08:00
|
|
|
google_access_context_manager_access_level.basic[s.value].id,
|
|
|
|
s.value
|
2022-11-10 10:34:45 -08:00
|
|
|
)
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "sources" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.from.resources)
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
|
|
|
resource = sources.key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dynamic "ingress_to" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = policy.value.to == null ? [] : [""]
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
resources = policy.value.to.resources
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "operations" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(policy.value.to.operations)
|
|
|
|
iterator = o
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
service_name = o.value.service_name
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "method_selectors" {
|
2022-11-10 10:34:45 -08:00
|
|
|
for_each = toset(coalesce(o.value.method_selectors, []))
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-11-10 10:34:45 -08:00
|
|
|
method = method_selectors.value
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2023-06-24 23:45:37 -07:00
|
|
|
dynamic "method_selectors" {
|
|
|
|
for_each = toset(coalesce(o.value.permission_selectors, []))
|
|
|
|
content {
|
|
|
|
permission = method_selectors.value
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
dynamic "vpc_accessible_services" {
|
2022-12-05 00:00:00 -08:00
|
|
|
for_each = status.value.vpc_accessible_services == null ? {} : { 1 = 1 }
|
2021-12-31 04:29:22 -08:00
|
|
|
content {
|
2022-12-05 00:00:00 -08:00
|
|
|
allowed_services = status.value.vpc_accessible_services.allowed_services
|
|
|
|
enable_restriction = status.value.vpc_accessible_services.enable_restriction
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2022-11-10 10:34:45 -08:00
|
|
|
|
2021-12-31 04:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2022-01-03 06:27:00 -08:00
|
|
|
# lifecycle {
|
|
|
|
# ignore_changes = [spec[0].resources, status[0].resources]
|
|
|
|
# }
|
2021-12-31 04:29:22 -08:00
|
|
|
depends_on = [
|
|
|
|
google_access_context_manager_access_policy.default,
|
|
|
|
google_access_context_manager_access_level.basic
|
|
|
|
]
|
|
|
|
}
|