I am Trying to change the AWS Tags for the Existing EC2 resources based on Key-Value pair. If Key-value pair matches, add/modify the tag. I am using AWS CLI for this operation
declare -a instance instance=$(aws ec2 describe-instances | jq ".Reservations[].Instances[].Tags[] | [.Key, .Value]")
This is generating the output as [ "Name", "TestCLI2" ] [ "Instance", "Trial2" ] [ "Instance", "Trial1" ] [ "Name", "TestCLI1" ]
Now I want to match for all those instances which has Key="Instance" and Value=["Trial1", "Trial2] should be modified to Trial3
I am trying to use loop but not able to proceed further as how to parse this JSON to check under if statements
for i in "${instance[@]}" # Looping through all the instances