Giter Club home page Giter Club logo

terraform-modules-13's Introduction

modules/assume-role

Features

  1. Define IAM user and iam assumable role
  2. Create assume role script

Module Usage

module "this" {
  source = "github.com/bigflood/terraform-modules//modules/assume-role"

  name            = "infra-dev"
  script_filename = "${path.module}/assume-role-bash.sh"

  additional_role_policy_document = jsonencode({
    "Version" = "2012-10-17",
    "Statement" = [
      {
        "Action" = [
          "iam:UpdateAssumeRolePolicy",
          "iam:CreatePolicy",
          "iam:DeletePolicy",
          "iam:CreateRole",
          "iam:DeleteRole",
          "iam:PassRole",
          "iam:AttachRolePolicy",
          "iam:DetachRolePolicy",
          "iam:CreateOpenIDConnectProvider",
          "iam:DeleteOpenIDConnectProvider",
          "iam:Tag*",
        ],
        "Effect"   = "Allow",
        "Resource" = "*"
      }
    ]
  })

  tags = {
    Terrraform  = "true"
    Environment = "dev"
  }
}

Assume role script

to run generated script, you need to enable MFA of IAM user(ex: infra-dev)

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_enable_virtual.html

Usage

$ ./assume-role.sh MFA_token

example

$ ./assume-role.sh 123456
Expiration: 2022-02-22T22:22:22Z
...

$ (AWSCLI-assume-role) aws sts get-caller-identity
{
    "UserId": "********:AWSCLI-assume-role",
    "Account": "******",
    "Arn": "arn:aws:sts::******:assumed-role/infra-dev-role/AWSCLI-assume-role"
}

$ (AWSCLI-assume-role) exit

$ aws sts get-caller-identity
{
    "UserId": "********",
    "Account": "******",
    "Arn": "arn:aws:iam::******:user/infra-dev"
}

Pre-requisites

  • terraform
  • jq
  • awscli

Inputs

Name Description Type Default Required
name Desired name for the IAM user string n/a yes
additional_role_policy_document additional policy document for assumable role string "" no
script_filename assume role script filename string "" no
max_session_duration Maximum CLI/API session duration in seconds between 3600 and 43200 number 3600 no
tags A map of tags to add to all resources. map(string) {} no

terraform-modules-13's People

Contributors

bigflood avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.