@@ -63,6 +63,77 @@ func resourceGithubEMUGroupMapping() *schema.Resource {
6363 }
6464}
6565
66+ func resourceGithubEMUGroupMappingCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
67+ resourceID := d .Id ()
68+ tflog .Trace (ctx , "Creating EMU group mapping" , map [string ]any {
69+ "resource_id" : resourceID ,
70+ })
71+
72+ err := checkOrganization (meta )
73+ if err != nil {
74+ return diag .FromErr (err )
75+ }
76+ client := meta .(* Owner ).v3client
77+ orgName := meta .(* Owner ).name
78+ tflog .SetField (ctx , "org_name" , orgName )
79+
80+ teamSlug := d .Get ("team_slug" ).(string )
81+ tflog .SetField (ctx , "team_slug" , teamSlug )
82+
83+ groupID := toInt64 (d .Get ("group_id" ))
84+ tflog .SetField (ctx , "group_id" , groupID )
85+ eg := & github.ExternalGroup {
86+ GroupID : github .Ptr (groupID ),
87+ }
88+
89+ tflog .Debug (ctx , "Connecting external group to team via GitHub API" )
90+
91+ group , resp , err := client .Teams .UpdateConnectedExternalGroup (ctx , orgName , teamSlug , eg )
92+ if err != nil {
93+ return diag .FromErr (err )
94+ }
95+
96+ tflog .Debug (ctx , "Successfully updated connected external group" )
97+
98+ teamID , err := matchTeamID (ctx , meta , teamSlug , group .Teams )
99+ if err != nil {
100+ return diag .FromErr (err )
101+ }
102+
103+ err = d .Set ("team_id" , teamID )
104+ if err != nil {
105+ return diag .FromErr (err )
106+ }
107+
108+ newResourceID , err := buildID (strconv .FormatInt (teamID , 10 ), teamSlug , strconv .FormatInt (groupID , 10 ))
109+ if err != nil {
110+ return diag .FromErr (err )
111+ }
112+
113+ tflog .Trace (ctx , "Setting resource ID" , map [string ]any {
114+ "resource_id" : newResourceID ,
115+ })
116+ d .SetId (newResourceID )
117+
118+ etag := resp .Header .Get ("ETag" )
119+ tflog .Trace (ctx , "Setting state attribute: etag" , map [string ]any {
120+ "etag" : etag ,
121+ })
122+ if err = d .Set ("etag" , etag ); err != nil {
123+ return diag .FromErr (err )
124+ }
125+
126+ if err = d .Set ("group_name" , group .GetGroupName ()); err != nil {
127+ return diag .FromErr (err )
128+ }
129+
130+ tflog .Trace (ctx , "Resource created or updated successfully" , map [string ]any {
131+ "resource_id" : d .Id (),
132+ })
133+
134+ return nil
135+ }
136+
66137func resourceGithubEMUGroupMappingRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
67138 tflog .Trace (ctx , "Reading EMU group mapping" , map [string ]any {
68139 "resource_id" : d .Id (),
@@ -151,77 +222,6 @@ func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceDa
151222 return nil
152223}
153224
154- func resourceGithubEMUGroupMappingCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
155- resourceID := d .Id ()
156- tflog .Trace (ctx , "Creating EMU group mapping" , map [string ]any {
157- "resource_id" : resourceID ,
158- })
159-
160- err := checkOrganization (meta )
161- if err != nil {
162- return diag .FromErr (err )
163- }
164- client := meta .(* Owner ).v3client
165- orgName := meta .(* Owner ).name
166- tflog .SetField (ctx , "org_name" , orgName )
167-
168- teamSlug := d .Get ("team_slug" ).(string )
169- tflog .SetField (ctx , "team_slug" , teamSlug )
170-
171- groupID := toInt64 (d .Get ("group_id" ))
172- tflog .SetField (ctx , "group_id" , groupID )
173- eg := & github.ExternalGroup {
174- GroupID : github .Ptr (groupID ),
175- }
176-
177- tflog .Debug (ctx , "Connecting external group to team via GitHub API" )
178-
179- group , resp , err := client .Teams .UpdateConnectedExternalGroup (ctx , orgName , teamSlug , eg )
180- if err != nil {
181- return diag .FromErr (err )
182- }
183-
184- tflog .Debug (ctx , "Successfully updated connected external group" )
185-
186- teamID , err := matchTeamID (ctx , meta , teamSlug , group .Teams )
187- if err != nil {
188- return diag .FromErr (err )
189- }
190-
191- err = d .Set ("team_id" , teamID )
192- if err != nil {
193- return diag .FromErr (err )
194- }
195-
196- newResourceID , err := buildID (strconv .FormatInt (teamID , 10 ), teamSlug , strconv .FormatInt (groupID , 10 ))
197- if err != nil {
198- return diag .FromErr (err )
199- }
200-
201- tflog .Trace (ctx , "Setting resource ID" , map [string ]any {
202- "resource_id" : newResourceID ,
203- })
204- d .SetId (newResourceID )
205-
206- etag := resp .Header .Get ("ETag" )
207- tflog .Trace (ctx , "Setting state attribute: etag" , map [string ]any {
208- "etag" : etag ,
209- })
210- if err = d .Set ("etag" , etag ); err != nil {
211- return diag .FromErr (err )
212- }
213-
214- if err = d .Set ("group_name" , group .GetGroupName ()); err != nil {
215- return diag .FromErr (err )
216- }
217-
218- tflog .Trace (ctx , "Resource created or updated successfully" , map [string ]any {
219- "resource_id" : d .Id (),
220- })
221-
222- return nil
223- }
224-
225225func resourceGithubEMUGroupMappingUpdate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
226226 resourceID := d .Id ()
227227 tflog .Trace (ctx , "Updating EMU group mapping" , map [string ]any {
0 commit comments