Skip to content

Commit

Permalink
chore(ec2): update InitFile.fromObject tests with non-string data typ…
Browse files Browse the repository at this point in the history
…es (#21394)

Issue link: #14100

I tested described functionality and could not reproduce it with the latest version of cdk (commit 715158f).

Decided to update appropriate unit and integration tests for ec2.InitFile.fromObject to cover int, bool, number types as well as string.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
arewa authored Jul 30, 2022
1 parent 715158f commit 0ea8a1c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
6 changes: 6 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 @@ -264,6 +264,9 @@ describe('InitFile', () => {
const content = {
version: '1234',
secretsFile: '/tmp/secrets',
maxThreads: 15,
isEnabled: true,
floatNumber: 23.18,
};
const file = ec2.InitFile.fromObject('/tmp/foo', content);

Expand All @@ -276,6 +279,9 @@ describe('InitFile', () => {
content: {
version: '1234',
secretsFile: '/tmp/secrets',
maxThreads: 15,
isEnabled: true,
floatNumber: 23.18,
},
owner: 'root',
group: 'root',
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"17.0.0"}
{"version":"20.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "17.0.0",
"version": "20.0.0",
"files": {
"f8a1af398dac2fad92eeea4fb7620be1c4f504e23e3bfcd859fbb5744187930b": {
"source": {
Expand All @@ -14,15 +14,15 @@
}
}
},
"6d00e54104832c562dc7d659fc2df0a5a8d096d46d6d3ab8bf79c3fb5759a13e": {
"e62e8b1ed4fd967ec674edc5d686a08042183fd4164dd2f026c1e4f56835a6f3": {
"source": {
"path": "integ-init.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "6d00e54104832c562dc7d659fc2df0a5a8d096d46d6d3ab8bf79c3fb5759a13e.json",
"objectKey": "e62e8b1ed4fd967ec674edc5d686a08042183fd4164dd2f026c1e4f56835a6f3.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
]
}
},
"Instance255F352651ad64873f230a4d2": {
"Instance255F35265555f8bd64fe3316f": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
Expand Down Expand Up @@ -555,23 +555,23 @@
"Fn::Join": [
"",
[
"#!/bin/bash\n# fingerprint: 8ef54c03058b2a11\n(\n set +e\n /opt/aws/bin/cfn-init -v --region ",
"#!/bin/bash\n# fingerprint: 8deb3fafcf9d33f0\n(\n set +e\n /opt/aws/bin/cfn-init -v --region ",
{
"Ref": "AWS::Region"
},
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource Instance255F352651ad64873f230a4d2 -c default\n /opt/aws/bin/cfn-signal -e $? --region ",
" --resource Instance255F35265555f8bd64fe3316f -c default\n /opt/aws/bin/cfn-signal -e $? --region ",
{
"Ref": "AWS::Region"
},
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource Instance255F352651ad64873f230a4d2\n cat /var/log/cfn-init.log >&2\n)"
" --resource Instance255F35265555f8bd64fe3316f\n cat /var/log/cfn-init.log >&2\n)"
]
]
}
Expand Down Expand Up @@ -668,15 +668,18 @@
}
},
"files": {
"/tmp/file2": {
"/tmp/file2.json": {
"content": {
"stackId": {
"Ref": "AWS::StackId"
},
"stackName": "integ-init",
"region": {
"Ref": "AWS::Region"
}
},
"intProperty": 18,
"boolProperty": true,
"numProperty": 58.23
},
"mode": "000644",
"owner": "root",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "17.0.0",
"version": "20.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
Expand Down Expand Up @@ -194,7 +194,7 @@
"/integ-init/Instance2/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "Instance255F352651ad64873f230a4d2"
"data": "Instance255F35265555f8bd64fe3316f"
}
],
"/integ-init/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.0.9"
"version": "10.1.58"
}
},
"integ-init": {
Expand Down Expand Up @@ -900,23 +900,23 @@
"Fn::Join": [
"",
[
"#!/bin/bash\n# fingerprint: 8ef54c03058b2a11\n(\n set +e\n /opt/aws/bin/cfn-init -v --region ",
"#!/bin/bash\n# fingerprint: 8deb3fafcf9d33f0\n(\n set +e\n /opt/aws/bin/cfn-init -v --region ",
{
"Ref": "AWS::Region"
},
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource Instance255F352651ad64873f230a4d2 -c default\n /opt/aws/bin/cfn-signal -e $? --region ",
" --resource Instance255F35265555f8bd64fe3316f -c default\n /opt/aws/bin/cfn-signal -e $? --region ",
{
"Ref": "AWS::Region"
},
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource Instance255F352651ad64873f230a4d2\n cat /var/log/cfn-init.log >&2\n)"
" --resource Instance255F35265555f8bd64fe3316f\n cat /var/log/cfn-init.log >&2\n)"
]
]
}
Expand Down Expand Up @@ -1011,13 +1011,13 @@
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.0.9"
"version": "10.1.58"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.0.9"
"version": "10.1.58"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-ec2/test/integ.instance-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ new ec2.Instance(stack, 'Instance2', {
ec2.InitPackage.yum('git'),
]),
config: new ec2.InitConfig([
ec2.InitFile.fromObject('/tmp/file2', {
ec2.InitFile.fromObject('/tmp/file2.json', {
stackId: stack.stackId,
stackName: stack.stackName,
region: stack.region,
intProperty: 18,
boolProperty: true,
numProperty: 58.23,
}),
ec2.InitGroup.fromName('group1'),
ec2.InitGroup.fromName('group2', 42),
Expand Down

0 comments on commit 0ea8a1c

Please sign in to comment.