Skip to content

Commit

Permalink
fix(codepipeline-actions): CodeDeployEcsDeployAction does not properl…
Browse files Browse the repository at this point in the history
…y handle unnamed Artifacts (#9147)

If the Artifacts passed to the CodeDeployEcsDeployAction were unnamed,
the action incorrectly passed undefined to the configuration populated by them.
Change to using Lazy values to fix this problem.

Fixes #8971

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 committed Jul 27, 2020
1 parent eee8689 commit ac612c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
@@ -1,7 +1,7 @@
import * as codedeploy from '@aws-cdk/aws-codedeploy';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as iam from '@aws-cdk/aws-iam';
import { Construct } from '@aws-cdk/core';
import { Construct, Lazy } from '@aws-cdk/core';
import { Action } from '../action';

/**
Expand Down Expand Up @@ -177,17 +177,19 @@ export class CodeDeployEcsDeployAction extends Action {
// the Action's Role needs to read from the Bucket to get artifacts
options.bucket.grantRead(options.role);

const taskDefinitionTemplateArtifact = determineTaskDefinitionArtifact(this.actionProps);
const appSpecTemplateArtifact = determineAppSpecArtifact(this.actionProps);
const actionConfig: codepipeline.ActionConfig = {
configuration: {
ApplicationName: this.actionProps.deploymentGroup.application.applicationName,
DeploymentGroupName: this.actionProps.deploymentGroup.deploymentGroupName,

TaskDefinitionTemplateArtifact: determineTaskDefinitionArtifact(this.actionProps).artifactName,
TaskDefinitionTemplateArtifact: Lazy.stringValue({ produce: () => taskDefinitionTemplateArtifact.artifactName }),
TaskDefinitionTemplatePath: this.actionProps.taskDefinitionTemplateFile
? this.actionProps.taskDefinitionTemplateFile.fileName
: 'taskdef.json',

AppSpecTemplateArtifact: determineAppSpecArtifact(this.actionProps).artifactName,
AppSpecTemplateArtifact: Lazy.stringValue({ produce: () => appSpecTemplateArtifact.artifactName }),
AppSpecTemplatePath: this.actionProps.appSpecTemplateFile
? this.actionProps.appSpecTemplateFile.fileName
: 'appspec.yaml',
Expand All @@ -197,7 +199,7 @@ export class CodeDeployEcsDeployAction extends Action {
if (this.actionProps.containerImageInputs) {
for (let i = 1; i <= this.actionProps.containerImageInputs.length; i++) {
const imageInput = this.actionProps.containerImageInputs[i - 1];
actionConfig.configuration[`Image${i}ArtifactName`] = imageInput.input.artifactName;
actionConfig.configuration[`Image${i}ArtifactName`] = Lazy.stringValue({ produce: () => imageInput.input.artifactName });
actionConfig.configuration[`Image${i}ContainerName`] = imageInput.taskDefinitionPlaceholder
? imageInput.taskDefinitionPlaceholder
: 'IMAGE';
Expand Down
Expand Up @@ -146,13 +146,13 @@ export = {
'defaults task definition placeholder string'(test: Test) {
const stack = new cdk.Stack();
const deploymentGroup = addEcsDeploymentGroup(stack);
const artifact1 = new codepipeline.Artifact('Artifact1');
const artifact2 = new codepipeline.Artifact('Artifact2');
const artifact1 = new codepipeline.Artifact();
const artifact2 = new codepipeline.Artifact();
addCodeDeployECSCodePipeline(stack, {
actionName: 'DeployToECS',
deploymentGroup,
taskDefinitionTemplateFile: new codepipeline.ArtifactPath(artifact1, 'task-definition.json'),
appSpecTemplateFile: new codepipeline.ArtifactPath(artifact2, 'appspec-test.yaml'),
taskDefinitionTemplateFile: artifact1.atPath('task-definition.json'),
appSpecTemplateFile: artifact2.atPath('appspec-test.yaml'),
containerImageInputs: [
{
input: artifact1,
Expand All @@ -172,21 +172,21 @@ export = {
Configuration: {
ApplicationName: 'MyApplication',
DeploymentGroupName: 'MyDeploymentGroup',
TaskDefinitionTemplateArtifact: 'Artifact1',
AppSpecTemplateArtifact: 'Artifact2',
TaskDefinitionTemplateArtifact: 'Artifact_Source_GitHub',
AppSpecTemplateArtifact: 'Artifact_Source_GitHub2',
TaskDefinitionTemplatePath: 'task-definition.json',
AppSpecTemplatePath: 'appspec-test.yaml',
Image1ArtifactName: 'Artifact1',
Image1ArtifactName: 'Artifact_Source_GitHub',
Image1ContainerName: 'IMAGE',
Image2ArtifactName: 'Artifact2',
Image2ArtifactName: 'Artifact_Source_GitHub2',
Image2ContainerName: 'IMAGE',
},
InputArtifacts: [
{
Name: 'Artifact1',
Name: 'Artifact_Source_GitHub',
},
{
Name: 'Artifact2',
Name: 'Artifact_Source_GitHub2',
},
],
},
Expand Down

0 comments on commit ac612c6

Please sign in to comment.