88 "github.com/google/go-github/v82/github"
99 "github.com/hashicorp/terraform-plugin-log/tflog"
1010 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1211 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1312)
1413
@@ -21,10 +20,8 @@ func resourceGithubEMUGroupMapping() *schema.Resource {
2120 Importer : & schema.ResourceImporter {
2221 StateContext : resourceGithubEMUGroupMappingImport ,
2322 },
24- CustomizeDiff : customdiff .All (
25- customdiff .ForceNewIf ("team_slug" , hasNewTeamID ),
26- ),
27- Description : "Manages the mapping of an external group to a GitHub team." ,
23+ CustomizeDiff : diffTeam ,
24+ Description : "Manages the mapping of an external group to a GitHub team." ,
2825 Schema : map [string ]* schema.Schema {
2926 "team_id" : {
3027 Type : schema .TypeString ,
@@ -361,45 +358,3 @@ func resourceGithubEMUGroupMappingImport(ctx context.Context, d *schema.Resource
361358
362359 return []* schema.ResourceData {d }, nil
363360}
364-
365- func hasNewTeamID (ctx context.Context , diff * schema.ResourceDiff , meta any ) bool {
366- // Skip for new resources - no existing team_id to compare against
367- if diff .Id () == "" {
368- return false
369- }
370-
371- // Only check when team_slug changes
372- if ! diff .HasChange ("team_slug" ) {
373- return false
374- }
375-
376- // Get old team_id from state
377- oldTeamID := toInt64 (diff .Get ("team_id" ))
378- if oldTeamID == 0 {
379- return false
380- }
381-
382- // Resolve new team_slug to team ID via API
383- oldTeamSlug , newTeamSlug := diff .GetChange ("team_slug" )
384- newTeamID , err := lookupTeamID (ctx , meta .(* Owner ), newTeamSlug .(string ))
385- if err != nil {
386- // If team doesn't exist or API fails, skip ForceNew check and let Read handle it
387- tflog .Debug (ctx , "Unable to resolve new team_slug to team ID, skipping ForceNew check" , map [string ]any {
388- "new_team_slug" : newTeamSlug ,
389- "error" : err .Error (),
390- })
391- return false
392- }
393-
394- if newTeamID != oldTeamID {
395- tflog .Debug (ctx , "Team ID changed, forcing new resource" , map [string ]any {
396- "old_team_id" : oldTeamID ,
397- "new_team_id" : newTeamID ,
398- "new_team_slug" : newTeamSlug ,
399- "old_team_slug" : oldTeamSlug ,
400- })
401- return true
402- }
403-
404- return false
405- }
0 commit comments