Skip to content

Commit

Permalink
fix(codebuild): incorrect SSM Parameter ARN in Project's IAM permissi…
Browse files Browse the repository at this point in the history
…ons (#11917)

(CodeBuild) Build fails after introducing environmentVariables with type BuildEnvironmentVariableType.PARAMETER_STORE.

Fixes #9980 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
markusl authored Dec 8, 2020
1 parent ae2e9c1 commit 7a09c18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,16 @@ export class Project extends ProjectBase {

const resources = Object.values(props.environmentVariables)
.filter(envVariable => envVariable.type === BuildEnvironmentVariableType.PARAMETER_STORE)
.map(envVariable =>
// If the parameter name starts with / the resource name is not separated with a double '/'
// arn:aws:ssm:region:1111111111:parameter/PARAM_NAME
(envVariable.value as string).startsWith('/')
? (envVariable.value as string).substr(1)
: envVariable.value)
.map(envVariable => Stack.of(this).formatArn({
service: 'ssm',
resource: 'parameter',
sep: ':',
resourceName: envVariable.value,
resourceName: envVariable,
}));

if (resources.length === 0) {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ export = {
},
'ENV_VAR2': {
type: codebuild.BuildEnvironmentVariableType.PARAMETER_STORE,
value: '/params/param2',
value: 'params/param2',
},
},
});
Expand All @@ -823,7 +823,7 @@ export = {
{
Ref: 'AWS::AccountId',
},
':parameter:/params/param1',
':parameter/params/param1',
],
],
},
Expand All @@ -843,7 +843,7 @@ export = {
{
Ref: 'AWS::AccountId',
},
':parameter:/params/param2',
':parameter/params/param2',
],
],
}],
Expand Down

0 comments on commit 7a09c18

Please sign in to comment.