terraform-aws-iam-policy
A Terraform base module for deploying and managing IAM Policies on Amazon Web Services (AWS).
This module supports Terraform v1.x, v0.15, v0.14, v0.13, as well as v0.12.20 and above and is compatible with the terraform AWS provider v3 as well as v2.0 and above.
- Module Features
- Getting Started
- Module Argument Reference
- Module Outputs
- External Documentation
- Module Versioning
- About Mineiros
- Reporting Issues
- Contributing
- Makefile Targets
- License
Module Features
You can create a custom AWS IAM Policy that can be attached to other IAM resources such as users, roles or groups.
- Standard Module Features: Create a custom IAM Policy.
- Extended Module Features: Create exclusive policy attachments to roles, groups and/or users.
Getting Started
Basic usage for creating an IAM Policy granting full access to AWS Simple Storage Service (S3)
module "role-s3-full-access" {
source = "mineiros-io/iam-policy/aws"
version = "~> 0.5.0"
name = "S3FullAccess"
policy_statements = [
{
sid = "FullS3Access"
effect = "Allow"
actions = ["s3:*"]
resources = ["*"]
}
]
}
Module Argument Reference
See variables.tf and examples/ for details and use-cases.
Module Configuration
-
module_enabled
: (Optionalbool
)Specifies whether resources in the module will be created.
Default is
true
. -
module_tags
: (Optionalmap(string)
)A map of tags that will be applied to all created resources that accept tags. Tags defined with
module_tags
can be overwritten by resource-specific tags.Default is
{}
. -
module_depends_on
: (Optionallist(any)
)A list of dependencies. Any object can be assigned to this list to define a hidden external dependency.
Top-level Arguments
Main Resource Configuration
-
policy
: (Requiredstring
)This is a JSON formatted string representing an IAM Policy Document. (only required if
policy_statements
is not set) -
policy_statements
: (Requiredlist(statement)
)A list of policy statements to build the policy document from. (only required if
policy
is not set)Example:
policy_statements = [ { sid = "FullS3Access" effect = "Allow" actions = ["s3:*"] not_actions = [] resources = ["*"] not_resources = [] principals = [ { type = "AWS" identifiers = ["arn:aws:iam::123456789012:root"] } ] not_principals = [] conditions = [ { test = "Bool" variable = "aws:MultiFactorAuthPresent" values = [ "true" ] } ] } ]
-
description
: (Optionalstring
)Description of the IAM policy. Forces new resource.
-
name
: (Optionalstring
)The name of the policy. If omitted, Terraform will assign a random, unique name. Forces new resource.
-
name_prefix
: (Optionalstring
)Creates a unique name beginning with the specified prefix. Forces new resource. Conflicts with
name
. -
path
: (Optionalstring
)Path in which to create the policy.
Default is
"/"
.
Extended Resource configuration
Policy attachment
WARNING: The used
aws_iam_policy_attachment
resource creates exclusive IAM policies attachments. Across the entire AWS account, all of the users/roles/groups to which a single policy is attached must be declared by a singleaws_iam_policy_attachment
resource. This means that even any users/roles/groups that have the attached policy via any other mechanism (including other Terraform resources) will have that attached policy revoked by this resource.Consider attaching this policy using the other Mineiros IAM modules
mineiros-io/terraform-aws-iam-role
,mineiros-io/terraform-aws-iam-group
,mineiros-io/terraform-aws-iam-user
.Or consider attaching this policy via the direct resources
aws_iam_role_policy_attachment
,aws_iam_user_policy_attachment
, oraws_iam_group_policy_attachment
instead. These modules and/or resources do not enforce exclusive attachment of an IAM policy.
-
attachment_name
: (Optionalstring
)The name of the attachment. Defaults to the
name
of the policy. -
users
: (Optionallist(string)
)The user(s) the policy should be applied to.
-
roles
: (Optionallist(string)
)The role(s) the policy should be applied to.
-
groups
: (Optionallist(string)
)The group(s) the policy should be applied to.
-
tags
: (Optionalmap(string)
)A map of tags that will be applied to the created IAM policy.
Default is
{}
.
Module Outputs
The following attributes are exported by the module:
-
policy
: (object(policy)
)The
aws_iam_policy
object. -
policy_attachment
: (object(policy_attachment)
)The
aws_iam_policy_attachment
object.
External Documentation
AWS Documentation
- https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html
Terraform AWS Provider Documentation
- https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy
- https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy_attachment
Module Versioning
This Module follows the principles of Semantic Versioning (SemVer).
Given a version number MAJOR.MINOR.PATCH
, we increment the:
MAJOR
version when we make incompatible changes,MINOR
version when we add functionality in a backwards compatible manner, andPATCH
version when we make backwards compatible bug fixes.
0.0.z
and 0.y.z
version
Backwards compatibility in - Backwards compatibility in versions
0.0.z
is not guaranteed whenz
is increased. (Initial development) - Backwards compatibility in versions
0.y.z
is not guaranteed wheny
is increased. (Pre-release)
About Mineiros
Mineiros is a DevOps as a Service company based in Berlin, Germany. We offer commercial support for all of our projects and encourage you to reach out if you have any questions or need help. Feel free to send us an email at hello@mineiros.io or join our Community Slack channel.
We can also help you with:
- Terraform modules for all types of infrastructure such as VPCs, Docker clusters, databases, logging and monitoring, CI, etc.
- Consulting & training on AWS, Terraform and DevOps
Reporting Issues
We use GitHub Issues to track community reported issues and missing features.
Contributing
Contributions are always encouraged and welcome! For the process of accepting changes, we use Pull Requests. If you'd like more information, please see our Contribution Guidelines.
Makefile Targets
This repository comes with a handy Makefile.
Run make help
to see details on each available target.
License
This module is licensed under the Apache License Version 2.0, January 2004. Please see LICENSE for full details.
Copyright © 2020-2022 Mineiros GmbH