我正在尝试为rancher2配置Github身份验证,下面的链接是:https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/auth_config_github
但是当我使用这个资源时,我得到了401个未经授权的响应。
这是我的代码:
terraform {
required_providers {
rancher2 = {
source = "rancher/rancher2"
version = "1.21.0"
}
}
}
provider "rancher2" {
api_url = "https://{{ rancher_public_domain }}"
bootstrap = true
}
resource "rancher2_bootstrap" "admin" {
password = "{{ admin_password }}"
telemetry = false
ui_default_landing = "ember"
}
resource "rancher2_auth_config_github" "github" {
client_id = "<MY_GITHUB_CLIENT_ID>"
client_secret = "<MY_GITHUB_CLIENT_SECRET>"
enabled = true
}
output "rancher_username" {
value = rancher2_bootstrap.admin.user
}
output "rancher_token" {
value = rancher2_bootstrap.admin.token
sensitive = true
}
output "rancher_url" {
value = rancher2_bootstrap.admin.url
}错误是:
Error: Bad response statusCode [401]. Status [401 Unauthorized]. Body: [message=Unauthorized 401: must authenticate] from [https://{{ rancher_public_domain }}]
with rancher2_auth_config_github.github,
on main.tf line 21, in resource "rancher2_auth_config_github" "github":
21: resource "rancher2_auth_config_github" "github" {当我不使用这个资源时,错误不会发生。我能帮忙吗?谢谢
发布于 2022-01-27 14:02:40
根据Rancher/RKE认证文档和Rancher提供者文档,rancher2_auth_config_github需要一个具有admin配置的提供者,而不是bootstrap。我们可以使用rancher2_bootstrap资源的导出资源属性token对此进行身份验证:
provider "rancher2" {
api_url = rancher2_bootstrap.admin.url
token_key = rancher2_bootstrap.admin.token
}现在的问题是,第二个提供程序配置将与bootstrap提供程序配置发生冲突。为此,我们可以使用提供程序别名:
provider "rancher2" {
api_url = rancher2_bootstrap.admin.url
token_key = rancher2_bootstrap.admin.token
alias = "admin"
}
resource "rancher2_auth_config_github" "github" {
provider = rancher2.admin
client_id = "<MY_GITHUB_CLIENT_ID>"
client_secret = "<MY_GITHUB_CLIENT_SECRET>"
enabled = true
}https://stackoverflow.com/questions/70875381
复制相似问题