Terraform module to create AWS IAM resources 🇺🇦
See the codeTerraform module which creates AWS IAM resources.
Please refer to the AWS published IAM Best Practices for up to date guidance on IAM best practices.
Creates an account policy and account alias. Module instantiation is once per account.
module "iam_account" {
source = "terraform-aws-modules/iam/aws//modules/iam-account"
account_alias = "awesome-company"
max_password_age = 90
minimum_password_length = 24
require_uppercase_characters = true
require_lowercase_characters = true
require_numbers = true
require_symbols = true
password_reuse_prevention = 3
allow_users_to_change_password = true
}
Creates an IAM group with IAM policy attached that one or more users can be added to.
module "iam_group" {
source = "terraform-aws-modules/iam/aws//modules/iam-group"
name = "superadmins"
users = [
"user1",
"user2"
]
enable_self_management_permissions = true
permissions = {
AssumeRole = {
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::111111111111:role/admin"]
}
}
policies = {
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess",
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an OpenID connect provider. Useful for trusting external identity providers such as GitHub, Bitbucket, etc.
[!TIP] An IAM provider is 1 per account per given URL. This module would be provisioned once per AWS account, and then one or more roles can be created with this provider as the trusted identity.
module "iam_oidc_provider" {
source = "terraform-aws-modules/iam/aws//modules/iam-oidc-provider"
url = "https://token.actions.githubusercontent.com"
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM policy.
module "iam_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
name = "example"
path = "/"
description = "My example policy"
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM policy that allows read-only access to the list of AWS services provided.
module "iam_read_only_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-read-only-policy"
name = "example"
path = "/"
description = "My example read-only policy"
allowed_services = ["rds", "dynamo", "health"]
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role with a trust policy and (optional) IAM instance profile. Useful for service roles such as EC2, ECS, etc., or roles assumed across AWS accounts.
module "iam_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
name = "example"
trust_policy_permissions = {
TrustRoleAndServiceToAssume = {
actions = [
"sts:AssumeRole",
"sts:TagSession",
]
principals = [{
type = "AWS"
identifiers = [
"arn:aws:iam::835367859851:user/anton",
]
}]
condition = [{
test = "StringEquals"
variable = "sts:ExternalId"
values = ["some-secret-id"]
}]
}
}
policies = {
AmazonCognitoReadOnly = "arn:aws:iam::aws:policy/AmazonCognitoReadOnly"
AlexaForBusinessFullAccess = "arn:aws:iam::aws:policy/AlexaForBusinessFullAccess"
custom = aws_iam_policy.this.arn
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role that trusts an OpenID connect provider. Useful for trusting external identity providers such as GitHub, Bitbucket, etc.
module "iam_role_github_oidc" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
enable_github_oidc = true
# This should be updated to suit your organization, repository, references/branches, etc.
oidc_wildcard_subjects = ["terraform-aws-modules/terraform-aws-iam:*"]
policies = {
S3ReadOnly = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role that trusts a SAML provider. Useful for trusting external identity providers such as Okta, OneLogin, etc.
module "iam_role_saml" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
name = "example"
enable_saml = true
saml_provider_ids = ["arn:aws:iam::235367859851:saml-provider/idp_saml"]
policies = {
ReadOnlyAccess = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
[!TIP] Upgrade to use EKS Pod Identity instead of IRSA A similar module for EKS Pod Identity is available here.
Creates an IAM role that is suitable for EKS IAM role for service accounts (IRSA) with a set of pre-defined policies for common EKS addons.
module "vpc_cni_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts"
name = "vpc-cni"
attach_vpc_cni_policy = true
vpc_cni_enable_ipv4 = true
oidc_providers = {
this = {
provider_arn = "arn:aws:iam::012345678901:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/5C54DDF35ER19312844C7333374CC09D"
namespace_service_accounts = ["kube-system:aws-node"]
}
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM user with ability to create a login profile, access key, and SSH key.
module "iam_user" {
source = "terraform-aws-modules/iam/aws//modules/iam-user"
name = "vasya.pupkin"
force_destroy = true
pgp_key = "keybase:test"
password_reset_required = false
tags = {
Terraform = "true"
Environment = "dev"
}
}
A few requests come up again and again and cannot be implemented by this
module, or by any module: Terraform requires lifecycle arguments to be
literal values inside the resource block.
hashicorp/terraform#18367
has been open since 2018,
#22544 since 2019, and
opentofu/opentofu#1329 is
the same request for OpenTofu.
default_tags, or fork this module and
add ignore_changes = [tags, tags_all].Compliance.tf serves this module with
these rules applied at download time, on top of whatever your organization
already has enabled there. Inputs and outputs do not change; the source line
does. Drop the version argument and pin the release you use by adding
&version= and that release number to the URL. To get started, register a free
compliance.tf account and configure an access token:
source = "https://registry.compliance.tf/terraform-aws-modules/iam/aws//modules/iam-role?add_rules=lifecycle_ignore_tags"
The full workaround for each item above, and the exact diff each rule makes, are in the compliance.tf docs for this module. To preview a diff without an account, open this module in the Rules Playground.
Disclosure: written by this module's maintainer, who also builds compliance.tf.
Module is maintained by Anton Babenko with help from these awesome contributors.
Apache-2.0 Licensed. See LICENSE.
211 followers · starred Oct 2026
149 followers · starred Nov 2023
40 followers · starred Jan 2023
75 followers · starred Apr 2023
Terraform module to create AWS IAM resources 🇺🇦
See the codeTerraform module which creates AWS IAM resources.
Please refer to the AWS published IAM Best Practices for up to date guidance on IAM best practices.
Creates an account policy and account alias. Module instantiation is once per account.
module "iam_account" {
source = "terraform-aws-modules/iam/aws//modules/iam-account"
account_alias = "awesome-company"
max_password_age = 90
minimum_password_length = 24
require_uppercase_characters = true
require_lowercase_characters = true
require_numbers = true
require_symbols = true
password_reuse_prevention = 3
allow_users_to_change_password = true
}
Creates an IAM group with IAM policy attached that one or more users can be added to.
module "iam_group" {
source = "terraform-aws-modules/iam/aws//modules/iam-group"
name = "superadmins"
users = [
"user1",
"user2"
]
enable_self_management_permissions = true
permissions = {
AssumeRole = {
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::111111111111:role/admin"]
}
}
policies = {
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess",
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an OpenID connect provider. Useful for trusting external identity providers such as GitHub, Bitbucket, etc.
[!TIP] An IAM provider is 1 per account per given URL. This module would be provisioned once per AWS account, and then one or more roles can be created with this provider as the trusted identity.
module "iam_oidc_provider" {
source = "terraform-aws-modules/iam/aws//modules/iam-oidc-provider"
url = "https://token.actions.githubusercontent.com"
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM policy.
module "iam_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
name = "example"
path = "/"
description = "My example policy"
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM policy that allows read-only access to the list of AWS services provided.
module "iam_read_only_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-read-only-policy"
name = "example"
path = "/"
description = "My example read-only policy"
allowed_services = ["rds", "dynamo", "health"]
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role with a trust policy and (optional) IAM instance profile. Useful for service roles such as EC2, ECS, etc., or roles assumed across AWS accounts.
module "iam_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
name = "example"
trust_policy_permissions = {
TrustRoleAndServiceToAssume = {
actions = [
"sts:AssumeRole",
"sts:TagSession",
]
principals = [{
type = "AWS"
identifiers = [
"arn:aws:iam::835367859851:user/anton",
]
}]
condition = [{
test = "StringEquals"
variable = "sts:ExternalId"
values = ["some-secret-id"]
}]
}
}
policies = {
AmazonCognitoReadOnly = "arn:aws:iam::aws:policy/AmazonCognitoReadOnly"
AlexaForBusinessFullAccess = "arn:aws:iam::aws:policy/AlexaForBusinessFullAccess"
custom = aws_iam_policy.this.arn
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role that trusts an OpenID connect provider. Useful for trusting external identity providers such as GitHub, Bitbucket, etc.
module "iam_role_github_oidc" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
enable_github_oidc = true
# This should be updated to suit your organization, repository, references/branches, etc.
oidc_wildcard_subjects = ["terraform-aws-modules/terraform-aws-iam:*"]
policies = {
S3ReadOnly = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM role that trusts a SAML provider. Useful for trusting external identity providers such as Okta, OneLogin, etc.
module "iam_role_saml" {
source = "terraform-aws-modules/iam/aws//modules/iam-role"
name = "example"
enable_saml = true
saml_provider_ids = ["arn:aws:iam::235367859851:saml-provider/idp_saml"]
policies = {
ReadOnlyAccess = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
[!TIP] Upgrade to use EKS Pod Identity instead of IRSA A similar module for EKS Pod Identity is available here.
Creates an IAM role that is suitable for EKS IAM role for service accounts (IRSA) with a set of pre-defined policies for common EKS addons.
module "vpc_cni_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts"
name = "vpc-cni"
attach_vpc_cni_policy = true
vpc_cni_enable_ipv4 = true
oidc_providers = {
this = {
provider_arn = "arn:aws:iam::012345678901:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/5C54DDF35ER19312844C7333374CC09D"
namespace_service_accounts = ["kube-system:aws-node"]
}
}
tags = {
Terraform = "true"
Environment = "dev"
}
}
Creates an IAM user with ability to create a login profile, access key, and SSH key.
module "iam_user" {
source = "terraform-aws-modules/iam/aws//modules/iam-user"
name = "vasya.pupkin"
force_destroy = true
pgp_key = "keybase:test"
password_reset_required = false
tags = {
Terraform = "true"
Environment = "dev"
}
}
A few requests come up again and again and cannot be implemented by this
module, or by any module: Terraform requires lifecycle arguments to be
literal values inside the resource block.
hashicorp/terraform#18367
has been open since 2018,
#22544 since 2019, and
opentofu/opentofu#1329 is
the same request for OpenTofu.
default_tags, or fork this module and
add ignore_changes = [tags, tags_all].Compliance.tf serves this module with
these rules applied at download time, on top of whatever your organization
already has enabled there. Inputs and outputs do not change; the source line
does. Drop the version argument and pin the release you use by adding
&version= and that release number to the URL. To get started, register a free
compliance.tf account and configure an access token:
source = "https://registry.compliance.tf/terraform-aws-modules/iam/aws//modules/iam-role?add_rules=lifecycle_ignore_tags"
The full workaround for each item above, and the exact diff each rule makes, are in the compliance.tf docs for this module. To preview a diff without an account, open this module in the Rules Playground.
Disclosure: written by this module's maintainer, who also builds compliance.tf.
Module is maintained by Anton Babenko with help from these awesome contributors.
Apache-2.0 Licensed. See LICENSE.
211 followers · starred Oct 2026
149 followers · starred Nov 2023
40 followers · starred Jan 2023
75 followers · starred Apr 2023