Skip to content

[BUG]: organization_ruleset - interface conversion error when required_status_checks omits optional fields #2776

@maxafinder

Description

@maxafinder

Expected Behavior

When creating a github_organization_ruleset or github_repository_ruleset with a required_status_checks block that only specifies required_check, the provider should apply default values for the optional fields do_not_enforce_on_create and strict_required_status_checks_policy.

Example configuration:

rules {
  required_status_checks {
    required_check {
      context = "example-check"
    }
  }
}

Expected outcome:

  • The ruleset should be created successfully.
  • do_not_enforce_on_create should default to false.
  • strict_required_status_checks_policy should default to false.

The provider should handle optional fields, either by:

  1. Providing defaults so the fields are always present in the configuration map, or
  2. Checking if the fields exist before performing type assertions and using appropriate defaults when they're absent.

Actual Behavior

The provider panics with the error:

panic: interface conversion: interface {} is nil, not bool

goroutine 47 [running]:
github.com/integrations/terraform-provider-github/v6/github.expandRules(...)
github.com/integrations/terraform-provider-github/v6/github/respository_rules_utils.go:343

When do_not_enforce_on_create or strict_required_status_checks_policy are not specified in the required_status_checks block, the code at line 343 attempts to perform a type assertion on a nil value (non-existent map key), causing the provider to crash and the resource creation to fail completely.

Terraform Version

Terraform v1.13.3
on darwin_arm64

Provider plugin: v6.6.0

Affected Resource(s)

  • github_repository_ruleset
  • github_organization_ruleset

Terraform Configuration Files

resource "github_organization_ruleset" "require_pr_title_validation" {
  name        = "require-signed-commits"
  target      = "branch"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["~ALL"]
      exclude = []
    }
    repository_name {
      include = ["*"]
      exclude = []
    }
  }

  rules {
    required_status_checks {
      required_check {
        context = "validate-pr-title"
      }
    }
  }
}

Steps to Reproduce

terraform apply

Debug Output

Panic Output

Stack trace from the terraform-provider-github_v6.6.0 plugin:

panic: interface conversion: interface {} is nil, not bool

goroutine 47 [running]:
github.com/integrations/terraform-provider-github/v6/github.expandRules({0xc00056c3c0?, 0xf1b546?, 0x0?}, 0x1)
	github.com/integrations/terraform-provider-github/v6/github/respository_rules_utils.go:343 +0x2a54
github.com/integrations/terraform-provider-github/v6/github.resourceGithubRulesetObject(0xc00041b580, {0xc000012c20, 0xb})
	github.com/integrations/terraform-provider-github/v6/github/respository_rules_utils.go:33 +0x2c5
github.com/integrations/terraform-provider-github/v6/github.resourceGithubOrganizationRulesetCreate(0xc00041b580, {0xd352c0, 0xc000252b80})
	github.com/integrations/terraform-provider-github/v6/github/resource_github_organization_ruleset.go:511 +0x5d
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x107d470?, {0x107d470?, 0xc00048ec60?}, 0xd?, {0xd352c0?, 0xc000252b80?})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:794 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003a0c40, {0x107d470, 0xc00048ec60}, 0xc0004f0680, 0xc00041b400, {0xd352c0, 0xc000252b80})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00036e5b8, {0x107d470?, 0xc00048eba0?}, 0xc000021810)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000267860, {0x107d470?, 0xc00048e1e0?}, 0xc0000f4850)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xee16c0, 0xc000267860}, {0x107d470, 0xc00048e1e0}, 0xc00041a900, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00017f000, {0x107d470, 0xc00048e150}, {0x1081d68, 0xc000002180}, 0xc00042fb00, 0xc00046c7b0, 0x1719558, 0x0)
	google.golang.org/grpc@v1.63.2/server.go:1369 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc00017f000, {0x1081d68, 0xc000002180}, 0xc00042fb00)
	google.golang.org/grpc@v1.63.2/server.go:1780 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 24
	google.golang.org/grpc@v1.63.2/server.go:1030 +0x125

Error: The terraform-provider-github_v6.6.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    ✅ Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions