mineiros-io / terraform-aws-iam-policy

A Terraform module to create an Identity and Access Management (IAM) Policy on Amazon Web Services (AWS). https://aws.amazon.com/iam

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status GitHub tag (latest SemVer) Terraform Version AWS Provider Version Join Slack

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

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: (Optional bool)

    Specifies whether resources in the module will be created.

    Default is true.

  • module_tags: (Optional map(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: (Optional list(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: (Required string)

    This is a JSON formatted string representing an IAM Policy Document. (only required if policy_statements is not set)

  • policy_statements: (Required list(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: (Optional string)

    Description of the IAM policy. Forces new resource.

  • name: (Optional string)

    The name of the policy. If omitted, Terraform will assign a random, unique name. Forces new resource.

  • name_prefix: (Optional string)

    Creates a unique name beginning with the specified prefix. Forces new resource. Conflicts with name.

  • path: (Optional string)

    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 single aws_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, or aws_iam_group_policy_attachment instead. These modules and/or resources do not enforce exclusive attachment of an IAM policy.

  • attachment_name: (Optional string)

    The name of the attachment. Defaults to the name of the policy.

  • users: (Optional list(string))

    The user(s) the policy should be applied to.

  • roles: (Optional list(string))

    The role(s) the policy should be applied to.

  • groups: (Optional list(string))

    The group(s) the policy should be applied to.

  • tags: (Optional map(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

Terraform AWS Provider Documentation

Module Versioning

This Module follows the principles of Semantic Versioning (SemVer).

Given a version number MAJOR.MINOR.PATCH, we increment the:

  1. MAJOR version when we make incompatible changes,
  2. MINOR version when we add functionality in a backwards compatible manner, and
  3. PATCH version when we make backwards compatible bug fixes.

Backwards compatibility in 0.0.z and 0.y.z version

  • Backwards compatibility in versions 0.0.z is not guaranteed when z is increased. (Initial development)
  • Backwards compatibility in versions 0.y.z is not guaranteed when y 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

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

About

A Terraform module to create an Identity and Access Management (IAM) Policy on Amazon Web Services (AWS). https://aws.amazon.com/iam

License:Apache License 2.0


Languages

Language:HCL 64.5%Language:Makefile 24.2%Language:Go 11.3%