'Get Organisation Unit from Account ID

In terraform is there a way (data source etc.) to extract Organization Unit (OU) from ID of the account that belongs to that OU?

I can extract various pieces of information from

data "aws_caller_identity" "current" {}

or

data "aws_iam_session_context" "current" {}

But no OU.



Solution 1:[1]

I couldn't find direct way to do this in terraform, but found out that CLI command list-parents exists that I could use in conjunction with terraform. Until terraform adds this datasource I will go this way.

Solution 2:[2]

There is a data source for OUs: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organizational_units.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yuriy Galanter
Solution 2 Marko E