2022-04-11 23:17:27 -07:00
|
|
|
/**
|
2024-02-14 15:10:24 -08:00
|
|
|
* Copyright 2024 Google LLC
|
2022-04-11 23:17:27 -07: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# tfdoc:file:description Workload Identity Federation provider definitions.
|
|
|
|
|
|
|
|
locals {
|
2024-02-14 15:10:24 -08:00
|
|
|
workforce_identity_providers = {
|
|
|
|
for k, v in var.workforce_identity_providers : k => merge(
|
2022-06-22 23:06:25 -07:00
|
|
|
v,
|
2024-02-14 15:10:24 -08:00
|
|
|
lookup(local.workforce_identity_providers_defs, v.issuer, {})
|
2022-04-11 23:17:27 -07:00
|
|
|
)
|
|
|
|
}
|
2024-02-14 15:10:24 -08:00
|
|
|
workload_identity_providers = {
|
|
|
|
for k, v in var.workload_identity_providers : k => merge(
|
|
|
|
v,
|
|
|
|
lookup(local.workload_identity_providers_defs, v.issuer, {})
|
|
|
|
)
|
|
|
|
}
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
|
2024-02-14 15:10:24 -08:00
|
|
|
resource "google_iam_workforce_pool" "default" {
|
|
|
|
count = length(local.workforce_identity_providers) > 0 ? 1 : 0
|
|
|
|
parent = "organizations/${var.organization.id}"
|
|
|
|
location = "global"
|
|
|
|
workforce_pool_id = "${var.prefix}-bootstrap"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_iam_workforce_pool_provider" "default" {
|
|
|
|
for_each = local.workforce_identity_providers
|
|
|
|
attribute_condition = each.value.attribute_condition
|
|
|
|
attribute_mapping = each.value.attribute_mapping
|
|
|
|
description = each.value.description
|
|
|
|
disabled = each.value.disabled
|
|
|
|
display_name = each.value.display_name
|
2024-04-17 01:23:48 -07:00
|
|
|
location = google_iam_workforce_pool.default[0].location
|
2024-02-14 15:10:24 -08:00
|
|
|
provider_id = "${var.prefix}-bootstrap-${each.key}"
|
2024-04-17 01:23:48 -07:00
|
|
|
workforce_pool_id = google_iam_workforce_pool.default[0].workforce_pool_id
|
2024-02-14 15:10:24 -08:00
|
|
|
saml {
|
|
|
|
idp_metadata_xml = each.value.saml.idp_metadata_xml
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 23:17:27 -07:00
|
|
|
resource "google_iam_workload_identity_pool" "default" {
|
|
|
|
provider = google-beta
|
2024-02-14 15:10:24 -08:00
|
|
|
count = length(local.workload_identity_providers) > 0 ? 1 : 0
|
2022-04-11 23:17:27 -07:00
|
|
|
project = module.automation-project.project_id
|
|
|
|
workload_identity_pool_id = "${var.prefix}-bootstrap"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_iam_workload_identity_pool_provider" "default" {
|
|
|
|
provider = google-beta
|
2024-02-14 15:10:24 -08:00
|
|
|
for_each = local.workload_identity_providers
|
2022-04-11 23:17:27 -07:00
|
|
|
project = module.automation-project.project_id
|
|
|
|
workload_identity_pool_id = (
|
2024-04-17 01:23:48 -07:00
|
|
|
google_iam_workload_identity_pool.default[0].workload_identity_pool_id
|
2022-04-11 23:17:27 -07:00
|
|
|
)
|
|
|
|
workload_identity_pool_provider_id = "${var.prefix}-bootstrap-${each.key}"
|
|
|
|
attribute_condition = each.value.attribute_condition
|
|
|
|
attribute_mapping = each.value.attribute_mapping
|
|
|
|
oidc {
|
2023-08-03 09:09:45 -07:00
|
|
|
# Setting an empty list configures allowed_audiences to the url of the provider
|
2023-08-15 03:59:31 -07:00
|
|
|
allowed_audiences = each.value.custom_settings.audiences
|
2023-10-04 21:17:20 -07:00
|
|
|
# If users don't provide an issuer_uri, we set the public one for the platform choosed.
|
2022-06-22 23:06:25 -07:00
|
|
|
issuer_uri = (
|
2023-08-03 09:09:45 -07:00
|
|
|
each.value.custom_settings.issuer_uri != null
|
2022-06-22 23:06:25 -07:00
|
|
|
? each.value.custom_settings.issuer_uri
|
|
|
|
: try(each.value.issuer_uri, null)
|
|
|
|
)
|
2023-12-21 09:10:50 -08:00
|
|
|
# OIDC JWKs in JSON String format. If no value is provided, they key is
|
2023-10-21 09:52:19 -07:00
|
|
|
# fetched from the `.well-known` path for the issuer_uri
|
|
|
|
jwks_json = each.value.custom_settings.jwks_json
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
}
|