Проблема импорта Terraform: объекты были изменены вне Terraform

На 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.

Однако проблема в том, что когда я нажимаю свой локальный компьютер в свой PR на github, который подключен к Terraform, работающему на Jenkins... в плане 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.

Таким образом, он не улавливает импорт терраформ, который я сделал локально. Я не знаю, почему это происходит, и не знаю, как это исправить.

1 ответ

Решением было то, что используемый токен личного доступа github не имел правильных разрешений для учетной записи / репозитория github. Поэтому использовался новый токен с дополнительными разрешениями на доступ, и эта проблема была исправлена.