Skip to content

[MAINT] Convert legacy Schema Migrations to use StateUpgraders - #3065

Merged
stevehipwell merged 16 commits into
integrations:mainfrom
F-Secure-web:upgrade-state-migrations
Jan 16, 2026
Merged

stevehipwell merged 16 commits into
integrations:mainfrom
F-Secure-web:upgrade-state-migrations

Conversation

@deiga

@deiga deiga commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

Supersedes #3018


Before the change?

  • Schema Migrations used MigrateState which is from 0.11 of the SDK
  • Converted resources:
    • github_actions_organization_secret
    • github_actions_secret
    • github_repository_webhook
    • github_repository

After the change?

  • Schema Migrations use StateUpgraders which is the default since 0.12 of the SDK

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

@github-actions

github-actions Bot commented Jan 7, 2026

Copy link
Copy Markdown

👋 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! 🚀

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we move the migration code into the resource files instead of having it in separate files which makes it significantly harder to reason about?

@stevehipwell stevehipwell added this to the v6.10.0 Release milestone Jan 8, 2026
@stevehipwell stevehipwell added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Jan 8, 2026
@nickfloyd

Copy link
Copy Markdown
Contributor

Could we move the migration code into the resource files instead of having it in separate files which makes it significantly harder to reason about?

We can definitely do that - I'd recommend that we follow up with changing the existing ones as well so that we have a consistent pattern.

@stevehipwell

Copy link
Copy Markdown
Collaborator

@nickfloyd I think this PR is modifying all of the existing ones, so I was meaning for all migrations to be located next to the relevant schemas.

@nickfloyd

Copy link
Copy Markdown
Contributor

@stevehipwell That makes so much more sense... thank you for the clarity.

@deiga

deiga commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator Author

@nickfloyd @stevehipwell I'm honestly not sure about merging the migration files with the resource files

Some of these migration files are very long and since they contain Schemas at specific points in time it could make it confusing to have multiple schema in the same file. Or would we keep the schemas still in separate files and only move the state upgrade functions to the resource files?

@stevehipwell

Copy link
Copy Markdown
Collaborator

What about adding schema files with the same name as the primary files and then adding a schema suffix so they're at least located next to each other? For example github_resource_foo.go & github_resource_foo_schema.go

@nickfloyd

Copy link
Copy Markdown
Contributor

@stevehipwell I'm wondering if this would be a good move for 7.x. I really like the idea of a related grouping so for instance our protocol would be:

github_[resource]_[function].go

So, given something like: branch_protection, like you were sketching out, you'd have:

  • github_branch_protection_migrate.go
  • github_branch_protection_resource.go
  • github_branch_protection_resource_test.go
  • github_branch_protection_data_source.go
  • github_branch_protection_data_source_test.go

Is that what you were thinking? If so I can write up an issue for us to rework all of that.

@deiga
deiga force-pushed the upgrade-state-migrations branch from 6fc64f6 to 710d9b8 Compare January 8, 2026 20:44
@deiga

deiga commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator Author

@stevehipwell Something like this? 710d9b8 (#3065)

@stevehipwell

Copy link
Copy Markdown
Collaborator

@deiga do you mean the code or file paths?

@nickfloyd for v7 I'd suggest aligning to a more idiomatic approach like below. But for now I'd really like to see the migration code moved as it's all being modified.

  • internal/provider/data_repository.go
  • internal/provider/data_repository_schema.go
  • internal/provider/data_repository_test.go
  • internal/provider/repository.go
  • internal/provider/repository_schema.go
  • internal/provider/repository_test.go

@deiga

deiga commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator Author

@stevehipwell Both? Just wanted to double check if this close enough to what you had in mind, before I do the same change for every migration file

@stevehipwell

Copy link
Copy Markdown
Collaborator

@stevehipwell Both? Just wanted to double check if this close enough to what you had in mind, before I do the same change for every migration file

I was on my phone so it was hard to figure out what had changed.

OK, how about github/resource_github_actions_secret_migration.go (& github/resource_github_actions_secret_migration_test.go) with the migration functions and the schemas in the one file? I think this will meet my desire for keeping the code together without adding additional complexity to the main files. Also after thinking it through carefully I realized that once the migration has happened the code is effectively meaningless so should be kept out of the way for general readability.

@deiga
deiga requested a review from stevehipwell January 10, 2026 21:02
@deiga
deiga force-pushed the upgrade-state-migrations branch 2 times, most recently from 04ae654 to c4fd2a4 Compare January 13, 2026 20:05

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The code changes look great, I've just added a comment suggesting a change to the way that the migration function tests are structured.

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@stevehipwell

Copy link
Copy Markdown
Collaborator

@deiga could you please rebase this PR?

Timo Sand added 8 commits January 15, 2026 22:23
…ers` for schema migrations

Signed-off-by: Timo Sand <[email protected]>
…tionWebhook` schema migrations to use StateUpgraders

Signed-off-by: Timo Sand <[email protected]>
Rename migrate_github_actions_organization_secret*.go to
resource_github_actions_organization_secret_migration*.go for
consistent naming with resource files.
Timo Sand added 8 commits January 15, 2026 22:23
Rename migrate_github_branch_protection.go to
resource_github_branch_protection_migration.go for
consistent naming with resource files.
Rename migrate_github_organization_webhook*.go to
resource_github_organization_webhook_migration*.go for
consistent naming with resource files.
Rename migrate_github_repository*.go to
resource_github_repository_migration*.go for
consistent naming with resource files.
Rename migrate_github_repository_webhook*.go to
resource_github_repository_webhook_migration*.go for
consistent naming with resource files.
Migrate resource_github_actions_secret.go from legacy CRUD functions
to Context-aware functions (CreateContext, ReadContext, DeleteContext).

- Add diag import
- Update function signatures to accept context.Context
- Return diag.Diagnostics instead of error
- Use StateContext for importer

Ref: integrations#2996
Migrate resource_github_actions_organization_secret.go from legacy
CRUD to context-aware CRUD functions (CreateContext, ReadContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996
Migrate resource_github_organization_webhook.go from legacy CRUD to
context-aware CRUD functions (CreateContext, ReadContext, UpdateContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996
Migrate resource_github_repository_webhook.go from legacy CRUD to
context-aware CRUD functions (CreateContext, ReadContext, UpdateContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996
@deiga
deiga force-pushed the upgrade-state-migrations branch from c4fd2a4 to 8b6a21f Compare January 15, 2026 20:24
@stevehipwell
stevehipwell merged commit 1dfeffe into integrations:main Jan 16, 2026
JiayangZhou pushed a commit to JiayangZhou/terraform-provider-github that referenced this pull request Apr 16, 2026
…rations#3065)

* Convert `resourceGithubActionsOrganizationSecret` to use `StateUpgraders` for schema migrations

Signed-off-by: Timo Sand <[email protected]>

* Convert `resourceGithubActionsSecret` to use `StateUpgraders` for schema migrations

Signed-off-by: Timo Sand <[email protected]>

* Convert `resourceGithubRepositoryWebhook` and `resourceGithubOrganizationWebhook` schema migrations to use StateUpgraders

Signed-off-by: Timo Sand <[email protected]>

* Convert `resourceGithubRepository` schema migration to use StateUpgraders

Signed-off-by: Timo Sand <[email protected]>

* Restructure github_actions_secret state migration files

Signed-off-by: Timo Sand <[email protected]>

* Rename to new naming scheme `<resource>_migration.go`

Signed-off-by: Timo Sand <[email protected]>

* Mmove migration code to _migration.go file and exxtract tests to _migartion_test.go file

Signed-off-by: Timo Sand <[email protected]>

* refactor(github): rename actions organization secret migration files

Rename migrate_github_actions_organization_secret*.go to
resource_github_actions_organization_secret_migration*.go for
consistent naming with resource files.

* refactor(github): rename branch protection migration file

Rename migrate_github_branch_protection.go to
resource_github_branch_protection_migration.go for
consistent naming with resource files.

* refactor(github): rename organization webhook migration files

Rename migrate_github_organization_webhook*.go to
resource_github_organization_webhook_migration*.go for
consistent naming with resource files.

* refactor(github): rename repository migration files

Rename migrate_github_repository*.go to
resource_github_repository_migration*.go for
consistent naming with resource files.

* refactor(github): rename repository webhook migration files

Rename migrate_github_repository_webhook*.go to
resource_github_repository_webhook_migration*.go for
consistent naming with resource files.

* refactor(github): migrate actions secret to context-aware CRUD

Migrate resource_github_actions_secret.go from legacy CRUD functions
to Context-aware functions (CreateContext, ReadContext, DeleteContext).

- Add diag import
- Update function signatures to accept context.Context
- Return diag.Diagnostics instead of error
- Use StateContext for importer

Ref: integrations#2996

* refactor(actions-org-secret): migrate to context-aware CRUD functions

Migrate resource_github_actions_organization_secret.go from legacy
CRUD to context-aware CRUD functions (CreateContext, ReadContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996

* refactor(org-webhook): migrate to context-aware CRUD functions

Migrate resource_github_organization_webhook.go from legacy CRUD to
context-aware CRUD functions (CreateContext, ReadContext, UpdateContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996

* refactor(repo-webhook): migrate to context-aware CRUD functions

Migrate resource_github_repository_webhook.go from legacy CRUD to
context-aware CRUD functions (CreateContext, ReadContext, UpdateContext,
DeleteContext) per Terraform Plugin SDK v2 best practices.

Ref: integrations#2996

---------

Signed-off-by: Timo Sand <[email protected]>
@deiga
deiga deleted the upgrade-state-migrations branch May 24, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants