Skip to content

Commit 0828908

Browse files
Add support for EC2 metadata options input (machulav#246)
Introduces a new 'metadata-options' input in action.yml and updates config.js and aws.js to handle and pass EC2 instance metadata options when creating instances. This allows users to specify advanced metadata settings for their EC2 instances.
1 parent 5ae8cda commit 0828908

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ inputs:
125125
description: >-
126126
EC2 block device type.
127127
required: false
128-
128+
metadata-options:
129+
description: >-
130+
JSON string specifying the metadata options for the EC2 instance.
131+
Example: '{"HttpTokens": "required", "HttpEndpoint": "enabled", "HttpPutResponseHopLimit": 2, "InstanceMetadataTags": "enabled"}'
129132
outputs:
130133
label:
131134
description: >-

src/aws.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async function createEc2InstanceWithParams(imageId, subnetId, securityGroupId, l
7575
IamInstanceProfile: config.input.iamRoleName ? { Name: config.input.iamRoleName } : undefined,
7676
TagSpecifications: config.tagSpecifications,
7777
InstanceMarketOptions: buildMarketOptions(),
78+
MetadataOptions: Object.keys(config.input.metadataOptions).length > 0 ? config.input.metadataOptions : undefined,
7879
};
7980

8081
if (config.input.ec2VolumeSize !== '' || config.input.ec2VolumeType !== '') {

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Config {
2626
ec2VolumeType: core.getInput('ec2-volume-type'),
2727
blockDeviceMappings: JSON.parse(core.getInput('block-device-mappings') || '[]'),
2828
availabilityZonesConfig: core.getInput('availability-zones-config'),
29+
metadataOptions: JSON.parse(core.getInput('metadata-options') || '{}'),
2930
};
3031

3132
// Get the AWS_REGION environment variable

0 commit comments

Comments
 (0)