terraform导入失败,terraform云远程后端

terraform导入失败,terraform云远程后端,terraform,terraform-provider-github,terraform-cloud,Terraform,Terraform Provider Github,Terraform Cloud,我正在尝试将现有的github存储库导入terraform。我决定尝试terraform cloud,设置好后,terraform导入s会因401未经授权而失败,即使一切都设置正确 基本上,我有: provider "github" { token = "${var.github_token}" organization = "goreleaser" } terraform { required_version = "~> 0.12.0" } variable

我正在尝试将现有的github存储库导入terraform。我决定尝试terraform cloud,设置好后,
terraform导入
s会因
401未经授权
而失败,即使一切都设置正确

基本上,我有:

provider "github" {
  token        = "${var.github_token}"
  organization = "goreleaser"
}

terraform {
  required_version = "~> 0.12.0"
}

variable "github_token" {
  type = string
}

resource "github_repository" "goreleaser" {
  name = "goreleaser"
}
如果我运行
terraform import github\u repository.goreleaser goreleaser
,它将按预期工作(我在环境上有一个
TF\u VAR\u github\u令牌)

如果我添加远程后端:

terraform {
  required_version = "~> 0.12.0"

  backend "remote" {
    hostname     = "app.terraform.io"
    organization = "goreleaser"

    workspaces {
      name = "tf"
    }
  }
}
然后运行相同的命令,我得到:

github_repository.goreleaser: Importing from ID "goreleaser"...
github_repository.goreleaser: Import prepared!
  Prepared github_repository for import
github_repository.goreleaser: Refreshing state... [id=goreleaser]

Error: GET https://api.github.com/repos/goreleaser/goreleaser: 401 Bad credentials []
这样行吗


我在terraform cloud上也设置了变量-远程
terraform plan
工作,但导入失败。

您如何提供您的terraform cloud令牌?在
~/.terraformrc
,根据文档…
terraform import
目前(从terraform 0.12.9开始)是一个仅限本地的命令,即使工作区配置为远程操作,它也将在运行terraform import的系统上运行。因此,对于导入,您需要在本地配置GitHub API凭据。远程操作仅支持主
terraform plan
terraform apply
工作流命令。@MartinAtkins我在本地也有它,作为一个环境变量(
TF\u VAR\u github\u token
)。我需要不同的设置吗?