在具有Terraform权限错误的GCP上构建GKE集群

时间:2019-07-26 14:39:32

标签: google-cloud-platform terraform

我正在尝试使用Terraform 0.12.5添加一个GKE群集[据我所知,以前在0.11.7上还可以]

resource "google_container_cluster" "primary" {
  name = "gke-${terraform.workspace}-cluster"
  zone = "${var.region}-b"

  initial_node_count = 3
  network            = "${var.vpc_name}"
  subnetwork         = "${var.subnet_name}"

  addons_config {

    horizontal_pod_autoscaling {
      disabled = false
    }

    kubernetes_dashboard {
      disabled = false
    }
  }

  # getting a vpc-native network
  ip_allocation_policy {
  }

  master_auth {
    username = "${var.gke_master_user}"
    password = "${var.gke_master_pass}"
  }

  node_config {
    oauth_scopes = [
      "https://www.googleapis.com/auth/compute",
      "https://www.googleapis.com/auth/devstorage.read_only",
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
    ]

    labels = {
      env = "${var.gke_label[terraform.workspace]}"
    }

    disk_size_gb = 10
    machine_type = "${var.gke_node_machine_type}"
    tags         = ["gke-node"]
  }
}

我是根据具有以下角色的服务帐户运行此

  • roles / compute.networkAdmin
  • roles / resourcemanager.projectCreator
  • roles / storage.admin

但是令我惊讶的是,我现在在构建GKE集群时遇到了权限问题。

1) deploy error: Not all instances running in IGM after 10.808470514s. 
Expect 1. Current errors: [PERMISSIONS_ERROR]: Instance 'gke-gke-dev- 
cluster-default-pool-6266baac-0pn3' creation failed: Required 
'compute.instances.create' permission for 
'projects/353065647996/zones/europe-west1-b/instances/gke-gke-dev- 
cluster-default-pool-6266baac-0pn3' (when acting as 
'353065647996@cloudservices.gserviceaccount.com'); 
[PERMISSIONS_ERROR]: Instance 'gke-gke-dev-cluster-default-pool- 
6266baac-0pn3' creation failed: Required 'compute.disks.create' 
permission for 'projects/353065647996/zones/europe-west1-b/disks/gke- 
gke-dev-cluster-default-pool-6266baac-0pn3' (when acting as 
'353065647996@cloudservices.gserviceaccount.com'); 
[PERMISSIONS_ERROR]: Instance 'gke-gke-dev-cluster-default-pool- 
6266baac-0pn3' creation failed: Required 'compute.subnetworks.use' 
permission for 'projects/353065647996/regions/europe- 
west1/subnetworks/dev-subnet' (when acting as 
'353065647996@cloudservices.gserviceaccount.com'); 
[PERMISSIONS_ERROR]: Instance 'gke-gke-dev-cluster-default-pool- 
6266baac-0pn3' creation failed: Required 
'compute.subnetworks.useExternalIp' permission for 
'projects/353065647996/regions/europe-west1/subnetworks/dev-subnet' 
(when acting as '353065647996@cloudservices.gserviceaccount.com'); 
[PERMISSIONS_ERROR]: Instance 'gke-gke-dev-cluster-default-pool- 
6266baac-0pn3' creation failed: Required 
'compute.instances.setMetadata' permission for 
'projects/353065647996/zones/europe-west1-b/instances/gke-gke-dev- 
cluster-default-pool-6266baac-0pn3' (when acting as 
'353065647996@cloudservices.gserviceaccount.com') (truncated)

此服务帐户353065647996@cloudservices.gserviceaccount.com是为项目创建的,并且继承了原始服务帐户。我不清楚如何为它提供正确的角色/凭据。

1 个答案:

答案 0 :(得分:0)

这是由于在创建项目时将仅具有查看权限的用户添加为最后一个用户引起的。删除该用户,它按预期运行。