NEW: account-list module

This commit is contained in:
xpk 2022-08-17 15:20:12 +08:00
parent d7d12301d8
commit 89a45a747e
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
4 changed files with 31 additions and 0 deletions

View File

@ -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")
}
```

View File

@ -0,0 +1,2 @@
data "aws_organizations_organization" "org" {}

View File

@ -0,0 +1,3 @@
output accounts {
value = zipmap(data.aws_organizations_organization.org.accounts[*].name, data.aws_organizations_organization.org.accounts[*].id)
}

View File

@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.2.5"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.22"
}
}
}