Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconcodegen
file-type-iconexamples
file-type-iconcloudtrail
file-type-iconcloudwatch-logs-metric-filters
file-type-iconcross-account-iam-roles
file-type-iconcustom-iam-entity
file-type-iconterraform
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconterragrunt
file-type-iconiam-groups
file-type-iconiam-password-policy
file-type-iconsaml-iam-roles
file-type-iconsecurityhub
file-type-iconmodules
file-type-iconrfcs
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
file-type-iconsetup.cfg

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconcodegen
file-type-iconexamples
file-type-iconcloudtrail
file-type-iconcloudwatch-logs-metric-filters
file-type-iconcross-account-iam-roles
file-type-iconcustom-iam-entity
file-type-iconterraform
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconterragrunt
file-type-iconiam-groups
file-type-iconiam-password-policy
file-type-iconsaml-iam-roles
file-type-iconsecurityhub
file-type-iconmodules
file-type-iconrfcs
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
file-type-iconsetup.cfg
CIS Foundations Benchmark

CIS Foundations Benchmark

Modules and utilities certified by Gruntwork and CIS to comply with the CIS AWS Foundations Benchmark

Code Preview

Preview the Code

mobile file icon

README.md

down

Custom IAM Entity Terraform wrapper example

This is an example of how to use the custom-iam-entity module to create an IAM group or role with attached IAM policies. If you're using Terragrunt, see the terragrunt example.

Use the boolean variables should_create_iam_group and should_create_iam_role variables to specify whether to create a group and/or a role, respectively. Name the group and/or role with the iam_group_name and iam_role_name variables. If creating an IAM role, you must also specify a list of ARNs that are allowed to assume the role in assume_role_arns.

This example will create an IAM group and/or role with several example IAM policies attached. You can attach policies in any combination of the following variables:

  • iam_policy_arns: Attach policies by providing a list of policy ARNs
  • iam_customer_managed_policy_names: Attach policies by providing a list of customer-managed policy names
  • iam_aws_managed_policy_names: Attach policies by providing a list of AWS-managed policy names

All of these variables are optional.

If you provide customer-managed policy names, the module will look up the current AWS account ID and use it to generate the policy ARN for attachment.

arn:aws:iam::0123456789012:policy/MyCustomPolicy

If you provide AWS-managed policy names, the module will use the AWS formatted policy names for attachment. For example:

arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess

Any policies you provide must already exist or Terraform will throw an error.

Quick start

To try these templates out you must have Terraform installed:

  1. Open variables.tf and fill in any variables that don't have a default.
  2. Review the policies in variables.tf and decide which policies you would like to include.
  3. Lean on the example policy in main.tf to generate your own managed policies to attach.
  4. Run terraform init
  5. Run terraform apply to create the IAM groups/roles.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?