Skip to content

Commit

Permalink
fix(ec2): InitFile does not work on Windows (#10450)
Browse files Browse the repository at this point in the history
Fixes #10390.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Sep 21, 2020
1 parent 1a5a024 commit 84b9d5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-ec2/lib/cfn-init-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ export abstract class InitFile extends InitElement {
if (fileOptions.group || fileOptions.owner || fileOptions.mode) {
throw new Error('Owner, group, and mode options not supported for Windows.');
}
return {};
return {
[this.fileName]: { ...contentVars },
};
}

return {
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/cfn-init-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ describe('InitFile', () => {
}).toThrow('Owner, group, and mode options not supported for Windows.');
});

test('file renders properly on Windows', () => {
// GIVEN
const file = ec2.InitFile.fromString('/tmp/foo', 'My content');

// WHEN
const rendered = getElementConfig(file, InitPlatform.WINDOWS);

// THEN
expect(rendered).toEqual({
'/tmp/foo': {
content: 'My content',
encoding: 'plain',
},
});
});

test('symlink throws an error if mode is set incorrectly', () => {
expect(() => {
ec2.InitFile.symlink('/tmp/foo', '/tmp/bar', {
Expand Down

0 comments on commit 84b9d5e

Please sign in to comment.