在tf版本1.0.3上
我在本地导入资源:
terraform import github_repository.terraform-xxxx-github_repo terraform-xxxx-github
github_repository.terraform-xxxx-github_repo: Importing from ID "terraform-xxxx-github"...
github_repository.terraform-xxxx-github_repo: Import prepared!
Prepared github_repository for import
github_repository.terraform-xxxx-github_repo: Refreshing state... [id=terraform-xxxx-github]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.这是repos.tf文件中的资源配置:
resource "github_repository" "terraform-xxxx-github_repo" {
name = "terraform-xxxx-github"
visibility = "private"
has_projects = true
has_wiki = true
has_issues = true
has_downloads = true
allow_merge_commit = true
allow_squash_merge = true
allow_rebase_merge = true
archived = false
auto_init = false
}现在,当我在本地运行tf init和tf plan时,我确实看不到任何变化:
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of integrations/github from the dependency lock file
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed integrations/github v4.13.0
- Using previously-installed hashicorp/aws v3.54.0
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.当我运行tf plan时:
github_repository.terraform-xxxx-github_repo: Refreshing state... [id=terraform-xxxx-github]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.然而,问题是当我将我的本地推送到我的github PR中时,它连接到在Jenkins上运行的Terraform……在Jenkins tf计划中,我看到了以下内容:
10:59:30 + terraform plan -input=false -out=terraform.plan
10:59:33 github_repository.terraform-xxxx-github_repo: Refreshing state... [id=terraform-xxxx-github]
10:59:33
10:59:33 Note: Objects have changed outside of Terraform
10:59:33
10:59:33 Terraform detected the following changes made outside of Terraform since the
10:59:33 last "terraform apply":
10:59:33
10:59:33 # github_repository.terraform-xxxx-github_repo has been deleted
10:59:33 - resource "github_repository" "terraform-xxxx-github_repo" {
10:59:33 - allow_merge_commit = true -> null
10:59:33 - allow_rebase_merge = true -> null
10:59:33 - allow_squash_merge = true -> null
10:59:33 - archived = false -> null
10:59:33 - auto_init = false -> null
10:59:33 - default_branch = "master" -> null
10:59:33 - visibility = "private" -> null
10:59:33 }
10:59:33
10:59:33 Unless you have made equivalent changes to your configuration, or ignored the
10:59:33 relevant attributes using ignore_changes, the following plan may include
10:59:33 actions to undo or respond to these changes.
10:59:33
10:59:33 ─────────────────────────────────────────────────────────────────────────────
10:59:33
10:59:33 Terraform used the selected providers to generate the following execution
10:59:33 plan. Resource actions are indicated with the following symbols:
10:59:33 + create
10:59:33
10:59:33 Terraform will perform the following actions:
10:59:33
10:59:33 # github_repository.terraform-xxxx-github_repo will be created
10:59:33 + resource "github_repository" "terraform-xxxx-github_repo" {
10:59:33 + allow_merge_commit = true
10:59:33 + allow_rebase_merge = true
10:59:33 + allow_squash_merge = true
10:59:33 + archived = false
10:59:33 + auto_init = false
10:59:33 + default_branch = (known after apply)
10:59:33 + visibility = "private"
10:59:33 }
10:59:33
10:59:33 Plan: 1 to add, 0 to change, 0 to destroy.因此,它不会拾取我在本地执行的terraform导入。我不知道为什么会发生这种情况,也不知道如何解决这个问题。
发布于 2021-08-20 18:52:05
该问题的解决方案是,正在使用的github个人访问令牌没有github帐户/repo的正确权限。因此,使用了具有更多访问权限的新令牌,并修复了此问题。
https://stackoverflow.com/questions/68850706
复制相似问题