ec2_instance_tags doesn't work
Closed this issue ยท 3 comments
Issue: Need to add some custom tags for cost management and the custom tags are not passed to AWS. Neither showing on the EC2 instance, nor showing on the CloudTrail event. Also didn't see any error message on GHA logs.
Expected Behavior: Should be able to see my custom tags on the CloudTrail Event and on the EC2 instance. If there is any error about tagging, log it in GHA.
Github Actions Job defination
uses: NextChapterSoftware/ec2-action-builder@v1
with:
......
ec2_instance_ttl: 120 # Optional (default is 60 minutes)
ec2_spot_instance_strategy: BestEffort # Other options are: SpotOnly, BestEffort, MaxPerformance
ec2_instance_tags: >
[
{"Key": "Name", "Value": "${{github.event.repository.name}}:gha-runner:${{ github.run_id }}"}, # not necessarily to replace the default "Name"
{"Key": "Scope", "Value": "xxx"}, # this is more important
{"Key": "Contract", "Value": "${{github.event.repository.name}}"}, # this is more important
]
Github Actions Job metadata
> Run NextChapterSoftware/ec2-action-builder@v1
with:
......
ec2_instance_ttl: 120
ec2_spot_instance_strategy: BestEffort
ec2_instance_tags: [
{"Key": "Name", "Value": "<repo-name>:gha-runner:9604898059"}, # not necessarily to replace the default "Name"
{"Key": "Scope", "Value": "xxx"}, # this is more important
{"Key": "Contract", "Value": "<repo-name>"}, # this is more important
]
AWS CloudTrail - RunInstance Event
"tagSpecificationSet": {
"items": [
{
"resourceType": "instance",
"tags": [
{
"key": "Name",
"value": "<repo-name>-9604898059"
},
{
"key": "github_ref",
"value": "refs/heads/main"
},
{
"key": "owner",
"value": "EC2_ACTION_BUILDER"
},
{
"key": "github_job_id",
"value": "9604898059"
},
{
"key": "github_repo",
"value": "<repo-name>"
}
]
}
]
I did dive in to the source code for an hour, but I'm not very good at JS, I wasn't able to visually find any logical issues or find a hack for myself.... Not sure if I configured something wrong on the GHA job? Please let me know ๐
Potential place of bug:
Hi,
Thanks for reporting this. I'll take a look and see what's going with the tags and get back to you.
TLDR Fix: Use the latest version of this action
This is a documentation bug. The tag problem was fixed in this commit 3160fa3c1c75dff72afb6a97a2322a21194a4d47
but we forgot to update the docs to point to a newer release. Also please make sure the tag is a pure JSON string. It cannot contain comments or otherwise the job will fail. It should be fine with value interpolation as long as the final result is a valid JSON.
I merged this PR to update the docs. #19
Thanks for getting back quickly!
Update: Tested with the fix, it's working, thanks for the update again!