-
Notifications
You must be signed in to change notification settings - Fork 961
[BUG] Ensure github_emu_group_mapping behaves correctly if mapping changes upstream
#3118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stevehipwell
merged 25 commits into
integrations:main
from
F-Secure-web:fix-emu-group-mapping-read-issue
Feb 4, 2026
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5cc6da0
Move `toInt` and `toInt64` functions to `util.go`
deiga 4654ca5
`resource_github_emu_group_mapping`) Change `Read` to use `ListExtern…
deiga 1787fb3
`resource_github_emu_group_mapping`: Refactor `Create` to have less u…
deiga a4a8eaf
`emu_group_mapping`: Add `group_name` computed attribute
deiga 8693502
Add matching of team ID into Read
deiga 19dfa51
Split Create and Update to separate functions
deiga 9973292
Update Importer to use new ID pattern
deiga 7858f1a
Add Schema migration for new ID format
deiga cd9220b
Changes `group_id` to `ForceNew`
deiga 1f80b9b
Add skipped test while waiting for `terraform-plugin-testing`
deiga 54cf8dc
Add `CustomizeDiff` function to determine if `team_slug` change needs…
deiga 98276f5
Update docs
deiga eb28a9f
Use `lookupTeamID` instead of `getTeamID`
deiga 22d8455
Move `Create` before `Read`
deiga ff8de82
Replace `deep` package with `go-cmp`
deiga e632207
`ListExternalGroupsForTeamBySlug` does not return a nested `Teams` sl…
deiga 7649872
Replace `go-github-mock` with `githubApiMock`
deiga e1fe75b
Remove unnecessry `matchTeamID` function
deiga 6195269
Address review comments
deiga 0e9d579
Rename state migartion functions
deiga 998aa15
Inline unnecessary function
deiga f8e0147
Use new reusable diffing pattern
deiga 1b4f74e
Address review comments
deiga 343bc7d
Refactor mockResponse builder to accept inputs
deiga 9c3367d
Delete test
deiga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "strconv" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-log/tflog" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| ) | ||
|
|
||
| func resourceGithubEMUGroupMappingV0() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "team_slug": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: "Slug of the GitHub team.", | ||
| }, | ||
| "group_id": { | ||
| Type: schema.TypeInt, | ||
| Required: true, | ||
| Description: "Integer corresponding to the external group ID to be linked.", | ||
| }, | ||
| "etag": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func resourceGithubEMUGroupMappingStateUpgradeV0(ctx context.Context, rawState map[string]any, meta any) (map[string]any, error) { | ||
| orgName := meta.(*Owner).name | ||
| tflog.Trace(ctx, "GitHub EMU Group Mapping State before migration", map[string]any{"state": rawState, "owner": orgName}) | ||
|
|
||
| client := meta.(*Owner).v3client | ||
|
|
||
| teamSlug := rawState["team_slug"].(string) | ||
| // We need to bypass the etag because we need to get the latest group | ||
| ctx = context.WithValue(ctx, ctxEtag, nil) | ||
| groupsList, resp, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, orgName, teamSlug) | ||
| if err != nil { | ||
| if resp != nil && (resp.StatusCode == http.StatusNotFound) { | ||
| // If the Group is not found, remove it from state | ||
| tflog.Info(ctx, "Removing EMU group mapping from state because team no longer exists in GitHub", map[string]any{ | ||
| "resource_id": rawState["id"], | ||
| }) | ||
| return nil, err | ||
| } | ||
| return nil, err | ||
| } | ||
|
|
||
| group := groupsList.Groups[0] | ||
| teamID, err := lookupTeamID(ctx, meta.(*Owner), teamSlug) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| rawState["team_id"] = teamID | ||
| resourceID, err := buildID(strconv.FormatInt(teamID, 10), teamSlug, strconv.FormatInt(group.GetGroupID(), 10)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| rawState["id"] = resourceID | ||
|
|
||
| tflog.Trace(ctx, "GitHub EMU Group Mapping State after migration", map[string]any{"state": rawState}) | ||
| return rawState, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.