Skip to content

Commit f5dc012

Browse files
committed
Migrate modules from terraform-aws-account
1 parent eda3482 commit f5dc012

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3776
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# terraform-aws-organization
2+
3+
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/tedilabs/terraform-aws-organization?color=blue&sort=semver&style=flat-square)
4+
![GitHub](https://img.shields.io/github/license/tedilabs/terraform-aws-organization?color=blue&style=flat-square)
5+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square)](https://github.com/pre-commit/pre-commit)
6+
7+
Terraform modules to manage Organization related resources on AWS.
8+
9+
- [account](./modules/account)
10+
- [organization](./modules/organization)
11+
- [organizational-unit](./modules/organizational-unit)
12+
- [ram-share](./modules/ram-share)
13+
- [sso-access-control-attributes](./modules/sso-access-control-attributes)
14+
- [sso-account-assignment](./modules/sso-account-assignment)
15+
- [sso-permission-set](./modules/sso-permission-set)
16+
17+
18+
## Target AWS Services
19+
20+
Terraform Modules from [this package](https://github.com/tedilabs/terraform-aws-organization) were written to manage the following AWS Services with Terraform.
21+
22+
- **AWS IAM Identity Center (AWS SSO)**
23+
- Access Control Attributes
24+
- Account Assignment
25+
- Permission Set
26+
- **AWS Organization**
27+
- Organization
28+
- Organization Unit
29+
- Account
30+
- **AWS RAM (Resource Access Manager)**
31+
- Share
32+
33+
34+
## Other Terraform Modules from Tedilabs
35+
36+
Enjoying [terraform-aws-organization](https://github.com/tedilabs/terraform-aws-organization)? Check out some of our other modules:
37+
38+
- [AWS Container](https://github.com/tedilabs/terraform-aws-container) - A package of Terraform Modules to manage AWS Container resources.
39+
- [AWS Domain](https://github.com/tedilabs/terraform-aws-domain) - A package of Terraform Modules to manage AWS Domain resources.
40+
- [AWS Load Balancer](https://github.com/tedilabs/terraform-aws-load-balancer) - A package of Terraform Modules to manage AWS Load Balancer resources.
41+
- [AWS Network](https://github.com/tedilabs/terraform-aws-network) - A package of Terraform Modules to manage AWS Network resources.
42+
- [AWS Security](https://github.com/tedilabs/terraform-aws-security) - A package of Terraform Modules to manage AWS Security resources.
43+
44+
Or check out [the full list](https://github.com/search?q=org%3Atedilabs+topic%3Aterraform-module&type=repositories)
45+
46+
47+
## Self Promotion
48+
49+
Like this project? Follow the repository on [GitHub](https://github.com/tedilabs/terraform-aws-organization). And if you're feeling especially charitable, follow **[posquit0](https://github.com/posquit0)** on GitHub.
50+
51+
52+
## License
53+
54+
Provided under the terms of the [Apache License](LICENSE).
55+
56+
Copyright © 2024, [Byungjin Park](https://www.posquit0.com).

modules/account/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# account
2+
3+
This module creates following resources.
4+
5+
- `aws_organizations_account`
6+
- `aws_organizations_policy_attachment` (optional)
7+
- `aws_organizations_delegated_administrator` (optional)
8+
- `aws_fms_admin_account` (optional)
9+
- `aws_guardduty_organization_admin_account` (optional)
10+
- `aws_macie2_organization_admin_account` (optional)
11+
- `aws_securityhub_organization_admin_account` (optional)
12+
- `aws_vpc_ipam_organization_admin_account` (optional)
13+
14+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
15+
## Requirements
16+
17+
| Name | Version |
18+
|------|---------|
19+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
20+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.65 |
21+
22+
## Providers
23+
24+
| Name | Version |
25+
|------|---------|
26+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.19.0 |
27+
28+
## Modules
29+
30+
| Name | Source | Version |
31+
|------|--------|---------|
32+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
33+
34+
## Resources
35+
36+
| Name | Type |
37+
|------|------|
38+
| [aws_fms_admin_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/fms_admin_account) | resource |
39+
| [aws_guardduty_organization_admin_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/guardduty_organization_admin_account) | resource |
40+
| [aws_macie2_organization_admin_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/macie2_organization_admin_account) | resource |
41+
| [aws_organizations_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_account) | resource |
42+
| [aws_organizations_delegated_administrator.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_delegated_administrator) | resource |
43+
| [aws_organizations_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy_attachment) | resource |
44+
| [aws_securityhub_organization_admin_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/securityhub_organization_admin_account) | resource |
45+
| [aws_vpc_ipam_organization_admin_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_organization_admin_account) | resource |
46+
| [aws_organizations_organization.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
47+
48+
## Inputs
49+
50+
| Name | Description | Type | Default | Required |
51+
|------|-------------|------|---------|:--------:|
52+
| <a name="input_email"></a> [email](#input\_email) | The email address of the owner to assign to the new member account. This email address must not already be associated with another AWS account. | `string` | n/a | yes |
53+
| <a name="input_name"></a> [name](#input\_name) | A friendly name for the member account. | `string` | n/a | yes |
54+
| <a name="input_delegated_services"></a> [delegated\_services](#input\_delegated\_services) | A list of service principals of the AWS service for which you want to make the member account a delegated administrator. | `set(string)` | `[]` | no |
55+
| <a name="input_iam_user_access_to_billing_allowed"></a> [iam\_user\_access\_to\_billing\_allowed](#input\_iam\_user\_access\_to\_billing\_allowed) | If true, the new account enables IAM users to access account billing information if they have the required permissions. If false, then only the root user of the new account can access account billing information. | `bool` | `false` | no |
56+
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
57+
| <a name="input_parent_id"></a> [parent\_id](#input\_parent\_id) | Parent Organizational Unit ID or Root ID for the account. Defaults to the Organization default Root ID. A configuration must be present for this argument to perform drift detection. | `string` | `null` | no |
58+
| <a name="input_policies"></a> [policies](#input\_policies) | List of IDs of the policies to be attached to the Account. | `list(string)` | `[]` | no |
59+
| <a name="input_preconfigured_administrator_role_name"></a> [preconfigured\_administrator\_role\_name](#input\_preconfigured\_administrator\_role\_name) | The name of an IAM role that Organizations automatically preconfigures in the new member account. This role trusts the master account, allowing users in the master account to assume the role, as permitted by the master account administrator. The role has administrator permissions in the new member account. | `string` | `null` | no |
60+
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
61+
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
62+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
63+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources. | `map(string)` | `{}` | no |
64+
65+
## Outputs
66+
67+
| Name | Description |
68+
|------|-------------|
69+
| <a name="output_arn"></a> [arn](#output\_arn) | The Amazon Resource Name (ARN) of this account. |
70+
| <a name="output_created_at"></a> [created\_at](#output\_created\_at) | The datetime which this account joined to the organization. |
71+
| <a name="output_created_by"></a> [created\_by](#output\_created\_by) | The method how this account joined to the organization. |
72+
| <a name="output_delegated_services"></a> [delegated\_services](#output\_delegated\_services) | A list of service principals of the AWS service which the member account is a delegated administrator. |
73+
| <a name="output_email"></a> [email](#output\_email) | The email address of this account. |
74+
| <a name="output_iam_user_access_to_billing_allowed"></a> [iam\_user\_access\_to\_billing\_allowed](#output\_iam\_user\_access\_to\_billing\_allowed) | Whether accessing account billing information by IAM User is allowed. |
75+
| <a name="output_id"></a> [id](#output\_id) | The ID of this account. |
76+
| <a name="output_name"></a> [name](#output\_name) | The name of this account. |
77+
| <a name="output_parent_id"></a> [parent\_id](#output\_parent\_id) | The ID of the parent Organizational Unit. |
78+
| <a name="output_preconfigured_administrator_role_name"></a> [preconfigured\_administrator\_role\_name](#output\_preconfigured\_administrator\_role\_name) | The name of an IAM role that allow users in the master account to assume as administrator. |
79+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
locals {
2+
independent_services = [
3+
"fms.amazonaws.com",
4+
"guardduty.amazonaws.com",
5+
"ipam.amazonaws.com",
6+
"macie.amazonaws.com",
7+
"securityhub.amazonaws.com",
8+
]
9+
}
10+
11+
12+
###################################################
13+
# Delegated Administrators for Organization Account
14+
###################################################
15+
16+
resource "aws_organizations_delegated_administrator" "this" {
17+
for_each = toset([
18+
for service in var.delegated_services :
19+
service
20+
if !contains(local.independent_services, service)
21+
])
22+
23+
account_id = aws_organizations_account.this.id
24+
service_principal = each.key
25+
}
26+
27+
resource "aws_fms_admin_account" "this" {
28+
count = contains(var.delegated_services, "fms.amazonaws.com") ? 1 : 0
29+
30+
account_id = aws_organizations_account.this.id
31+
}
32+
33+
resource "aws_guardduty_organization_admin_account" "this" {
34+
count = contains(var.delegated_services, "guardduty.amazonaws.com") ? 1 : 0
35+
36+
admin_account_id = aws_organizations_account.this.id
37+
}
38+
39+
resource "aws_macie2_organization_admin_account" "this" {
40+
count = contains(var.delegated_services, "macie.amazonaws.com") ? 1 : 0
41+
42+
admin_account_id = aws_organizations_account.this.id
43+
}
44+
45+
resource "aws_securityhub_organization_admin_account" "this" {
46+
count = contains(var.delegated_services, "securityhub.amazonaws.com") ? 1 : 0
47+
48+
admin_account_id = aws_organizations_account.this.id
49+
}
50+
51+
resource "aws_vpc_ipam_organization_admin_account" "this" {
52+
count = contains(var.delegated_services, "ipam.amazonaws.com") ? 1 : 0
53+
54+
delegated_admin_account_id = aws_organizations_account.this.id
55+
}

modules/account/main.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-organization"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
module_tags = var.module_tags_enabled ? {
9+
"module.terraform.io/package" = local.metadata.package
10+
"module.terraform.io/version" = local.metadata.version
11+
"module.terraform.io/name" = local.metadata.module
12+
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
13+
"module.terraform.io/instance" = local.metadata.name
14+
} : {}
15+
}
16+
17+
data "aws_organizations_organization" "this" {}
18+
19+
locals {
20+
organization_root_id = data.aws_organizations_organization.this.roots[0].id
21+
}
22+
23+
resource "aws_organizations_account" "this" {
24+
name = var.name
25+
email = var.email
26+
parent_id = coalesce(var.parent_id, local.organization_root_id)
27+
28+
iam_user_access_to_billing = var.iam_user_access_to_billing_allowed ? "ALLOW" : "DENY"
29+
role_name = var.preconfigured_administrator_role_name
30+
31+
tags = merge(
32+
{
33+
"Name" = local.metadata.name
34+
},
35+
local.module_tags,
36+
var.tags,
37+
)
38+
39+
# There is no AWS Organizations API for reading role_name
40+
lifecycle {
41+
ignore_changes = [
42+
iam_user_access_to_billing,
43+
role_name,
44+
]
45+
}
46+
}
47+
48+
49+
###################################################
50+
# AWS Managed Policies
51+
###################################################
52+
53+
resource "aws_organizations_policy_attachment" "this" {
54+
for_each = toset(var.policies)
55+
56+
target_id = aws_organizations_account.this.id
57+
policy_id = each.key
58+
}

modules/account/outputs.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
output "name" {
2+
description = "The name of this account."
3+
value = aws_organizations_account.this.name
4+
}
5+
6+
output "email" {
7+
description = "The email address of this account."
8+
value = aws_organizations_account.this.email
9+
}
10+
11+
output "id" {
12+
description = "The ID of this account."
13+
value = aws_organizations_account.this.id
14+
}
15+
16+
output "arn" {
17+
description = "The Amazon Resource Name (ARN) of this account."
18+
value = aws_organizations_account.this.arn
19+
}
20+
21+
output "parent_id" {
22+
description = "The ID of the parent Organizational Unit."
23+
value = aws_organizations_account.this.parent_id
24+
}
25+
26+
output "iam_user_access_to_billing_allowed" {
27+
description = "Whether accessing account billing information by IAM User is allowed."
28+
value = var.iam_user_access_to_billing_allowed
29+
}
30+
31+
output "preconfigured_administrator_role_name" {
32+
description = "The name of an IAM role that allow users in the master account to assume as administrator."
33+
value = var.preconfigured_administrator_role_name
34+
}
35+
36+
output "delegated_services" {
37+
description = "A list of service principals of the AWS service which the member account is a delegated administrator."
38+
value = var.delegated_services
39+
}
40+
41+
output "created_by" {
42+
description = "The method how this account joined to the organization."
43+
value = aws_organizations_account.this.joined_method
44+
}
45+
46+
output "created_at" {
47+
description = "The datetime which this account joined to the organization."
48+
value = aws_organizations_account.this.joined_timestamp
49+
}

modules/account/resource-group.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
locals {
2+
resource_group_name = (var.resource_group_name != ""
3+
? var.resource_group_name
4+
: join(".", [
5+
local.metadata.package,
6+
local.metadata.module,
7+
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"),
8+
])
9+
)
10+
}
11+
12+
13+
module "resource_group" {
14+
source = "tedilabs/misc/aws//modules/resource-group"
15+
version = "~> 0.10.0"
16+
17+
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
18+
19+
name = local.resource_group_name
20+
description = var.resource_group_description
21+
22+
query = {
23+
resource_tags = local.module_tags
24+
}
25+
26+
module_tags_enabled = false
27+
tags = merge(
28+
local.module_tags,
29+
var.tags,
30+
)
31+
}

0 commit comments

Comments
 (0)