【发布时间】:2019-10-22 08:48:23
【问题描述】:
在 2 台不同的 Windows 10 机器上工作,其中“terraform apply”在一台机器上工作,但在另一台机器上不工作。在移动到第二台电脑之前,我完全删除了 gcp 上的基础设施,并确保我只复制了 tf 文件 + 基本的 json。 (没有状态文件等)自从为管道做准备以来,我希望有一个干净的环境开始
codesnippit(完整的脚本在最后,在下面):
provider "kubernetes" {
host = "https://${google_container_cluster.primary.endpoint}"
username = "${var.username}"
password = "${var.password}"
client_certificate = "${base64decode(google_container_cluster.primary.master_auth[0].client_certificate)}"
client_key = "${base64decode(google_container_cluster.primary.master_auth[0].client_key)}"
cluster_ca_certificate = "${base64decode(google_container_cluster.primary.master_auth[0].cluster_ca_certificate)}"
version = "~> 1.7"
}
# Namespace
resource "kubernetes_namespace" "testspace" {
metadata {
annotations = {
name = "testspace"
}
name = "testspace"
}
}
根据我看到的所有示例,这应该可以工作,并且在我的笔记本电脑上确实可以,但在我的第二台机器上我收到以下错误:
Error: Failed to configure: username/password or bearer token may be set, but not both
on Deploy_Test.tf line 1, in provider "kubernetes":
1: provider "kubernetes" {
如果我删除用户名和密码,错误就会消失,但我无法创建命名空间,因为我没有授权?错误状态:
Error: namespaces is forbidden: User "client" cannot create namespaces at the cluster scope
现在我有点迷失了:这段代码在一台电脑上运行良好,但在另一台电脑上运行良好,我不知道为什么。在从新的干净 terraform 文件夹中开始后,再次从 pc 重新部署时 希望有人知道在哪里看?
到目前为止尝试了以下方法:
更新到 0.12.1 - 没有区别。
降级到 0.11 - 没有区别。
尝试了使用证书或用户名/密码组合的所有不同组合
provider "google" {
credentials = file("account.json")
project = var.project
region = var.region
version = "~> 2.7"
}
resource "google_container_cluster" "primary" {
name = "${var.name}-cluster"
location = var.region
initial_node_count = 1
master_auth {
username = var.username
password = var.password
/*
client_certificate_config {
issue_client_certificate = true
}
*/
}
node_version = "1.11.10-gke.4"
min_master_version = "1.11.10-gke.4"
node_config {
preemptible = true
machine_type = "n1-standard-1"
metadata = {
disable-legacy-endpoints = "true"
}
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",
]
}
}
provider "kubernetes" {
host = "https://${google_container_cluster.primary.endpoint}"
username = "${var.username}"
password = "${var.password}"
client_certificate = "${base64decode(google_container_cluster.primary.master_auth[0].client_certificate)}"
client_key = "${base64decode(google_container_cluster.primary.master_auth[0].client_key)}"
cluster_ca_certificate = "${base64decode(google_container_cluster.primary.master_auth[0].cluster_ca_certificate)}"
version = "~> 1.7"
}
# Namespace
resource "kubernetes_namespace" "testspace" {
metadata {
annotations = {
name = "testspace"
}
name = "testspace"
}
}
【问题讨论】:
标签: google-cloud-platform terraform google-kubernetes-engine