|
| 1 | +[](https://github.com/elastic2ls-com/terraform-aws-finops-costreview-access/actions) |
| 2 | + |
| 3 | + |
| 4 | +[](https://github.com/sponsors/AlexanderWiechert/) |
| 5 | +[](https://www.elastic2ls.com/) |
| 6 | +[](https://registry.terraform.io/modules/elastic2ls-com/finops-costreview-access/aws/latest) |
| 7 | + |
| 8 | + |
| 9 | +# terraform-aws-finops-costreview-access |
| 10 | + |
| 11 | +Terraform module to create an IAM user or cross-account IAM role for external FinOps cost reviews in an AWS account. |
| 12 | + |
| 13 | +This module is compatible with both Terraform (>=1.3) and OpenTofu (>=1.3). |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +- Create **IAM user** with read-only access for Billing, Cost Explorer, CloudWatch. |
| 20 | +- Create **cross-account IAM role** with trust policy for a service provider. |
| 21 | +- Optional: attach `AWSOrganizationsReadOnlyAccess` policy. |
| 22 | +- Flexible naming of user and role, with defaults. |
| 23 | +- Includes examples and CI workflow with security checks. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +### IAM User (default mode) |
| 30 | + |
| 31 | +```hcl |
| 32 | +module "finops_access" { |
| 33 | + source = "github.com/elastic2ls-com/terraform-aws-finops-costreview-access" |
| 34 | + mode = "iam-user" |
| 35 | + account_id = "123456789012" |
| 36 | + user_name = "finops-review-user" |
| 37 | + role_name = "finops-review-role" |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Cross-Account Role |
| 42 | + |
| 43 | +```hcl |
| 44 | +module "finops_access" { |
| 45 | + source = "github.com/elastic2ls-com/terraform-aws-finops-costreview-access" |
| 46 | + mode = "cross-account-role" |
| 47 | + service_provider_account_id = "123456789012" |
| 48 | + service_provider_role_name = "finops-review-role" |
| 49 | + external_id = "your-secure-external-id" # Optional |
| 50 | + role_name = "custom-finops-role" # Optional, default: 'FinOpsCostReviewRole' |
| 51 | + user_name = "custom-finops-user" # Optional, default: 'finops-review-user' (ignored in this mode) |
| 52 | + attach_organizations_policy = true |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Security Best Practices |
| 57 | + |
| 58 | +- Use `service_provider_role_name` to limit access to a specific role. |
| 59 | +- Set `external_id` to prevent the confused-deputy problem. |
| 60 | +- Avoid using account root (`arn:aws:iam::<account_id>:root`) as principal. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## Examples |
| 65 | + |
| 66 | +- [IAM User Example](./examples/iam-user/main.tf) |
| 67 | +- [Cross-Account Role Example](./examples/cross-account-role/main.tf) |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Variables |
| 72 | + |
| 73 | +| Name | Description | Type | Default | |
| 74 | +|-----------------------------|---------------------------------------------------------------------|---------|--------------------------| |
| 75 | +| `mode` | Access mode: `'iam-user'` or `'cross-account-role'` | string | `"iam-user"` | |
| 76 | +| `user_name` | IAM user name (for `iam-user` mode). Defaults to `'finops-review-user'`. | string | `"finops-review-user"` | |
| 77 | +| `service_provider_account_id` | AWS account ID of the service provider (for role mode) | string | `""` | |
| 78 | +| `role_name` | IAM role name (for `cross-account-role` mode). Defaults to `'FinOpsCostReviewRole'`. | string | `"FinOpsCostReviewRole"` | |
| 79 | +| `attach_organizations_policy` | Whether to attach `AWSOrganizationsReadOnlyAccess` policy | bool | `false` | |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Outputs |
| 84 | + |
| 85 | +| Name | Description | |
| 86 | +|------------|----------------------------------| |
| 87 | +| `user_name` | IAM user name (if created) | |
| 88 | +| `user_arn` | IAM user ARN (if created) | |
| 89 | +| `role_name` | IAM role name (if created) | |
| 90 | +| `role_arn` | IAM role ARN (if created) | |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Requirements |
| 95 | + |
| 96 | +- Terraform ≥ 1.3 |
| 97 | +- AWS Provider ≥ 5.0 |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## CI/CD |
| 102 | + |
| 103 | +This module uses GitHub Actions to run: |
| 104 | +- `terraform fmt` |
| 105 | +- `terraform validate` |
| 106 | +- `terraform plan` on examples |
| 107 | +- `checkov` security scan |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## License |
| 112 | + |
| 113 | +[MIT](./LICENSE) |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## Maintainers |
| 118 | + |
| 119 | +[elastic2ls](https://github.com/elastic2ls-com) |
0 commit comments