In normal terraform, I can do something like this to find an AWS Organizational OU by its name:
data "aws_organizations_organization" "this" {
}
data "aws_organizations_organizational_units" "ou" {
parent_id = data.aws_organizations_organization.this.roots[0].id
}
locals {
specific_ou = [for ou in data.aws_organizations_organizational_units.ou.children: ou if ou.name == "ou_name"]
}
Is there a way to replicate this with CDK?
I am trying with the DataAwsOrganizationsOrganizationalUnits class but not quite sure how I can filter on name as the synth only creates the code and won’t fetch the data (I think).
Locals aren’t natively supported at this time. You should be able to workaround by using an escape hatch.
Something along the lines of: stack.addOverride('locals.specific_out', [for ou in data.aws_organizations_organizational_units.ou.children: ou if ou.name == "ou_name"]'
There isn’t currently control over the name given to data sources, so you’ll need to concatenate the value.