@@ -54,6 +54,13 @@ func resourceImageVersion() *schema.Resource {
54
54
Type : schema .TypeString ,
55
55
Computed : true ,
56
56
},
57
+ "aliases" : {
58
+ Type : schema .TypeSet ,
59
+ Optional : true ,
60
+ Elem : & schema.Schema {
61
+ Type : schema .TypeString ,
62
+ },
63
+ },
57
64
"base_image" : {
58
65
Type : schema .TypeString ,
59
66
Required : true ,
@@ -119,7 +126,7 @@ func resourceImageVersionCreate(ctx context.Context, d *schema.ResourceData, met
119
126
conn := meta .(* conns.AWSClient ).SageMakerClient (ctx )
120
127
121
128
name := d .Get ("image_name" ).(string )
122
- input := sagemaker.CreateImageVersionInput {
129
+ input := & sagemaker.CreateImageVersionInput {
123
130
ImageName : aws .String (name ),
124
131
BaseImage : aws .String (d .Get ("base_image" ).(string )),
125
132
ClientToken : aws .String (id .UniqueId ()),
@@ -153,7 +160,15 @@ func resourceImageVersionCreate(ctx context.Context, d *schema.ResourceData, met
153
160
input .ProgrammingLang = aws .String (v .(string ))
154
161
}
155
162
156
- if _ , err := conn .CreateImageVersion (ctx , & input ); err != nil {
163
+ if v , ok := d .GetOk ("aliases" ); ok {
164
+ aliases := v .(* schema.Set ).List ()
165
+ input .Aliases = make ([]string , len (aliases ))
166
+ for i , alias := range aliases {
167
+ input .Aliases [i ] = alias .(string )
168
+ }
169
+ }
170
+
171
+ if _ , err := conn .CreateImageVersion (ctx , input ); err != nil {
157
172
return sdkdiag .AppendErrorf (diags , "creating SageMaker AI Image Version %s: %s" , name , err )
158
173
}
159
174
@@ -208,6 +223,34 @@ func resourceImageVersionRead(ctx context.Context, d *schema.ResourceData, meta
208
223
d .Set ("ml_framework" , image .MLFramework )
209
224
d .Set ("programming_lang" , image .ProgrammingLang )
210
225
226
+ // The AWS SDK doesn't have an Aliases field in DescribeImageVersionOutput
227
+ // We need to fetch aliases separately using ListAliases API
228
+ idParts , err := flex .ExpandResourceId (d .Id (), imageVersionResourcePartCount , false )
229
+ if err != nil {
230
+ return sdkdiag .AppendErrorf (diags , "invalid resource ID format: %s" , d .Id ())
231
+ }
232
+
233
+ imageName := idParts [0 ]
234
+ versionStr := idParts [1 ]
235
+ versionNum , err := strconv .Atoi (versionStr )
236
+ if err != nil {
237
+ return sdkdiag .AppendErrorf (diags , "invalid version number in resource ID: %s" , d .Id ())
238
+ }
239
+
240
+ aliasesInput := & sagemaker.ListAliasesInput {
241
+ ImageName : aws .String (imageName ),
242
+ Version : aws .Int32 (int32 (versionNum )),
243
+ }
244
+
245
+ aliasesOutput , err := conn .ListAliases (ctx , aliasesInput )
246
+ if err != nil {
247
+ return sdkdiag .AppendErrorf (diags , "listing aliases for SageMaker AI Image Version (%s): %s" , d .Id (), err )
248
+ }
249
+
250
+ if err := d .Set ("aliases" , aliasesOutput .SageMakerImageVersionAliases ); err != nil {
251
+ return sdkdiag .AppendErrorf (diags , "setting aliases: %s" , err )
252
+ }
253
+
211
254
return diags
212
255
}
213
256
@@ -218,7 +261,7 @@ func resourceImageVersionUpdate(ctx context.Context, d *schema.ResourceData, met
218
261
name := d .Get ("image_name" ).(string )
219
262
version := d .Get (names .AttrVersion ).(int )
220
263
221
- input := sagemaker.UpdateImageVersionInput {
264
+ input := & sagemaker.UpdateImageVersionInput {
222
265
ImageName : aws .String (name ),
223
266
Version : aws .Int32 (int32 (version )),
224
267
}
@@ -251,7 +294,53 @@ func resourceImageVersionUpdate(ctx context.Context, d *schema.ResourceData, met
251
294
input .ProgrammingLang = aws .String (d .Get ("programming_lang" ).(string ))
252
295
}
253
296
254
- if _ , err := conn .UpdateImageVersion (ctx , & input ); err != nil {
297
+ if d .HasChange ("aliases" ) {
298
+ // For UpdateImageVersion, we need to use AliasesToAdd and AliasesToDelete
299
+ // instead of Aliases directly
300
+ oldAliasesSet , newAliasesSet := d .GetChange ("aliases" )
301
+ oldAliases := oldAliasesSet .(* schema.Set ).List ()
302
+ newAliases := newAliasesSet .(* schema.Set ).List ()
303
+
304
+ // Find aliases to add (in new but not in old)
305
+ var aliasesToAdd []string
306
+ for _ , newAlias := range newAliases {
307
+ found := false
308
+ for _ , oldAlias := range oldAliases {
309
+ if newAlias .(string ) == oldAlias .(string ) {
310
+ found = true
311
+ break
312
+ }
313
+ }
314
+ if ! found {
315
+ aliasesToAdd = append (aliasesToAdd , newAlias .(string ))
316
+ }
317
+ }
318
+
319
+ // Find aliases to delete (in old but not in new)
320
+ var aliasesToDelete []string
321
+ for _ , oldAlias := range oldAliases {
322
+ found := false
323
+ for _ , newAlias := range newAliases {
324
+ if oldAlias .(string ) == newAlias .(string ) {
325
+ found = true
326
+ break
327
+ }
328
+ }
329
+ if ! found {
330
+ aliasesToDelete = append (aliasesToDelete , oldAlias .(string ))
331
+ }
332
+ }
333
+
334
+ if len (aliasesToAdd ) > 0 {
335
+ input .AliasesToAdd = aliasesToAdd
336
+ }
337
+
338
+ if len (aliasesToDelete ) > 0 {
339
+ input .AliasesToDelete = aliasesToDelete
340
+ }
341
+ }
342
+
343
+ if _ , err := conn .UpdateImageVersion (ctx , input ); err != nil {
255
344
return sdkdiag .AppendErrorf (diags , "updating SageMaker AI Image Version (%s): %s" , d .Id (), err )
256
345
}
257
346
@@ -353,7 +442,7 @@ func expandImageVersionResourceID(id string) (string, int, error) {
353
442
name := parts [0 ]
354
443
version , err := strconv .Atoi (parts [1 ])
355
444
if err != nil {
356
- return name , version , err
445
+ return name , 0 , err
357
446
}
358
447
359
448
return name , version , nil
0 commit comments