Skip to content

feat: Add github_organization_security_configuration and github_enterprise_security_configuration resource#3143

Closed
sprioriello wants to merge 2 commits intointegrations:mainfrom
sprioriello:feat/organization-security-configuration
Closed

feat: Add github_organization_security_configuration and github_enterprise_security_configuration resource#3143
sprioriello wants to merge 2 commits intointegrations:mainfrom
sprioriello:feat/organization-security-configuration

Conversation

@sprioriello
Copy link

@sprioriello sprioriello commented Jan 30, 2026

This commit adds a new resource github_organization_security_configuration & github_enterprise_security_configuration to manage Code Security Configurations at the organization & enterprise level respectively. It includes:

  • Resource implementation.
  • Acceptance tests.
  • Documentation.
  • Provider registration.

Resolves #2412


Before the change?

  • Resource not available.

After the change?

  • Implement code security configuration resource on organizational level.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • 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?

Please see our docs on breaking changes to help!

  • Yes
  • No

Tests

==> Running acceptance tests on branch: 🌿 feat/organization-security-configuration 🌿...
TF_ACC=1 CGO_ENABLED=0 go test ./github/... -v -run '^TestAcc' -run='TestAccGithubOrganizationSecurityConfiguration'  -timeout 120m -count=1
=== RUN   TestAccGithubOrganizationSecurityConfiguration
=== RUN   TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_without_error
=== RUN   TestAccGithubOrganizationSecurityConfiguration/updates_organization_security_configuration_without_error
=== RUN   TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_with_options
=== RUN   TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_with_minimal_config
--- PASS: TestAccGithubOrganizationSecurityConfiguration (48.02s)
    --- PASS: TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_without_error (12.08s)
    --- PASS: TestAccGithubOrganizationSecurityConfiguration/updates_organization_security_configuration_without_error (15.99s)
    --- PASS: TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_with_options (10.98s)
    --- PASS: TestAccGithubOrganizationSecurityConfiguration/creates_organization_security_configuration_with_minimal_config (8.96s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     48.317s
==> Running acceptance tests on branch: 🌿 feat/organization-security-configuration 🌿...
TF_ACC=1 CGO_ENABLED=0 go test ./github/... -v -run '^TestAcc' -run='TestAccGithubEnterpriseSecurityConfiguration'  -timeout 120m -count=1
=== RUN   TestAccGithubEnterpriseSecurityConfiguration
=== RUN   TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_without_error
=== RUN   TestAccGithubEnterpriseSecurityConfiguration/updates_enterprise_security_configuration_without_error
=== RUN   TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_with_options
=== RUN   TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_with_minimal_config
--- PASS: TestAccGithubEnterpriseSecurityConfiguration (46.68s)
    --- PASS: TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_without_error (10.97s)
    --- PASS: TestAccGithubEnterpriseSecurityConfiguration/updates_enterprise_security_configuration_without_error (15.31s)
    --- PASS: TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_with_options (11.52s)
    --- PASS: TestAccGithubEnterpriseSecurityConfiguration/creates_enterprise_security_configuration_with_minimal_config (8.88s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     46.923s

@github-actions github-actions bot added the Type: Feature New feature or request label Jan 30, 2026
@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@sprioriello sprioriello changed the title feat: Add github_organization_security_configuration resource [FEAT]: Add github_organization_security_configuration resource Jan 30, 2026
@sprioriello sprioriello changed the title [FEAT]: Add github_organization_security_configuration resource feat: Add github_organization_security_configuration resource Jan 30, 2026
@sprioriello sprioriello changed the title feat: Add github_organization_security_configuration resource feat: Add github_organization_security_configuration and github_enterprise_security_configuration resource Feb 1, 2026
@sprioriello
Copy link
Author

@deiga ready for review

@sprioriello sprioriello requested a review from deiga February 3, 2026 10:55
@sprioriello
Copy link
Author

sprioriello commented Feb 9, 2026

@nickfloyd @deiga is there anything else you need to help get this through. We are keen on this feature :)

@deiga
Copy link
Collaborator

deiga commented Feb 13, 2026

@sprioriello You'll need to at least rebase this 😬

Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Please apply applicable changes also to the Org resource, I don't want to repeat myself there

@sprioriello
Copy link
Author

Acceptance Test Results

All 8 acceptance tests pass (4 organization + 4 enterprise):

--- PASS: TestAccGithubOrganizationSecurityConfiguration (56.53s)
    --- PASS: .../creates_organization_security_configuration_without_error (13.28s)
    --- PASS: .../updates_organization_security_configuration_without_error (19.47s)
    --- PASS: .../creates_organization_security_configuration_with_options (12.26s)
    --- PASS: .../creates_organization_security_configuration_with_minimal_config (11.51s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     56.936s

--- PASS: TestAccGithubEnterpriseSecurityConfiguration (54.89s)
    --- PASS: .../creates_enterprise_security_configuration_without_error (13.85s)
    --- PASS: .../updates_enterprise_security_configuration_without_error (17.04s)
    --- PASS: .../creates_enterprise_security_configuration_with_options (12.63s)
    --- PASS: .../creates_enterprise_security_configuration_with_minimal_config (11.38s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     55.324s

@sprioriello sprioriello force-pushed the feat/organization-security-configuration branch from 47e7766 to 33ae057 Compare February 16, 2026 10:42
@sprioriello
Copy link
Author

sprioriello commented Feb 16, 2026

@sprioriello You'll need to at least rebase this 😬

@deiga rebased and addressed comments as requested. Thank you

@sprioriello sprioriello requested a review from deiga February 17, 2026 11:27
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Please review all the comments we've left before and check that they are actually done. Many seem to have somehow gotten reverted

@sprioriello sprioriello force-pushed the feat/organization-security-configuration branch from a14d69e to 6fec8f5 Compare February 18, 2026 10:49
@sprioriello sprioriello requested a review from deiga February 18, 2026 11:00
@sprioriello sprioriello force-pushed the feat/organization-security-configuration branch 2 times, most recently from cdb1e63 to 6d3c919 Compare February 18, 2026 11:12
@sprioriello
Copy link
Author

@deiga @stevehipwell ready for review

Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Before asking for review after this round, please make sure that any discussions from previous rounds have been addressed.

And see to it that comments are addressed across all changes, not just where we left them.

enterprise := d.Get("enterprise_slug").(string)
name := d.Get("name").(string)

tflog.Debug(ctx, fmt.Sprintf("Creating enterprise code security configuration: %s/%s", enterprise, name), map[string]any{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't use fmt.Sprintf inside tflog. calls

Suggested change
tflog.Debug(ctx, fmt.Sprintf("Creating enterprise code security configuration: %s/%s", enterprise, name), map[string]any{
tflog.Debug(ctx, "Creating enterprise code security configuration", map[string]any{

"id": configuration.GetID(),
})

return resourceGithubEnterpriseSecurityConfigurationRead(ctx, d, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You've managed to revert to the problematic behaviour, which we already asked you to remove.

Comment on lines +283 to +286
enterprise, idStr, err := parseID2(d.Id())
if err != nil {
return diag.FromErr(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace parsing fields from the ID with d.Get calls when we should have the information in State already

Comment on lines +406 to +414
enterprise, idStr, err := parseID2(d.Id())
if err != nil {
return diag.FromErr(err)
}

id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
return diag.FromErr(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace with fetching data from State

"id": id,
})

return resourceGithubEnterpriseSecurityConfigurationRead(ctx, d, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to populate any Computed fields inside Update

Suggested change
return resourceGithubEnterpriseSecurityConfigurationRead(ctx, d, meta)
return nil

Comment on lines +444 to +452
enterprise, idStr, err := parseID2(d.Id())
if err != nil {
return diag.FromErr(err)
}

id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
return diag.FromErr(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

No parsing fields from ID

Comment on lines +491 to +495
id, err := buildID(enterpriseSlug, configID)
if err != nil {
return nil, err
}
d.SetId(id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is already the ID value, setting it again seems unnecessary

return diag.FromErr(err)
}

id, err := buildID(enterprise, strconv.FormatInt(configuration.GetID(), 10))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the configuration ID is needed for API calls, we should store it separately in the State as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add tests for these util functions

sprioriello added a commit to sprioriello/terraform-provider-github that referenced this pull request Mar 16, 2026
…prise_security_configuration resources

Adds resources to manage Code Security Configurations at the organization
and enterprise level. Addresses all reviewer feedback from PR integrations#3143:

- Fixed go-github import to v82 (matching go.mod)
- Removed fmt.Sprintf from all tflog calls, using structured fields only
- Create/Update set Computed fields directly and return nil (no Read call)
- Added configuration_id Computed field for numeric API ID in State
- Update/Delete use d.Get() from State instead of parsing composite ID
- Simplified Import function, removed redundant buildID/SetId
- Extracted setState helpers to DRY up Computed field population
- Added unit tests for all util flatten functions

Resolves integrations#2412
@sprioriello sprioriello force-pushed the feat/organization-security-configuration branch from 8c53a8b to 616802e Compare March 16, 2026 10:30
sprioriello and others added 2 commits March 16, 2026 23:03
…prise_security_configuration resources

Adds two new resources to manage Code Security Configurations:

- github_organization_security_configuration: manages code security
  configurations at the organization level
- github_enterprise_security_configuration: manages code security
  configurations at the enterprise level

Both resources include:
- Full CRUD operations using GitHub's Code Security Configurations API
- Composite IDs (org/enterprise + config ID)
- 404-tolerant delete
- tflog structured logging throughout
- All optional fields use GetOk to avoid sending unset values
- Custom import support
- Shared expandCodeSecurityConfigurationCommon helper to avoid duplication
- All 4 delegated fields on enterprise: code_scanning_delegated_alert_dismissal,
  secret_scanning_delegated_bypass, secret_scanning_delegated_bypass_options,
  secret_scanning_delegated_alert_dismissal
- Fix flattenCodeScanningDefaultSetupOptions runner_type empty string drift

Acceptance tests (5 per resource):
- creates without error (with import verification)
- updates without error
- creates with nested options (runner, autosubmit)
- creates with minimal config (with import verification)
- creates with delegated bypass options

Documentation added for both resources.

Resolves integrations#2412

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Make `description` Optional+Computed on both org and enterprise security
  configuration resources (the API does not require it)
- Add unit tests for `flattenCodeScanningDefaultSetupOptions` covering the
  empty RunnerType edge case that caused spurious plan diffs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sprioriello sprioriello force-pushed the feat/organization-security-configuration branch from 616802e to ee7c8d5 Compare March 16, 2026 21:18
@deiga deiga closed this Mar 16, 2026
@deiga
Copy link
Collaborator

deiga commented Mar 16, 2026

Something went wrong with your changes. Please open a new PR

@sprioriello
Copy link
Author

New PR: #3284

sprioriello added a commit to sprioriello/terraform-provider-github that referenced this pull request Mar 16, 2026
- Remove fmt.Sprintf from all tflog calls; use static messages with
  structured fields map for dynamic data (28 instances fixed)
- Add configuration_id Computed field to both resources so the numeric
  config ID is stored separately in state
- Update/Delete now read enterprise_slug and configuration_id from
  state via d.Get() instead of parsing the composite ID
- Update enterprise docs with configuration_id attribute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sprioriello added a commit to sprioriello/terraform-provider-github that referenced this pull request Mar 17, 2026
- Remove fmt.Sprintf from all tflog calls; use static messages with
  structured fields map for dynamic data (28 instances fixed)
- Add configuration_id Computed field to both resources so the numeric
  config ID is stored separately in state
- Update/Delete now read enterprise_slug and configuration_id from
  state via d.Get() instead of parsing the composite ID
- Update enterprise docs with configuration_id attribute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sprioriello added a commit to sprioriello/terraform-provider-github that referenced this pull request Mar 17, 2026
…view feedback

- Upgrade go-github imports from v83 to v84 across all feature files
- Remove secret_scanning_delegated_bypass from enterprise resource (org-only API)
- Fix reviewer_type enum casing to TEAM/ROLE to match GitHub API
- Wire expandSecretScanningDelegatedBypass into org Create/Update
- Remove hardcoded "disabled" defaults for code_security/secret_protection
- Use GetOk for description field in expand (consistency with other Optional fields)
- Add unit tests for all flatten utility functions (deiga requested)
- Add missing ImportState steps to acceptance tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Code Security Configuration

2 participants