How to filter resource by OU tag with c7n-org #9687
-
I have a use case where I’d like to control policies being run against a set of accounts using c7n-org. I noticed that the OU gets generated as a tag in accounts.yaml so I was thinking of using it as a condition or filter in my policy but I can’t seem to get the logic right to get it working. Is it possible to filter resources based on OU like this or is there some other better way of handling this? Here’s an example policy for reference, the tag comes from account.yaml.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When you use execution conditions, there's an conditions:
- or:
- type: value
key: account.tags
op: contains
value: "path:/Stage" # <- this is pulled from account.yaml
- type: value
key: account_id
op: in
value:
- "111111111111"
- "222222222222" c7n-org also provides the ability to select accounts by tag at the command line. So rather than building that condition into your policy, you could run: c7n-org run --dryrun --verbose --tags 'path:/Stage' --config c7n-org-cfg.yml --use my-policy.yml On the plus side, that means you don't have to hardcode conditions into your policy. But if you try this for your case you'd need two separate runs: c7n-org run --dryrun --verbose --tags 'path:/Stage' --config c7n-org-cfg.yml --use my-policy.yml
c7n-org run --dryrun --verbose --accounts '111111111111,222222222222' --config c7n-org-cfg.yml --use my-policy.yml Because combining |
Beta Was this translation helpful? Give feedback.
When you use execution conditions, there's an
account
key that has account details from the c7n-org configuration. So if you want to filter based on tags, you can use theaccount.tags
key in your condition filter. In your case, something like this should work:c7n-org also provides the ability to select accounts by tag at the command line. So rather than building that condition into your policy, you could run:
c…