当您导入到
github_repository
你需要使用
name
.
https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository#import
可以使用以下名称导入存储库
在您的repos文件中
名称
s只是repo名称,但在您的导入中,您可以用owner作为前缀。但是您的PAT令牌已经与之关联,并且可能会添加前缀,因此您的导入将成为
evoteum/evoteum/estate-config
我已经能够用以下方式重现这个问题
resource "github_repository" "repo" {
name = "killercoda"
}
import {
id = "cdsre/killercoda"
to = github_repository.repo
}
$ terraform apply
github_repository.repo: Preparing import... [id=cdsre/killercoda]
github_repository.repo: Refreshing state... [id=cdsre/killercoda]
â·
â Error: Cannot import non-existent remote object
â
â While attempting to import an existing object to "github_repository.repo", the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id
â is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
âµ
当我从导入中的id中删除我的用户前缀时
github_repository.repo: Importing... [id=killercoda]
github_repository.repo: Import complete [id=killercoda]
github_repository.repo: Modifying... [id=killercoda]
github_repository.repo: Modifications complete after 2s [id=killercoda]
Apply complete! Resources: 1 imported, 0 added, 1 changed, 0 destroyed.
编辑
我已经检查了github terraform提供者的源代码,可以看到这正是发生的事情
https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_repository.go#L628
func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
repoName := d.Id()
...
...
repo, resp, err := client.Repositories.Get(ctx, owner, repoName)