forked from metro-digital/terraform-google-cf-projectcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwif.tf
53 lines (47 loc) · 2.15 KB
/
wif.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright 2023 METRO Digital GmbH
#
# 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.
locals {
# Check if ANY given service account has a GitHub action repository configured
github_actions_enabled = length(compact([
for sa, config in var.service_accounts : sa if length(config.github_action_repositories) > 0
])) > 0 ? 1 : 0
# Check if ANY given service account has a Kubernetes Runtime Service Account configured
runtime_service_accounts_enabled = length(compact([
for sa, config in var.service_accounts : sa if length(config.runtime_service_accounts) > 0
])) > 0 ? 1 : 0
# We also need to enable some services to make the Workload Identity Federation setup possible
# if we have any usage of the service
wif_needed_services = (local.github_actions_enabled + local.runtime_service_accounts_enabled) > 0 ? toset([
"cloudresourcemanager.googleapis.com",
"iamcredentials.googleapis.com",
"sts.googleapis.com"
]) : toset([])
}
# renamed in v2.2 - Can be removed with v3
# Announce in a V3 release to upgrade to at least v2.2 first
moved {
from = google_project_service.github_actions
to = google_project_service.wif
}
resource "google_project_service" "wif" {
project = data.google_project.project.project_id
for_each = local.wif_needed_services
service = each.key
# The user may enable/use the needed services somewhere else, too!
# Hence, we are never disabling them again, even if we initially enabled them here.
# Keeping the service enabled is way less dangerous than disabling them, even if
# we do not have a reason to keep them enabled any longer. Users can still disable
# via CLI / UI if needed.
disable_on_destroy = false
}