|
| 1 | +/** |
| 2 | +* Copyright 2025 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 | +# Create a custom IAM node service account with the minimum role for GKE |
| 18 | + |
| 19 | +# [START gke_node_service_account] |
| 20 | +# [START gke_node_service_account_create] |
| 21 | +resource "google_service_account" "default" { |
| 22 | + account_id = "gke-node-service-account" |
| 23 | + display_name = "GKE node service account" |
| 24 | +} |
| 25 | +# [END gke_node_service_account_create] |
| 26 | + |
| 27 | +# [START gke_node_service_account_role] |
| 28 | +data "google_project" "project" { |
| 29 | +} |
| 30 | + |
| 31 | +resource "google_project_iam_member" "default" { |
| 32 | + project = data.google_project.project.project_id |
| 33 | + role = "roles/container.defaultNodeServiceAccount" |
| 34 | + member = "serviceAccount:${google_service_account.default.email}" |
| 35 | +} |
| 36 | +# [END gke_node_service_account_role] |
| 37 | +# [END gke_node_service_account] |
0 commit comments