title: How do I configure AWS MFA for Terraform?
body: <p>I want to perform MFA for Terraform so it's expected to ask the 6-digit token from my virtual MFA device for every <code>terraform [command]</code>. After reading the documentation:
  <a href="http://docs.aws.amazon.com/cli/latest/userguide/cli-roles.html" rel="noreferrer">cli-roles</a>
  <a href="https://www.terraform.io/docs/enterprise/runs/multifactor-authentication.html" rel="noreferrer">terraform mfa</a>
  I created a role:</p>
  
  <pre><code>{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {
          "AWS": "arn:aws:iam::[ACCOUNT_ID]:user/testuser"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
          "Bool": {
            "aws:MultiFactorAuthPresent": "true"
          }
        }
      }
    ]
  }
  </code></pre>
  
  <p>This user is forced to use MFA by default and I have a configured virtual MFA device for him.</p>
  
  <p>~/.aws/credentials:</p>
  
  <pre><code>[default]
  ...
  
  [terraform_role]
  role_arn = arn:aws:iam::[ACCOUNT_ID]:role/terraform-test-role
  source_profile = default
  mfa_serial = arn:aws:iam::[ACCOUNT_ID]:mfa/testuser
  </code></pre>
  
  <p>in my Terraform environment I placed the following:</p>
  
  <pre><code>provider "aws" {
    profile = "terraform_role"
  }
  </code></pre>
  
  <p>But when i run <code>terraform plan</code> it throws me an error:</p>
  
  <pre><code>Error refreshing state: 1 error(s) occurred:
  
  * provider.aws: No valid credential sources found for AWS Provider.
    Please see https://terraform.io/docs/providers/aws/index.html for more information on
    providing credentials for the AWS Provider
  </code></pre>