@@ -17,6 +17,7 @@ import (
17
17
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
18
18
"github.com/hashicorp/terraform-provider-aws/internal/conns"
19
19
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
20
+ "github.com/hashicorp/terraform-provider-aws/internal/flex"
20
21
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
21
22
"github.com/hashicorp/terraform-provider-aws/internal/verify"
22
23
"github.com/hashicorp/terraform-provider-aws/names"
@@ -84,6 +85,42 @@ func ResourceImagePipeline() *schema.Resource {
84
85
ValidateFunc : validation .StringMatch (regexp .MustCompile (`^arn:aws[^:]*:imagebuilder:[^:]+:(?:\d{12}|aws):image-recipe/[a-z0-9-_]+/\d+\.\d+\.\d+$` ), "valid image recipe ARN must be provided" ),
85
86
ExactlyOneOf : []string {"container_recipe_arn" , "image_recipe_arn" },
86
87
},
88
+ "image_scanning_configuration" : {
89
+ Type : schema .TypeList ,
90
+ Optional : true ,
91
+ Computed : true ,
92
+ MaxItems : 1 ,
93
+ Elem : & schema.Resource {
94
+ Schema : map [string ]* schema.Schema {
95
+ "ecr_configuration" : {
96
+ Type : schema .TypeList ,
97
+ Optional : true ,
98
+ Computed : true ,
99
+ MaxItems : 1 ,
100
+ Elem : & schema.Resource {
101
+ Schema : map [string ]* schema.Schema {
102
+ "container_tags" : {
103
+ Type : schema .TypeSet ,
104
+ Optional : true ,
105
+ Elem : & schema.Schema {
106
+ Type : schema .TypeString ,
107
+ },
108
+ },
109
+ "repository_name" : {
110
+ Type : schema .TypeString ,
111
+ Optional : true ,
112
+ },
113
+ },
114
+ },
115
+ },
116
+ "image_scanning_enabled" : {
117
+ Type : schema .TypeBool ,
118
+ Optional : true ,
119
+ Default : false ,
120
+ },
121
+ },
122
+ },
123
+ },
87
124
"image_tests_configuration" : {
88
125
Type : schema .TypeList ,
89
126
Optional : true ,
@@ -188,6 +225,10 @@ func resourceImagePipelineCreate(ctx context.Context, d *schema.ResourceData, me
188
225
input .ImageRecipeArn = aws .String (v .(string ))
189
226
}
190
227
228
+ if v , ok := d .GetOk ("image_scanning_configuration" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
229
+ input .ImageScanningConfiguration = expandImageScanningConfiguration (v .([]interface {})[0 ].(map [string ]interface {}))
230
+ }
231
+
191
232
if v , ok := d .GetOk ("image_tests_configuration" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
192
233
input .ImageTestsConfiguration = expandImageTestConfiguration (v .([]interface {})[0 ].(map [string ]interface {}))
193
234
}
@@ -259,23 +300,24 @@ func resourceImagePipelineRead(ctx context.Context, d *schema.ResourceData, meta
259
300
d .Set ("distribution_configuration_arn" , imagePipeline .DistributionConfigurationArn )
260
301
d .Set ("enhanced_image_metadata_enabled" , imagePipeline .EnhancedImageMetadataEnabled )
261
302
d .Set ("image_recipe_arn" , imagePipeline .ImageRecipeArn )
262
-
303
+ if imagePipeline .ImageScanningConfiguration != nil {
304
+ d .Set ("image_scanning_configuration" , []interface {}{flattenImageScanningConfiguration (imagePipeline .ImageScanningConfiguration )})
305
+ } else {
306
+ d .Set ("image_scanning_configuration" , nil )
307
+ }
263
308
if imagePipeline .ImageTestsConfiguration != nil {
264
309
d .Set ("image_tests_configuration" , []interface {}{flattenImageTestsConfiguration (imagePipeline .ImageTestsConfiguration )})
265
310
} else {
266
311
d .Set ("image_tests_configuration" , nil )
267
312
}
268
-
269
313
d .Set ("infrastructure_configuration_arn" , imagePipeline .InfrastructureConfigurationArn )
270
314
d .Set ("name" , imagePipeline .Name )
271
315
d .Set ("platform" , imagePipeline .Platform )
272
-
273
316
if imagePipeline .Schedule != nil {
274
317
d .Set ("schedule" , []interface {}{flattenSchedule (imagePipeline .Schedule )})
275
318
} else {
276
319
d .Set ("schedule" , nil )
277
320
}
278
-
279
321
d .Set ("status" , imagePipeline .Status )
280
322
281
323
setTagsOut (ctx , imagePipeline .Tags )
@@ -291,6 +333,7 @@ func resourceImagePipelineUpdate(ctx context.Context, d *schema.ResourceData, me
291
333
"description" ,
292
334
"distribution_configuration_arn" ,
293
335
"enhanced_image_metadata_enabled" ,
336
+ "image_scanning_configuration" ,
294
337
"image_tests_configuration" ,
295
338
"infrastructure_configuration_arn" ,
296
339
"schedule" ,
@@ -318,6 +361,10 @@ func resourceImagePipelineUpdate(ctx context.Context, d *schema.ResourceData, me
318
361
input .ImageRecipeArn = aws .String (v .(string ))
319
362
}
320
363
364
+ if v , ok := d .GetOk ("image_scanning_configuration" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
365
+ input .ImageScanningConfiguration = expandImageScanningConfiguration (v .([]interface {})[0 ].(map [string ]interface {}))
366
+ }
367
+
321
368
if v , ok := d .GetOk ("image_tests_configuration" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
322
369
input .ImageTestsConfiguration = expandImageTestConfiguration (v .([]interface {})[0 ].(map [string ]interface {}))
323
370
}
@@ -365,6 +412,42 @@ func resourceImagePipelineDelete(ctx context.Context, d *schema.ResourceData, me
365
412
return diags
366
413
}
367
414
415
+ func expandImageScanningConfiguration (tfMap map [string ]interface {}) * imagebuilder.ImageScanningConfiguration {
416
+ if tfMap == nil {
417
+ return nil
418
+ }
419
+
420
+ apiObject := & imagebuilder.ImageScanningConfiguration {}
421
+
422
+ if v , ok := tfMap ["image_scanning_enabled" ].(bool ); ok {
423
+ apiObject .ImageScanningEnabled = aws .Bool (v )
424
+ }
425
+
426
+ if v , ok := tfMap ["ecr_configuration" ].([]interface {}); ok && len (v ) > 0 && v [0 ] != nil {
427
+ apiObject .EcrConfiguration = expandECRConfiguration (v [0 ].(map [string ]interface {}))
428
+ }
429
+
430
+ return apiObject
431
+ }
432
+
433
+ func expandECRConfiguration (tfMap map [string ]interface {}) * imagebuilder.EcrConfiguration {
434
+ if tfMap == nil {
435
+ return nil
436
+ }
437
+
438
+ apiObject := & imagebuilder.EcrConfiguration {}
439
+
440
+ if v , ok := tfMap ["container_tags" ].(* schema.Set ); ok {
441
+ apiObject .ContainerTags = flex .ExpandStringSet (v )
442
+ }
443
+
444
+ if v , ok := tfMap ["repository_name" ].(string ); ok {
445
+ apiObject .RepositoryName = aws .String (v )
446
+ }
447
+
448
+ return apiObject
449
+ }
450
+
368
451
func expandImageTestConfiguration (tfMap map [string ]interface {}) * imagebuilder.ImageTestsConfiguration {
369
452
if tfMap == nil {
370
453
return nil
@@ -405,6 +488,42 @@ func expandPipelineSchedule(tfMap map[string]interface{}) *imagebuilder.Schedule
405
488
return apiObject
406
489
}
407
490
491
+ func flattenImageScanningConfiguration (apiObject * imagebuilder.ImageScanningConfiguration ) map [string ]interface {} {
492
+ if apiObject == nil {
493
+ return nil
494
+ }
495
+
496
+ tfMap := map [string ]interface {}{}
497
+
498
+ if v := apiObject .ImageScanningEnabled ; v != nil {
499
+ tfMap ["image_scanning_enabled" ] = aws .BoolValue (v )
500
+ }
501
+
502
+ if v := apiObject .EcrConfiguration ; v != nil {
503
+ tfMap ["ecr_configuration" ] = []interface {}{flattenECRConfiguration (v )}
504
+ }
505
+
506
+ return tfMap
507
+ }
508
+
509
+ func flattenECRConfiguration (apiObject * imagebuilder.EcrConfiguration ) map [string ]interface {} {
510
+ if apiObject == nil {
511
+ return nil
512
+ }
513
+
514
+ tfMap := map [string ]interface {}{}
515
+
516
+ if v := apiObject .RepositoryName ; v != nil {
517
+ tfMap ["repository_name" ] = aws .StringValue (v )
518
+ }
519
+
520
+ if v := apiObject .ContainerTags ; v != nil {
521
+ tfMap ["container_tags" ] = aws .StringValueSlice (v )
522
+ }
523
+
524
+ return tfMap
525
+ }
526
+
408
527
func flattenImageTestsConfiguration (apiObject * imagebuilder.ImageTestsConfiguration ) map [string ]interface {} {
409
528
if apiObject == nil {
410
529
return nil
0 commit comments