Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Invalid state of github_repository after a failed update #2426

Open
1 task done
krzysztofdrys opened this issue Oct 14, 2024 · 1 comment
Open
1 task done
Labels
Type: Bug Something isn't working as documented

Comments

@krzysztofdrys
Copy link

Expected Behavior

I don't have rights to update the repository settings. After I do terraform apply and the update fails, I want to see the correct stare.

In other words after failed apply like this:

❯ terraform apply
github_repository.yyy: Preparing import... [id=yyy]
github_repository.yyy: Refreshing state... [id=yyy]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # github_repository.yyy will be updated in-place
  # (imported from "yyy")
  ~ resource "github_repository" "yyy" {
        allow_auto_merge            = false
      ~ allow_merge_commit          = true -> false
      ~ allow_rebase_merge          = true -> false
        allow_squash_merge          = true
        allow_update_branch         = false
        archived                    = false
        auto_init                   = false
        default_branch              = "master"
        delete_branch_on_merge      = false
        etag                        = "W/\"c6fc49c0c8587160963c8cc0756f7d56f1bbbd9bba78f5279b22ebd1a64d579d\""
        full_name                   = "xxx/yyy"
        git_clone_url               = "git://github.com/xxx/yyy.git"
        has_discussions             = false
      ~ has_downloads               = true -> false
      ~ has_issues                  = true -> false
      ~ has_projects                = true -> false
      ~ has_wiki                    = true -> false
        html_url                    = "https://github.com/xxx/yyy"
        http_clone_url              = "https://github.com/xxx/yyy.git"
        id                          = "yyy"
        is_template                 = false
        merge_commit_message        = "PR_TITLE"
        merge_commit_title          = "MERGE_MESSAGE"
        name                        = "yyy"
        node_id                     = "MDEwOlJlcG9zaXRvcnkyNTQyMTAxNjM="
        primary_language            = "Mustache"
        private                     = true
        repo_id                     = 254210163
        squash_merge_commit_message = "COMMIT_MESSAGES"
        squash_merge_commit_title   = "COMMIT_OR_PR_TITLE"
        ssh_clone_url               = "[email protected]:xxx/yyy.git"
        svn_url                     = "https://github.com/xxx/yyy"
        topics                      = []
        visibility                  = "private"
        vulnerability_alerts        = false
        web_commit_signoff_required = false
    }

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

github_repository.yyy: Importing... [id=yyy]
github_repository.yyy: Import complete [id=yyy]
github_repository.yyy: Modifying... [id=yyy]
╷
│ Error: PATCH https://api.github.com/repos/xxx/yyy: 404 Not Found []
│ 
│   with github_repository.yyy,
│   on main.tf line 1, in resource "github_repository" "yyy":
│    1: resource "github_repository" "yyy" {
│ 
╵

I expect next terraform plan to show the same changes as the first terraform apply showed.

Actual Behavior

I am "stuck" with the incorrect state. Terraform apply changed some parts of the state, but not etag, so terraform plan or terraform refresh will not fetch the actual state.

❯ terraform plan
github_repository.yyy Refreshing state... [id=yyy]

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.

Terraform Version

Terraform v1.7.4
on darwin_amd64

  • provider registry.terraform.io/integrations/github v6.3.1

Affected Resource(s)

github_repository

Terraform Configuration Files

# When doing terraform apply, you should be able to "see" repository yyy, but not
# to modify it.

resource "github_repository" "yyy" {
  name = "yyy"

  has_downloads = false
  has_issues = false
  has_projects = false
  has_wiki = false

  allow_merge_commit = false
  allow_rebase_merge = false
}

import {
  id = "yyy"
  to = github_repository.yyy
}

terraform {
  required_version = ">= 1.1.5"
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 6.0"
    }
  }
}

provider "github" {
  owner = "xxx"
}

Steps to Reproduce

terraform apply
terraform plan

Debug Output

No response

Panic Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@krzysztofdrys krzysztofdrys added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Oct 14, 2024
@krzysztofdrys
Copy link
Author

Additional information: I use GitHub CLI authentication.

@kfcampbell kfcampbell removed the Status: Triage This is being looked at and prioritized label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

2 participants