integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
891 stars 736 forks source link

[BUG]: Importing github_repository_tag_protection resource results in type conversion error #2211

Open fmg-matthew-rabjones opened 6 months ago

fmg-matthew-rabjones commented 6 months ago

Expected Behavior

github_repository_tag_protection resource is successfully imported & plan succeeds

Actual Behavior

Error: tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: '12345'

Terraform Version

Terraform v1.7.5 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "6.2.0"
    }
  }
}

provider "github" {
  owner = "my-org"
  token = "my-token"
}

import {
  id = "my-cool-existing-repo"
  to = github_repository.repository
}

import {
  id = "my-cool-existing-repo/12345"
  to = github_repository_tag_protection.all
}

resource "github_repository" "repository" {
  name = "my-cool-existing-repo"
}

resource "github_repository_tag_protection" "all" {
  repository = github_repository.repository
  pattern = "*"
}

Steps to Reproduce

terraform plan

Debug Output

2024-03-25T14:17:07.637+0800 [INFO]  Terraform version: 1.7.5
2024-03-25T14:17:07.637+0800 [DEBUG] using github.com/hashicorp/go-tfe v1.41.0
2024-03-25T14:17:07.637+0800 [DEBUG] using github.com/hashicorp/hcl/v2 v2.19.1
2024-03-25T14:17:07.637+0800 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2024-03-25T14:17:07.637+0800 [DEBUG] using github.com/zclconf/go-cty v1.14.1
2024-03-25T14:17:07.637+0800 [INFO]  Go runtime version: go1.21.8
2024-03-25T14:17:07.637+0800 [INFO]  CLI args: []string{"terraform", "plan"}
2024-03-25T14:17:07.637+0800 [DEBUG] Attempting to open CLI config file: /home/matt/.terraformrc
2024-03-25T14:17:07.637+0800 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2024-03-25T14:17:07.637+0800 [INFO]  Loading CLI configuration from /home/matt/.terraform.d/credentials.tfrc.json
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory /home/matt/.terraform.d/plugins
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory /home/matt/.local/share/terraform/plugins
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory /usr/share/plasma/terraform/plugins
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2024-03-25T14:17:07.637+0800 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2024-03-25T14:17:07.637+0800 [INFO]  CLI command args: []string{"plan"}
2024-03-25T14:17:07.638+0800 [DEBUG] New state was assigned lineage "e2309403-7cc1-e3ee-fc37-fc26ae1eae02"
2024-03-25T14:17:07.653+0800 [DEBUG] checking for provisioner in "."
2024-03-25T14:17:07.658+0800 [DEBUG] checking for provisioner in "/usr/bin"
2024-03-25T14:17:07.658+0800 [INFO]  backend/local: starting Plan operation
2024-03-25T14:17:07.659+0800 [DEBUG] created provider logger: level=debug
2024-03-25T14:17:07.659+0800 [INFO]  provider: configuring client automatic mTLS
2024-03-25T14:17:07.665+0800 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 args=[".terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0"]
2024-03-25T14:17:07.665+0800 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389573
2024-03-25T14:17:07.665+0800 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0
2024-03-25T14:17:07.669+0800 [INFO]  provider.terraform-provider-github_v6.2.0: configuring server automatic mTLS: timestamp="2024-03-25T14:17:07.669+0800"
2024-03-25T14:17:07.677+0800 [DEBUG] provider: using plugin: version=5
2024-03-25T14:17:07.677+0800 [DEBUG] provider.terraform-provider-github_v6.2.0: plugin address: address=/tmp/plugin3671954571 network=unix timestamp="2024-03-25T14:17:07.677+0800"
2024-03-25T14:17:07.705+0800 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-03-25T14:17:07.706+0800 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389573
2024-03-25T14:17:07.709+0800 [DEBUG] provider: plugin exited
2024-03-25T14:17:07.709+0800 [DEBUG] Building and walking validate graph
2024-03-25T14:17:07.709+0800 [DEBUG] ProviderTransformer: "github_repository.repository" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/integrations/github"]
2024-03-25T14:17:07.709+0800 [DEBUG] ProviderTransformer: "github_repository_tag_protection.all" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/integrations/github"]
2024-03-25T14:17:07.710+0800 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/integrations/github\"]" references: []
2024-03-25T14:17:07.710+0800 [DEBUG] ReferenceTransformer: "github_repository.repository" references: []
2024-03-25T14:17:07.710+0800 [DEBUG] ReferenceTransformer: "github_repository_tag_protection.all" references: [github_repository.repository]
2024-03-25T14:17:07.710+0800 [DEBUG] Starting graph walk: walkValidate
2024-03-25T14:17:07.711+0800 [DEBUG] created provider logger: level=debug
2024-03-25T14:17:07.711+0800 [INFO]  provider: configuring client automatic mTLS
2024-03-25T14:17:07.719+0800 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 args=[".terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0"]
2024-03-25T14:17:07.719+0800 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389591
2024-03-25T14:17:07.719+0800 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0
2024-03-25T14:17:07.726+0800 [INFO]  provider.terraform-provider-github_v6.2.0: configuring server automatic mTLS: timestamp="2024-03-25T14:17:07.726+0800"
2024-03-25T14:17:07.741+0800 [DEBUG] provider.terraform-provider-github_v6.2.0: plugin address: address=/tmp/plugin2229167247 network=unix timestamp="2024-03-25T14:17:07.741+0800"
2024-03-25T14:17:07.741+0800 [DEBUG] provider: using plugin: version=5
2024-03-25T14:17:07.754+0800 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-03-25T14:17:07.755+0800 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389591
2024-03-25T14:17:07.757+0800 [DEBUG] provider: plugin exited
2024-03-25T14:17:07.757+0800 [INFO]  backend/local: plan calling Plan
2024-03-25T14:17:07.757+0800 [DEBUG] Building and walking plan graph for NormalMode
2024-03-25T14:17:07.757+0800 [DEBUG] ProviderTransformer: "github_repository.repository (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/integrations/github"]
2024-03-25T14:17:07.757+0800 [DEBUG] ProviderTransformer: "github_repository_tag_protection.all (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/integrations/github"]
2024-03-25T14:17:07.758+0800 [DEBUG] ReferenceTransformer: "github_repository.repository (expand)" references: []
2024-03-25T14:17:07.758+0800 [DEBUG] ReferenceTransformer: "github_repository_tag_protection.all (expand)" references: [github_repository.repository (expand)]
2024-03-25T14:17:07.758+0800 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/integrations/github\"]" references: []
2024-03-25T14:17:07.758+0800 [DEBUG] Starting graph walk: walkPlan
2024-03-25T14:17:07.758+0800 [DEBUG] created provider logger: level=debug
2024-03-25T14:17:07.758+0800 [INFO]  provider: configuring client automatic mTLS
2024-03-25T14:17:07.765+0800 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 args=[".terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0"]
2024-03-25T14:17:07.765+0800 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389604
2024-03-25T14:17:07.765+0800 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0
2024-03-25T14:17:07.771+0800 [INFO]  provider.terraform-provider-github_v6.2.0: configuring server automatic mTLS: timestamp="2024-03-25T14:17:07.771+0800"
2024-03-25T14:17:07.785+0800 [DEBUG] provider: using plugin: version=5
2024-03-25T14:17:07.785+0800 [DEBUG] provider.terraform-provider-github_v6.2.0: plugin address: address=/tmp/plugin3989375123 network=unix timestamp="2024-03-25T14:17:07.785+0800"
2024-03-25T14:17:07.792+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/integrations/github\"]" changed the config value, but that value is unused
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [INFO] Selecting owner  from GITHUB_OWNER environment variable: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [INFO] Setting write_delay_ms to 1000: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [DEBUG] Setting read_delay_ms to 0: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [DEBUG] Setting retry_delay_ms to 0: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [DEBUG] Setting max_retries to 3: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [DEBUG] Setting retriableErrors to map[500:true 502:true 503:true 504:true]: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:07.792+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:07 [DEBUG] Setting parallel_requests to false: timestamp="2024-03-25T14:17:07.792+0800"
2024-03-25T14:17:08.622+0800 [DEBUG] Resource instance state not found for node "github_repository.repository", instance github_repository.repository
2024-03-25T14:17:08.622+0800 [DEBUG] ReferenceTransformer: "github_repository.repository" references: []
github_repository.repository: Preparing import... [id=my-cool-existing-repo]
github_repository.repository: Refreshing state... [id=my-cool-existing-repo]
2024-03-25T14:17:09.416+0800 [WARN]  Provider "registry.terraform.io/integrations/github" produced an unexpected new value for github_repository.repository during refresh.
      - .allow_update_branch: was null, but now cty.True
      - .has_projects: was null, but now cty.True
      - .has_wiki: was null, but now cty.False
      - .is_template: was null, but now cty.False
      - .node_id: was null, but now cty.StringVal("repo-node-id")
      - .allow_squash_merge: was null, but now cty.True
      - .has_downloads: was null, but now cty.False
      - .merge_commit_message: was null, but now cty.StringVal("PR_TITLE")
      - .web_commit_signoff_required: was null, but now cty.False
      - .http_clone_url: was null, but now cty.StringVal("https://github.com/my-org/my-cool-existing-repo.git")
      - .ssh_clone_url: was null, but now cty.StringVal("git@github.com:my-org/my-cool-existing-repo.git")
      - .allow_merge_commit: was null, but now cty.False
      - .archived: was null, but now cty.False
      - .description: was null, but now cty.StringVal("Created by terraform for the purpose of testing repo automation, this will be deleted")
      - .has_issues: was null, but now cty.False
      - .merge_commit_title: was null, but now cty.StringVal("MERGE_MESSAGE")
      - .topics: was null, but now cty.SetVal([]cty.Value{cty.StringVal("internal-unit")})
      - .vulnerability_alerts: was null, but now cty.False
      - .etag: was null, but now cty.StringVal("W/\"a72c9b19467f2f45e82f4d9763b53cca1427fa286d35e48bc3de67da4cd9a07d\"")
      - .full_name: was null, but now cty.StringVal("my-org/my-cool-existing-repo")
      - .git_clone_url: was null, but now cty.StringVal("git://github.com/my-org/my-cool-existing-repo.git")
      - .html_url: was null, but now cty.StringVal("https://github.com/my-org/my-cool-existing-repo")
      - .private: was null, but now cty.True
      - .squash_merge_commit_title: was null, but now cty.StringVal("PR_TITLE")
      - .squash_merge_commit_message: was null, but now cty.StringVal("BLANK")
      - .allow_rebase_merge: was null, but now cty.False
      - .default_branch: was null, but now cty.StringVal("master")
      - .homepage_url: was null, but now cty.StringVal("")
      - .name: was null, but now cty.StringVal("my-cool-existing-repo")
      - .visibility: was null, but now cty.StringVal("private")
      - .allow_auto_merge: was null, but now cty.False
      - .delete_branch_on_merge: was null, but now cty.True
      - .has_discussions: was null, but now cty.False
      - .primary_language: was null, but now cty.StringVal("Python")
      - .repo_id: was null, but now cty.NumberIntVal(5.62694802e+08)
      - .svn_url: was null, but now cty.StringVal("https://github.com/my-org/my-cool-existing-repo")
2024-03-25T14:17:09.433+0800 [WARN]  Provider "registry.terraform.io/integrations/github" produced an invalid plan for github_repository.repository, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .homepage_url: planned value cty.StringVal("") for a non-computed attribute
      - .squash_merge_commit_message: planned value cty.StringVal("COMMIT_MESSAGES") for a non-computed attribute
      - .allow_rebase_merge: planned value cty.True for a non-computed attribute
      - .delete_branch_on_merge: planned value cty.False for a non-computed attribute
      - .has_discussions: planned value cty.False for a non-computed attribute
      - .allow_auto_merge: planned value cty.False for a non-computed attribute
      - .has_wiki: planned value cty.False for a non-computed attribute
      - .is_template: planned value cty.False for a non-computed attribute
      - .auto_init: planned value cty.False for a non-computed attribute
      - .has_downloads: planned value cty.False for a non-computed attribute
      - .merge_commit_message: planned value cty.StringVal("PR_TITLE") for a non-computed attribute
      - .web_commit_signoff_required: planned value cty.False for a non-computed attribute
      - .allow_squash_merge: planned value cty.True for a non-computed attribute
      - .archived: planned value cty.False for a non-computed attribute
      - .has_issues: planned value cty.False for a non-computed attribute
      - .allow_merge_commit: planned value cty.True for a non-computed attribute
      - .vulnerability_alerts: planned value cty.False for a non-computed attribute
      - .merge_commit_title: planned value cty.StringVal("MERGE_MESSAGE") for a non-computed attribute
      - .squash_merge_commit_title: planned value cty.StringVal("COMMIT_OR_PR_TITLE") for a non-computed attribute
2024-03-25T14:17:09.434+0800 [DEBUG] Resource instance state not found for node "github_repository_tag_protection.all", instance github_repository_tag_protection.all
2024-03-25T14:17:09.435+0800 [DEBUG] ReferenceTransformer: "github_repository_tag_protection.all" references: []
github_repository_tag_protection.all: Preparing import... [id=my-cool-existing-repo/tag-protection-id]
2024-03-25T14:17:09.436+0800 [INFO]  provider.terraform-provider-github_v6.2.0: 2024/03/25 14:17:09 [ERROR] setting state: tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: 'tag-protection-id': timestamp="2024-03-25T14:17:09.435+0800"
2024-03-25T14:17:09.436+0800 [ERROR] provider.terraform-provider-github_v6.2.0: Response contains error diagnostic: diagnostic_summary="tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: 'tag-protection-id'" tf_proto_version=5.4 tf_req_id=9f5775e3-952a-47d2-3d6f-a207690feabc tf_resource_type=github_repository_tag_protection diagnostic_detail="" tf_provider_addr=provider tf_rpc=ImportResourceState @caller=github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/diag/diagnostics.go:58 diagnostic_severity=ERROR @module=sdk.proto timestamp="2024-03-25T14:17:09.436+0800"
2024-03-25T14:17:09.436+0800 [ERROR] vertex "github_repository_tag_protection.all" error: tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: 'tag-protection-id'
2024-03-25T14:17:09.436+0800 [ERROR] vertex "github_repository_tag_protection.all (expand)" error: tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: 'tag-protection-id'
2024-03-25T14:17:09.436+0800 [INFO]  backend/local: plan operation completed

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

Terraform planned the following actions, but then encountered a problem:

  # github_repository.repository will be updated in-place
  # (imported from "my-cool-existing-repo")
  ~ resource "github_repository" "repository" {
        allow_auto_merge            = false
      ~ allow_merge_commit          = false -> true
      ~ allow_rebase_merge          = false -> true
        allow_squash_merge          = true
      - allow_update_branch         = true -> null
        archived                    = false
        auto_init                   = false
        default_branch              = "master"
      ~ delete_branch_on_merge      = true -> false
      - description                 = "Created by terraform for the purpose of testing repo automation, this will be deleted" -> null
        etag                        = "W/\"a72c9b19467f2f45e82f4d9763b53cca1427fa286d35e48bc3de67da4cd9a07d\""
        full_name                   = "my-org/my-cool-existing-repo"
        git_clone_url               = "git://github.com/my-org/my-cool-existing-repo.git"
        has_discussions             = false
        has_downloads               = false
        has_issues                  = false
      - has_projects                = true -> null
        has_wiki                    = false
        html_url                    = "https://github.com/my-org/my-cool-existing-repo"
        http_clone_url              = "https://github.com/my-org/my-cool-existing-repo.git"
        id                          = "my-cool-existing-repo"
        is_template                 = false
        merge_commit_message        = "PR_TITLE"
        merge_commit_title          = "MERGE_MESSAGE"
        name                        = "my-cool-existing-repo"
        node_id                     = "repo-node-id"
        primary_language            = "Python"
        private                     = true
        repo_id                     = repo-id
      ~ squash_merge_commit_message = "BLANK" -> "COMMIT_MESSAGES"
      ~ squash_merge_commit_title   = "PR_TITLE" -> "COMMIT_OR_PR_TITLE"
        ssh_clone_url               = "git@github.com:my-org/my-cool-existing-repo.git"
        svn_url                     = "https://github.com/my-org/my-cool-existing-repo"
        topics                      = [
            "internal-unit",
        ]
        visibility                  = "private"
        vulnerability_alerts        = false
        web_commit_signoff_required = false
    }

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.
╷
│ Error: tag_protection_id: '' expected type 'int', got unconvertible type 'string', value: 'tag-protection-id'
│ 
│ 
╵
2024-03-25T14:17:09.442+0800 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-03-25T14:17:09.446+0800 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/integrations/github/6.2.0/linux_amd64/terraform-provider-github_v6.2.0 pid=389604
2024-03-25T14:17:09.448+0800 [DEBUG] provider: plugin exited

Panic Output

No response

Code of Conduct