Skip to content

Add github_code_security_configuration resource - #3542

Open
mushhzz wants to merge 10 commits into
integrations:mainfrom
mushhzz:add-code-security-configuration-resource
Open

Add github_code_security_configuration resource#3542
mushhzz wants to merge 10 commits into
integrations:mainfrom
mushhzz:add-code-security-configuration-resource

Conversation

@mushhzz

@mushhzz mushhzz commented Jul 15, 2026

Copy link
Copy Markdown

Resolves #2412


Before the change?

After the change?

  • Adds a single github_code_security_configuration resource that manages a configuration at either the organization level (default, using the provider owner) or the enterprise level (set enterprise_slug, which is ForceNew).
  • Covers every configuration attribute exposed by go-github v89, including the nested option blocks (dependency_graph_autosubmit_action_options, code_scanning_default_setup_options, code_scanning_options, secret_scanning_delegated_bypass_options with reviewers) and the newer dependabot_delegated_alert_dismissal and secret_scanning_extended_metadata settings.
  • Manages default_for_new_repos through the /defaults endpoints, with full read-back so drift is detected.
  • Context-aware CRUD, tflog, 404 handling on read and delete, ConfigStateChecks/plancheck-based tests with t.Parallel(), tfplugindocs docs and examples.

Design notes

Verification

  • go build, go vet, gofmt, golangci-lint (default config: 0 issues; strict config on new code: 0 issues in these files) and tfplugindocs validate are clean.
  • Acceptance tests cover org create → update → import, nested option blocks create → update → empty plan, default_for_new_repos set → change → remove → empty plan, and enterprise create → update → import.
  • Note: the latest revision has not yet been run against a GHAS-enabled org; earlier revisions were. Maintainer CI approval would be appreciated.

Pull request checklist

  • Schema migrations have been created if needed (not needed — new resource)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

  • Yes
  • No

@github-actions

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

Adds org- and enterprise-level management of GitHub Code Security
Configurations, including /defaults and /attach sub-endpoints.
Covers org-level create/update and import, plus enterprise-level
create/update/import using the <enterprise_slug>:<id> import format.
@mushhzz
mushhzz force-pushed the add-code-security-configuration-resource branch from 0eb3a73 to 232b4cd Compare July 15, 2026 04:43
@deiga
deiga requested a review from Copilot July 15, 2026 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

These provider review instructions are being used. Adds organization- and enterprise-level GitHub Code Security Configuration management. Blocking reliability and test issues are noted inline.

Changes:

  • Adds full CRUD and import support.
  • Registers the resource and adds acceptance tests.
  • Adds examples and generated documentation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
github/resource_github_code_security_configuration.go Implements schema, CRUD, import, defaults, and attachment behavior.
github/resource_github_code_security_configuration_test.go Adds organization and enterprise acceptance tests.
github/provider.go Registers the resource.
examples/resources/code_security_configuration/example_1.tf Demonstrates typical usage.
templates/resources/code_security_configuration.md.tmpl Defines documentation content.
docs/resources/code_security_configuration.md Adds generated resource documentation.

Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration_test.go Outdated
Comment thread github/resource_github_code_security_configuration_test.go Outdated
Comment thread github/resource_github_code_security_configuration_test.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
Comment thread github/resource_github_code_security_configuration.go Outdated
- Migrate CRUD callbacks to CreateContext/ReadContext/UpdateContext/DeleteContext
  returning diag.Diagnostics, threading the provided context through all API calls
- Replace stdlib log with structured tflog logging per DECISIONS.md
- Treat 404 on delete as successful deletion
- Replace go-github attach helpers with a nil-safe direct request path
- Set computed fields directly in Create instead of chaining Read
- Convert acceptance tests to ConfigStateChecks/statecheck per DECISIONS.md
- Add acceptance coverage for default_for_new_repos (set/change/remove +
  empty-plan check) and attach_scope (set + idempotent plan)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mushhzz

mushhzz commented Jul 15, 2026

Copy link
Copy Markdown
Author

Thanks for the Copilot review — really useful pass! I've addressed the feedback in 5e15072:

  • Context-aware CRUD: migrated to CreateContext/ReadContext/UpdateContext/DeleteContext with diag.Diagnostics, threading the provided context through all API calls. Create now sets its computed fields directly rather than chaining Read.
  • Logging: all stdlib log calls replaced with structured tflog per DECISIONS.md.
  • Delete: a 404 is now treated as already-deleted, so terraform destroy succeeds if the configuration was removed out-of-band.
  • Attach path: swapped the go-github v89 attach helpers (which can nil-deref on transport failures) for a nil-safe direct client.NewRequest/client.Do call; that helper issue looks worth an upstream go-github report.
  • Tests: all steps converted to ConfigStateChecks + statecheck/knownvalue/plancheck per DECISIONS.md, and added new acceptance coverage for default_for_new_repos (set → change → remove → empty plan) and attach_scope (set + idempotent re-plan).

The one comment I didn't action is the new(d.Get(...).(string)) one — Go 1.26 (declared in go.mod) allows new(expr), and the repo already uses this idiom elsewhere; details in the thread reply.

make test, go vet, gofmt, and go build are all clean after the changes. Happy to adjust anything further!

@deiga deiga added Type: Feature New feature or request New resource Status: Triage This is being looked at and prioritized labels Jul 23, 2026
@deiga

deiga commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

What makes this PR better than #3284 or #2664?

- Add every configuration attribute exposed by go-github v89: code_security,
  secret_protection, dependency_graph_autosubmit_action (+ options),
  dependabot_delegated_alert_dismissal, code_scanning_default_setup_options,
  code_scanning_delegated_alert_dismissal, code_scanning_options,
  secret_scanning_delegated_bypass (+ reviewers), secret_scanning_generic_secrets,
  secret_scanning_delegated_alert_dismissal, secret_scanning_extended_metadata.
- New attributes are Optional-only: sent to the API and tracked in state only
  when configured, so GitHub keeps its own defaults for unmanaged settings.
- Defer delegated bypass reviewers to a follow-up update on create; the API
  rejects them on the initial create request.
- Remove attach_scope. It is a write-only action that cannot be read back and
  does not fit a declarative resource; attachment can be its own resource later.
- Tests: t.Parallel() on the root and every subtest, Terraform-formatted HCL,
  pre-rendered configs, and a new subtest covering the nested option blocks
  with create -> update -> empty-plan steps.
- Use comma-ok type assertions throughout so the strict lint config passes.
- Docs: document the two attribute categories and option blocks, add
  declarative import examples, regenerate with tfplugindocs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L2T8JF8uT6KcCtGKjnbvju
@mushhzz

mushhzz commented Sep 3, 2026

Copy link
Copy Markdown
Author

@deiga fair question, and the honest answer changed today because I pushed a revision (f78a022) to close the gaps.

#2664 is stale: go-github v66, legacy CRUD, no docs, no response since January.

Versus #3284, this PR now:

I removed attach_scope from this revision; it was write-only and did not fit a declarative resource.

I'm not attached to which PR lands. If you'd prefer #3284's two-resource shape, I'm happy to close this and contribute the missing attributes and default_for_new_repos handling there. If the single-resource shape is preferred, this one is ready for review and just needs CI approved on the fork.

@casey-robertson-paypal

Copy link
Copy Markdown

@mushhzz it will sound self-serving but the current PR I'm involved with has far more maintainer feedback #3284 - I think we should focus on getting this one over the line?

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

Labels

New resource Status: Triage This is being looked at and prioritized Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Code Security Configuration

5 participants