@@ -361,6 +361,8 @@ export class ContainerDefinition extends cdk.Construct {
361
361
362
362
private readonly imageConfig : ContainerImageConfig ;
363
363
364
+ private readonly secrets ?: CfnTaskDefinition . SecretProperty [ ] ;
365
+
364
366
/**
365
367
* Constructs a new instance of the ContainerDefinition class.
366
368
*/
@@ -382,6 +384,20 @@ export class ContainerDefinition extends cdk.Construct {
382
384
this . logDriverConfig = props . logging . bind ( this , this ) ;
383
385
}
384
386
props . taskDefinition . _linkContainer ( this ) ;
387
+
388
+ if ( props . secrets ) {
389
+ this . secrets = [ ] ;
390
+ for ( const [ name , secret ] of Object . entries ( props . secrets ) ) {
391
+ if ( this . taskDefinition . isFargateCompatible && secret . hasField ) {
392
+ throw new Error ( `Cannot specify secret JSON field for a task using the FARGATE launch type: '${ name } ' in container '${ this . node . id } '` ) ;
393
+ }
394
+ secret . grantRead ( this . taskDefinition . obtainExecutionRole ( ) ) ;
395
+ this . secrets . push ( {
396
+ name,
397
+ valueFrom : secret . arn ,
398
+ } ) ;
399
+ }
400
+ }
385
401
}
386
402
387
403
/**
@@ -564,35 +580,14 @@ export class ContainerDefinition extends cdk.Construct {
564
580
workingDirectory : this . props . workingDirectory ,
565
581
logConfiguration : this . logDriverConfig ,
566
582
environment : this . props . environment && renderKV ( this . props . environment , 'name' , 'value' ) ,
567
- secrets : this . renderSecrets ( ) ,
583
+ secrets : this . secrets ,
568
584
extraHosts : this . props . extraHosts && renderKV ( this . props . extraHosts , 'hostname' , 'ipAddress' ) ,
569
585
healthCheck : this . props . healthCheck && renderHealthCheck ( this . props . healthCheck ) ,
570
586
links : cdk . Lazy . listValue ( { produce : ( ) => this . links } , { omitEmpty : true } ) ,
571
587
linuxParameters : this . linuxParameters && this . linuxParameters . renderLinuxParameters ( ) ,
572
588
resourceRequirements : ( this . props . gpuCount !== undefined ) ? renderResourceRequirements ( this . props . gpuCount ) : undefined ,
573
589
} ;
574
590
}
575
-
576
- private renderSecrets ( ) : CfnTaskDefinition . SecretProperty [ ] | undefined {
577
- if ( ! this . props . secrets ) {
578
- return undefined ;
579
- }
580
-
581
- const secrets : CfnTaskDefinition . SecretProperty [ ] = [ ] ;
582
-
583
- for ( const [ k , v ] of Object . entries ( this . props . secrets ) ) {
584
- if ( this . taskDefinition . isFargateCompatible && v . hasField ) {
585
- throw new Error ( `Cannot specify secret JSON field for a task using the FARGATE launch type: '${ k } ' in container '${ this . node . id } '` ) ;
586
- }
587
- v . grantRead ( this . taskDefinition . obtainExecutionRole ( ) ) ;
588
- secrets . push ( {
589
- name : k ,
590
- valueFrom : v . arn ,
591
- } ) ;
592
- }
593
-
594
- return secrets ;
595
- }
596
591
}
597
592
598
593
/**
0 commit comments