|
| 1 | +/** |
| 2 | + * Copyright 2018 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +{{ autogeneration_note }} |
| 18 | + |
| 19 | +locals { |
| 20 | + service_account_list = "${compact(concat(google_service_account.cluster_service_account.*.email, list("dummy")))}" |
| 21 | + service_account = "${var.service_account == "create" ? element(local.service_account_list, 0) : var.service_account}" |
| 22 | +} |
| 23 | + |
| 24 | +resource "google_service_account" "cluster_service_account" { |
| 25 | + count = "${var.service_account == "create" ? 1 : 0}" |
| 26 | + project = "${var.project_id}" |
| 27 | + account_id = "tf-gke-${substr(var.name, 0, 20)}" |
| 28 | + display_name = "Terraform-managed service account for cluster ${var.name}" |
| 29 | +} |
| 30 | + |
| 31 | +resource "google_project_iam_member" "cluster_service_account-log_writer" { |
| 32 | + count = "${var.service_account == "create" ? 1 : 0}" |
| 33 | + project = "${google_service_account.cluster_service_account.project}" |
| 34 | + role = "roles/logging.logWriter" |
| 35 | + member = "serviceAccount:${google_service_account.cluster_service_account.email}" |
| 36 | +} |
| 37 | + |
| 38 | +resource "google_project_iam_member" "cluster_service_account-metric_writer" { |
| 39 | + count = "${var.service_account == "create" ? 1 : 0}" |
| 40 | + project = "${google_project_iam_member.cluster_service_account-log_writer.project}" |
| 41 | + role = "roles/monitoring.metricWriter" |
| 42 | + member = "serviceAccount:${google_service_account.cluster_service_account.email}" |
| 43 | +} |
| 44 | + |
| 45 | +resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" { |
| 46 | + count = "${var.service_account == "create" ? 1 : 0}" |
| 47 | + project = "${google_project_iam_member.cluster_service_account-metric_writer.project}" |
| 48 | + role = "roles/monitoring.viewer" |
| 49 | + member = "serviceAccount:${google_service_account.cluster_service_account.email}" |
| 50 | +} |
0 commit comments