diff --git a/modules/util/account-list/README.md b/modules/util/account-list/README.md new file mode 100644 index 0000000..7748081 --- /dev/null +++ b/modules/util/account-list/README.md @@ -0,0 +1,16 @@ +# acocunt-list module +This module returns a list of accounts by querying the aws_organizations_organiation datasource. It returns an accounts map like this + +``` +{ + account-name-1 = "111111111111" + account-name-2 = "111111111111" +} +``` + +In the root module, query the account id like this +```terraform +output result { + value = lookup(module.account-list.accounts, "account-name-1") +} +``` \ No newline at end of file diff --git a/modules/util/account-list/main.tf b/modules/util/account-list/main.tf new file mode 100644 index 0000000..8ca0bca --- /dev/null +++ b/modules/util/account-list/main.tf @@ -0,0 +1,2 @@ +data "aws_organizations_organization" "org" {} + diff --git a/modules/util/account-list/outputs.tf b/modules/util/account-list/outputs.tf new file mode 100644 index 0000000..33d1c70 --- /dev/null +++ b/modules/util/account-list/outputs.tf @@ -0,0 +1,3 @@ +output accounts { + value = zipmap(data.aws_organizations_organization.org.accounts[*].name, data.aws_organizations_organization.org.accounts[*].id) +} \ No newline at end of file diff --git a/modules/util/account-list/provider.tf b/modules/util/account-list/provider.tf new file mode 100644 index 0000000..da0e9eb --- /dev/null +++ b/modules/util/account-list/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "~> 1.2.5" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.22" + } + } +} +