JQ — add element to array and return full json
Although this works, it only output the specific section, as I am executing a select . Content of $policy :
< "Version": "2012-10-17", "Id": "key-consolepolicy-3", "Statement": [ < "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": < "AWS": "arn:aws:iam::*:root" >, "Action": "kms:*", "Resource": "*" >, < "Sid": "Allow access for Key Administrators", "Effect": "Allow", "Principal": < "AWS": "arn:aws:iam::*:user/*" >, "Action": [ "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:TagResource", "kms:UntagResource" ], "Resource": "*" >, < "Sid": "Allow use of the key", "Effect": "Allow", "Principal": < "AWS": [ "arn:aws:iam::*:root" ] >, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:DescribeKey", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:CreateGrant" ], "Resource": "*" > ] >
< "Version": "2012-10-17", "Id": "key-consolepolicy-3", "Statement": [ < "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": < "AWS": "arn:aws:iam::*:root" >, "Action": "kms:*", "Resource": "*" >, < "Sid": "Allow access for Key Administrators", "Effect": "Allow", "Principal": < "AWS": "arn:aws:iam::*:user/*" >, "Action": [ "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:TagResource", "kms:UntagResource" ], "Resource": "*" >, < "Sid": "Allow use of the key", "Effect": "Allow", "Principal": < "AWS": [ "arn:aws:iam::*:root", "arn:aws:iam::$root:root" , "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:DescribeKey", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:CreateGrant" ], "Resource": "*" > ] >