GorillaStack / auto-tag

Automatically tag AWS resources on creation, for cost assignment
GNU General Public License v3.0
463 stars 159 forks source link

Supply multiple custom tags as parameters #93

Closed vcach closed 2 years ago

vcach commented 3 years ago

Trying to supply multiple custom tags as parameters to --custom tags but still didnt find the correct way to do it, I always get a "parse error" at the moment of deployment with the script. The example in the readme suggest to use:

{
  "AutoTag_ManagedBy": "Site Reliability Engineering",
  "AutoTag_UserIdentityType": "$event.userIdentity.type",
  "AutoTag_UserName": "$event.userIdentity.userName",
  "AutoTag_ClientInfo": "SourceIP: $event.sourceIPAddress, UserAgent: $event.userAgent",
  "AutoTag_Ec2_ImageId": "$event.responseElements.instancesSet.items.0.imageId"
}

and also says to use a Json document, does this mean to save this on a Json file and use it as a parameter for --custom tags ? Tried to do this and even when the deployment worked fine, later the tags didnt apply to new resources, found in the logs some entries like "SyntaxError: Unexpected token a in JSON at position 1" which refers to getCustomTags in the Lambda

Can you plz give an example on how to provide multiple custom tags as parameters? The readme shows how to do this in the examples but with only one custom tag:

./deploy_autotag.sh -r us-west-2 -s3bu my-autotag-bucket create \
--custom-tags '{"AutoTag_ManagedBy": "Site Reliability Engineering"}'

Would be really helpful for new users of the tool. Thanks!

rayjanoka commented 3 years ago

Hi, This should work.

./deploy_autotag.sh -r us-west-2 -s3bu my-autotag-bucket create \
--custom-tags '{"AutoTag_ManagedBy": "Site Reliability Engineering", "AutoTag_Test": "Test123"}'

Let me know if you get an error running that.

rayjanoka commented 3 years ago

Also, we found out there is an issue with the comma in the value on this line in the example:

"AutoTag_ClientInfo": "SourceIP: $event.sourceIPAddress, UserAgent: $event.userAgent",

Try with a dash instead

"AutoTag_ClientInfo": "SourceIP: $event.sourceIPAddress - UserAgent: $event.userAgent",
vcach commented 3 years ago

Hi Ray

Tried with this:

./deploy_autotag.sh -r us-east-1 -s3bu bucket-name --release-version latest create \
--custom-tags '{"AutoTag_ManagedBy": "Ops Team", "AutoTag_Env": "Dev"}'

And Im getting a parse error:

Initializing AutoTag release version 0.5.3
Creating the Main CloudFormation Stack...
parse error: Invalid numeric literal at line 28, column 51
rayjanoka commented 3 years ago

I've reverted a change, please pull the latest code and try again. Thanks!

ecout commented 3 years ago

I ran into this too about a month ago. I decided to use the direct CF approach instead of the script because of it. Wouldn't know if the changes made because of it affect it. Tried CAT, ECHO, $(), etc in a calling script to no avail. Something to do with bash not parsing the json file properly. IMHO real fix should be for the script to take a json file path as input and call it day.