Skip to content

[BUG]: repository_ruleset crash on empty required_deployment_environments #1915

Description

@lewismiddleton

Expected Behavior

Should define an empty list of required deployments.

Equivalent of ticking the box in the UI but not specifying anything. See screenshot
Screenshot

Actual Behavior

Throws error

The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.

Seems like there was an error in repository_rules_utils.go. It fails to cast the required_deployments block to a map of strings because v[0] == nil.

Terraform Version

Terraform v1.5.7

Affected Resource(s)

  • github_repository_ruleset

Terraform Configuration Files

resource "github_repository_ruleset" "failure" {
  repository  = <insert repo here>
  name        = "failure"
  enforcement = "evaluate"
  target      = "branch"

  rules {
    # just here to so that removing the required_deployments block is still valid
    update = true

    required_deployments {
      required_deployment_environments = []
    }
  }
}

Steps to Reproduce

No response

Debug Output

No response

Panic Output

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with
the following symbols:
  + create

Terraform will perform the following actions:

  # github_repository_ruleset.failure will be created
  + resource "github_repository_ruleset" "failure" {
      + enforcement = "evaluate"
      + etag        = (known after apply)
      + id          = (known after apply)
      + name        = "failure"
      + node_id     = (known after apply)
      + repository  = <censored>
      + ruleset_id  = (known after apply)
      + target      = "branch"

      + rules {
          + update                        = true
          + update_allows_fetch_and_merge = false

          + required_deployments {
              + required_deployment_environments = []
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
github_repository_ruleset.failure: Creating...
╷
│ Error: Request cancelled
│ 
│   with github_repository_ruleset.failure,
│   on main.tf line 26, in resource "github_repository_ruleset" "failure":
│   26: resource "github_repository_ruleset" "failure" {
│ 
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-github_v5.37.0 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 68 [running]:
github.com/integrations/terraform-provider-github/v5/github.expandRules({0xc0006196a0?, 0x1f5d882?, 0x1d69ac0?}, 0x0)
        github.com/integrations/terraform-provider-github/v5/github/respository_rules_utils.go:242 +0x2105
github.com/integrations/terraform-provider-github/v5/github.resourceGithubRulesetObject(0xc000c22960?, {0x0, 0x0})
        github.com/integrations/terraform-provider-github/v5/github/respository_rules_utils.go:32 +0x2c5
github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryRulesetCreate(0x1d69ac0?, {0x1cc4160?, 0xc000350400})
        github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_ruleset.go:425 +0x56
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc00016ab40, 0xc000c41950, 0xc000c22960, {0x1cc4160, 0xc000350400})
        github.com/hashicorp/[email protected]/helper/schema/resource.go:320 +0x637
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc00006ae00, 0xc0007eb900, 0x1f6909a?, 0xf?)
        github.com/hashicorp/[email protected]/helper/schema/provider.go:294 +0x6a
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000802918, {0xc00096ee70?, 0x10bf886?}, 0xc00096ee70)
        github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:895 +0x7c5
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1f0c0a0?, 0xc000802918}, {0x2325c10, 0xc00064e330}, 0xc00096ee00, 0x0)
        github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3305 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00067a000, {0x232b3b0, 0xc000602680}, 0xc00064aea0, 0xc000573b90, 0x2c46ee0, 0x0)
        google.golang.org/[email protected]/server.go:1337 +0xde7
google.golang.org/grpc.(*Server).handleStream(0xc00067a000, {0x232b3b0, 0xc000602680}, 0xc00064aea0, 0x0)
        google.golang.org/[email protected]/server.go:1714 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/[email protected]/server.go:959 +0x8d
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 31
        google.golang.org/[email protected]/server.go:957 +0x165

Error: The terraform-provider-github_v5.37.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    Status: Triage
    Type: Bug
    on Sep 21, 2023
  2. added
    Status: Up for grabs
    hacktoberfest
    on Sep 21, 2023
  3. moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Activeon Sep 21, 2023
  4. moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Activeon Sep 22, 2023
  5. lewismiddleton commented on Sep 25, 2023

    @lewismiddleton
    Author

    Still getting the same error.

    Stack trace from the terraform-provider-github_v5.38.0 plugin:
    
    panic: interface conversion: interface {} is nil, not map[string]interface {}
    
    goroutine 42 [running]:
    github.com/integrations/terraform-provider-github/v5/github.expandRules({0xc000c9c480?, 0x1f5d882?, 0xc0008fb590?}, 0x0)
            github.com/integrations/terraform-provider-github/v5/github/respository_rules_utils.go:242 +0x2105
    github.com/integrations/terraform-provider-github/v5/github.resourceGithubRulesetObject(0xc0009dadc0?, {0x0, 0x0})
            github.com/integrations/terraform-provider-github/v5/github/respository_rules_utils.go:32 +0x2c5
    github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryRulesetCreate(0x1d69ac0?, {0x1cc4160?, 0xc000732780})
            github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_ruleset.go:426 +0x56
    github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0002dac80, 0xc0009cd310, 0xc0009dadc0, {0x1cc4160, 0xc000732780})
            github.com/hashicorp/[email protected]/helper/schema/resource.go:320 +0x637
    github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc000068e00, 0xc0008fb900, 0x1f6908c?, 0xf?)
            github.com/hashicorp/[email protected]/helper/schema/provider.go:294 +0x6a
    github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000186b48, {0xc00041d260?, 0x10bf886?}, 0xc00041d260)
            github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:895 +0x7c5
    github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1f0c0a0?, 0xc000186b48}, {0x2325cb0, 0xc0009c57a0}, 0xc00041d1f0, 0x0)
            github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3305 +0x169
    google.golang.org/grpc.(*Server).processUnaryRPC(0xc0006cc000, {0x232b450, 0xc0001a5380}, 0xc0009b18c0, 0xc0006c9530, 0x2c46ee0, 0x0)
            google.golang.org/[email protected]/server.go:1337 +0xde7
    google.golang.org/grpc.(*Server).handleStream(0xc0006cc000, {0x232b450, 0xc0001a5380}, 0xc0009b18c0, 0x0)
            google.golang.org/[email protected]/server.go:1714 +0x9e7
    google.golang.org/grpc.(*Server).serveStreams.func1.1()
            google.golang.org/[email protected]/server.go:959 +0x8d
    created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 52
            google.golang.org/[email protected]/server.go:957 +0x165
    
    Error: The terraform-provider-github_v5.38.0 plugin crashed!
    
    This is always indicative of a bug within the plugin. It would be immensely
    helpful if you could report the crash with the plugin's maintainers so that it
    can be fixed. The output above should help diagnose the issue.
    
  6. o-sama commented on Sep 25, 2023

    @o-sama
    Contributor

    That's interesting. I've done the following just now:

    • Upgrade provider to 5.38.0 - Installed integrations/github v5.38.0
    • Tested with the following code:
    rules {
        update = true
    
        required_deployments {
          required_deployment_environments = []
          # Also with the following: required_deployment_environments = ["test"]
        }
      }
    
    • Applied both of the changes above, both worked, here's my plan and apply from the empty list attempt:
    github_repository_ruleset.test: Refreshing state... [id=]
    github_organization_ruleset.test: Refreshing state... [id=]
    
    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_ruleset.test will be updated in-place
      ~ resource "github_repository_ruleset" "test" {
            id          = 
            name        = 
            # (6 unchanged attributes hidden)
    
          ~ rules {
                # (7 unchanged attributes hidden)
    
              ~ required_deployments {
                  ~ required_deployment_environments = [
                      - "test",
                    ]
                }
            }
        }
    
    Plan: 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_ruleset.test: Modifying... [id=]
    github_repository_ruleset.test: Modifications complete after 1s [id=]
    
    Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
    

    Is there anything else you can share that might help in figuring this out? Did the configuration you're trying to apply change since you initially posted the issue?

    Update: @lewismiddleton Looks like using DefaultFunc worked in solving this issue with an existing rule, but when creating a new one it still defaults to nil because of the schema for the block being a pointer. I'll create a PR for this tonight. @nickfloyd Sorry about this, do you mind reopening the issue?

  7. nickfloyd commented on Sep 25, 2023

    @nickfloyd
    Contributor

    @o-sama and @lewismiddleton thank you for the sleuthing here. @o-sama no worries, I missed it too; thank you for the followup! ❤️

  8. lewismiddleton commented on Sep 26, 2023

    @lewismiddleton
    Author

    Update: @lewismiddleton Looks like using DefaultFunc worked in solving this issue with an existing rule, but when creating a new one it still defaults to nil because of the schema for the block being a pointer. I'll create a PR for this tonight. @nickfloyd Sorry about this, do you mind reopening the issue?

    Thanks for figuring this out. You're right I was getting this failure in the context of creating a new repository rule.

  9. o-sama commented on Oct 5, 2023

    @o-sama
    Contributor

    I had to step away for a bit due to some health issues, apologies for the delay with this. I'll try to get it out in the next day or two 🙂

  10. removed
    Status: Triage
    on Oct 20, 2023
  11. kfcampbell commented on Oct 20, 2023

    @kfcampbell
    Contributor

    @o-sama I hope you're feeling better! Thank you for all your hard work on our provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsType: Bughacktoberfest

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions