2

I am trying to append the list of account Ids since I don't have access to organization, but whenever i am doing it, previous accounts get replaced with new account ID and i only want to append them. Please let me know how to do it.

aws configservice put-configuration-aggregator --configuration-aggregator-name test-config --account-aggregation-sources "[{\"AccountIds\": [\"xxxxxx\",\"xxxx\"],\"AwsRegions\": [\"us-east-1\"]}]"
SRJ
  • 2,092
  • 3
  • 17
  • 36
AniK
  • 55
  • 8

1 Answers1

2

From the documentation

accountIds that are passed will be replaced with existing accounts. If you want to add additional accounts into the aggregator, call DescribeAggregator to get the previous accounts and then append new ones.

References : https://awscli.amazonaws.com/v2/documentation/api/latest/reference/configservice/put-configuration-aggregator.html

So you can first call DescribeAggregator1 to get the previous accounts and store them in some variable. Then append new accounts to previous accounts variable via jq.

Append JSON Object via jq

Note - I have added links for AWS CLI V2.

SRJ
  • 2,092
  • 3
  • 17
  • 36
  • I tried this already, but whenever i am trying to append new ones by calling DescribeAggregator, i am not getting an idea on how to first save that account ids list and then appending it. Can you please suggest me the right steps for doing this – AniK Aug 10 '21 at 06:40
  • { "ConfigurationAggregators": [ { "ConfigurationAggregatorName": "test-config", "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:xxxx:config-aggregator/config-aggregator-uw2", "AccountAggregationSources": [ { "AccountIds": [ "xxxxx" ], "AllAwsRegions": true } ], "CreationTime": 1624454176.124, "LastUpdatedTime": 1626426755.504 } ] } – AniK Aug 10 '21 at 07:25
  • for storing into a variable, i tried something like this - name: Export results to JSON set_fact: config_ouput_json: "{{ AccountIds | json_query('*.AccountIds') }}" – AniK Aug 10 '21 at 07:25
  • command I ran for DescribeAggregator : aws configservice describe-configuration-aggregators --configuration-aggregator-name test-config --output json – AniK Aug 10 '21 at 07:28
  • 1
    Loop through `config_output_json` which is previous accounts and add values to existing json array of new accounts. Refer this https://serverfault.com/questions/1016863/building-list-of-json-objects-in-ansible – SRJ Aug 10 '21 at 07:46
  • 1
    I have posted the question on https://stackoverflow.com/questions/68737905/how-to-append-json-array-with-specific-data if you want to have a better look at it. – AniK Aug 11 '21 at 07:43