@@ -43,6 +43,13 @@ func resourceImageVersion() *schema.Resource {
43
43
Type : schema .TypeString ,
44
44
Computed : true ,
45
45
},
46
+ "aliases" : {
47
+ Type : schema .TypeSet ,
48
+ Optional : true ,
49
+ Elem : & schema.Schema {
50
+ Type : schema .TypeString ,
51
+ },
52
+ },
46
53
"base_image" : {
47
54
Type : schema .TypeString ,
48
55
Required : true ,
@@ -142,6 +149,14 @@ func resourceImageVersionCreate(ctx context.Context, d *schema.ResourceData, met
142
149
input .ProgrammingLang = aws .String (v .(string ))
143
150
}
144
151
152
+ if v , ok := d .GetOk ("aliases" ); ok {
153
+ aliases := v .(* schema.Set ).List ()
154
+ input .Aliases = make ([]string , len (aliases ))
155
+ for i , alias := range aliases {
156
+ input .Aliases [i ] = alias .(string )
157
+ }
158
+ }
159
+
145
160
_ , err := conn .CreateImageVersion (ctx , input )
146
161
if err != nil {
147
162
return sdkdiag .AppendErrorf (diags , "creating SageMaker AI Image Version %s: %s" , name , err )
@@ -220,6 +235,30 @@ func resourceImageVersionRead(ctx context.Context, d *schema.ResourceData, meta
220
235
d .Set ("ml_framework" , image .MLFramework )
221
236
d .Set ("programming_lang" , image .ProgrammingLang )
222
237
238
+ // The AWS SDK doesn't have an Aliases field in DescribeImageVersionOutput
239
+ // We need to fetch aliases separately using ListAliases API
240
+ idParts := strings .Split (id , ":" )
241
+ imageName := idParts [0 ]
242
+ versionStr := idParts [1 ]
243
+ versionNum , err := strconv .Atoi (versionStr )
244
+ if err != nil {
245
+ return sdkdiag .AppendErrorf (diags , "invalid version number in resource ID: %s" , d .Id ())
246
+ }
247
+
248
+ aliasesInput := & sagemaker.ListAliasesInput {
249
+ ImageName : aws .String (imageName ),
250
+ Version : aws .Int32 (int32 (versionNum )),
251
+ }
252
+
253
+ aliasesOutput , err := conn .ListAliases (ctx , aliasesInput )
254
+ if err != nil {
255
+ return sdkdiag .AppendErrorf (diags , "listing aliases for SageMaker AI Image Version (%s): %s" , d .Id (), err )
256
+ }
257
+
258
+ if err := d .Set ("aliases" , aliasesOutput .SageMakerImageVersionAliases ); err != nil {
259
+ return sdkdiag .AppendErrorf (diags , "setting aliases: %s" , err )
260
+ }
261
+
223
262
return diags
224
263
}
225
264
@@ -274,6 +313,52 @@ func resourceImageVersionUpdate(ctx context.Context, d *schema.ResourceData, met
274
313
input .ProgrammingLang = aws .String (d .Get ("programming_lang" ).(string ))
275
314
}
276
315
316
+ if d .HasChange ("aliases" ) {
317
+ // For UpdateImageVersion, we need to use AliasesToAdd and AliasesToDelete
318
+ // instead of Aliases directly
319
+ oldAliasesSet , newAliasesSet := d .GetChange ("aliases" )
320
+ oldAliases := oldAliasesSet .(* schema.Set ).List ()
321
+ newAliases := newAliasesSet .(* schema.Set ).List ()
322
+
323
+ // Find aliases to add (in new but not in old)
324
+ var aliasesToAdd []string
325
+ for _ , newAlias := range newAliases {
326
+ found := false
327
+ for _ , oldAlias := range oldAliases {
328
+ if newAlias .(string ) == oldAlias .(string ) {
329
+ found = true
330
+ break
331
+ }
332
+ }
333
+ if ! found {
334
+ aliasesToAdd = append (aliasesToAdd , newAlias .(string ))
335
+ }
336
+ }
337
+
338
+ // Find aliases to delete (in old but not in new)
339
+ var aliasesToDelete []string
340
+ for _ , oldAlias := range oldAliases {
341
+ found := false
342
+ for _ , newAlias := range newAliases {
343
+ if oldAlias .(string ) == newAlias .(string ) {
344
+ found = true
345
+ break
346
+ }
347
+ }
348
+ if ! found {
349
+ aliasesToDelete = append (aliasesToDelete , oldAlias .(string ))
350
+ }
351
+ }
352
+
353
+ if len (aliasesToAdd ) > 0 {
354
+ input .AliasesToAdd = aliasesToAdd
355
+ }
356
+
357
+ if len (aliasesToDelete ) > 0 {
358
+ input .AliasesToDelete = aliasesToDelete
359
+ }
360
+ }
361
+
277
362
if _ , err := conn .UpdateImageVersion (ctx , input ); err != nil {
278
363
return sdkdiag .AppendErrorf (diags , "updating SageMaker AI Image Version (%s): %s" , d .Id (), err )
279
364
}
0 commit comments