@@ -82,9 +82,16 @@ export type WebServerArgs = {
8282 */
8383 size ?: pulumi . Input < Size > ;
8484 /**
85- * The environment variables to pass to a container. Defaults to [].
85+ * The environment variables to pass to a container. Don't use this field for
86+ * sensitive information such as passwords, API keys, etc. For that purpose,
87+ * please use the `secrets` property.
88+ * Defaults to [].
8689 */
8790 environment ?: aws . ecs . KeyValuePair [ ] ;
91+ /**
92+ * The secrets to pass to the container. Defaults to [].
93+ */
94+ secrets ?: aws . ecs . Secret [ ] ;
8895 /**
8996 * Path for the health check request. Defaults to "/healtcheck".
9097 */
@@ -107,6 +114,7 @@ const defaults = {
107114 maxCount : 10 ,
108115 size : 'small' ,
109116 environment : [ ] ,
117+ secrets : [ ] ,
110118 healtCheckPath : '/healtcheck' ,
111119 taskExecutionRoleInlinePolicies : [ ] ,
112120 taskRoleInlinePolicies : [ ] ,
@@ -267,6 +275,21 @@ export class WebServer extends pulumi.ComponentResource {
267275 { parent : this } ,
268276 ) ;
269277
278+ const secretManagerSecretsInlinePolicy = {
279+ name : `${ name } -secret-manager-access` ,
280+ policy : JSON . stringify ( {
281+ Version : '2012-10-17' ,
282+ Statement : [
283+ {
284+ Sid : 'AllowContainerToGetSecretManagerSecrets' ,
285+ Effect : 'Allow' ,
286+ Action : [ 'secretsmanager:GetSecretValue' ] ,
287+ Resource : '*' ,
288+ } ,
289+ ] ,
290+ } ) ,
291+ } ;
292+
270293 const taskExecutionRole = new aws . iam . Role (
271294 `${ name } -ecs-task-exec-role` ,
272295 {
@@ -276,7 +299,10 @@ export class WebServer extends pulumi.ComponentResource {
276299 'arn:aws:iam::aws:policy/CloudWatchFullAccess' ,
277300 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess' ,
278301 ] ,
279- inlinePolicies : argsWithDefaults . taskExecutionRoleInlinePolicies ,
302+ inlinePolicies : [
303+ secretManagerSecretsInlinePolicy ,
304+ ...argsWithDefaults . taskExecutionRoleInlinePolicies ,
305+ ] ,
280306 } ,
281307 { parent : this } ,
282308 ) ;
@@ -344,11 +370,20 @@ export class WebServer extends pulumi.ComponentResource {
344370 argsWithDefaults . image ,
345371 argsWithDefaults . port ,
346372 argsWithDefaults . environment ,
373+ argsWithDefaults . secrets ,
347374 this . logGroup . name ,
348375 awsRegion ,
349376 ] )
350377 . apply (
351- ( [ containerName , image , port , environment , logGroup , region ] ) => {
378+ ( [
379+ containerName ,
380+ image ,
381+ port ,
382+ environment ,
383+ secrets ,
384+ logGroup ,
385+ region ,
386+ ] ) => {
352387 return JSON . stringify ( [
353388 {
354389 readonlyRootFilesystem : false ,
@@ -370,6 +405,7 @@ export class WebServer extends pulumi.ComponentResource {
370405 } ,
371406 } ,
372407 environment,
408+ secrets,
373409 } ,
374410 ] as ContainerDefinition [ ] ) ;
375411 } ,
0 commit comments