【问题标题】:Error while intergrating Terraform with github将 Terraform 与 github 集成时出错
【发布时间】:2021-06-21 16:21:00
【问题描述】:

我正在尝试将我的 Mac 上的 terraform 集成到 github。我已从 github 获取令牌并在以下代码中使用,但出现以下错误,可能是什么问题,

 Error: GET https://api.github.com/user: 401 Bad credentials []
 
   with provider["registry.terraform.io/integrations/github"],
   on github.tf line 10, in provider "github":
   10: provider "github" {

下面是代码供参考,


    terraform {
      required_providers {
        github = {
          source  = "integrations/github"
          version = "~> 4.0"
        }
      }
    }
    
    provider "github" {
      token = "9f07bd456019eebe4b0341f52ad3f5ad434a8c58"
    }
    
    resource "github_repository" "terraform" {
      name        = "Terraform"
      description = "Test for terraform intergration"
    
      visibility = "private"
    
    }

【问题讨论】:

  • 您是否尝试通过 Github Actions 在您的 Github 存储库上使用 Terraform? (如果是,我建议看看市场,那里已经创建了许多使用 Terraform 的自动化工具,以便更轻松地管理该工具:github.com/marketplace?type=actions&query=terraform+
  • 不,我正在尝试通过在我的 PC 上运行代码,使用 terraform 在 github 中创建 repo。为此我需要将 terraform 与 github 集成,所以在这种情况下它失败了。

标签: terraform github-actions


【解决方案1】:

如果您的 github 令牌有问题,则会出现此错误。

为确保令牌是好的,请在https://github.com/settings/tokens 创建一个具有“repo”权限的新令牌(如果您希望能够从 terraform 中删除它,还可以使用“delete_repo”)并将新令牌更新为你的地形代码。

如果您从 github 删除令牌,它也不会在您的 terraform 代码上运行,因此只要您打算继续在 terraform 上使用令牌,也不要删除 github 上的令牌。

【讨论】:

    猜你喜欢
    • 2012-10-25
    • 2019-05-30
    • 1970-01-01
    • 2014-03-08
    • 2016-12-11
    • 2011-09-26
    • 2017-09-27
    • 2017-08-06
    • 2016-09-12
    相关资源
    最近更新 更多