If you already have GnuPG installed and you have your key generated, jump to exporting the public key, otherwise follow the instructions below.
macOS
brew install gnupg
Ubuntu
sudo apt install gnupg
gpg --generate-key
Export the key and encode it with Base64.
gpg --export <public-key-id> | base64
The <public-key-id>
parameter can be found by listing all keys.
gpg --list-keys
Open the users.tf file and create a new instance of a user
module.
module "john_doe" {
source = "modules/user"
name = "john.doe"
pgp_key = "<your-exported-key>"
groups = [
aws_iam_group.self_managing.name,
module.developer_group_staging.group_name,
module.developer_group_production.group_name
]
providers = {
aws = "aws.users"
}
}
Include your user summary in the output.tf file.
output "users_summary" {
value = [
module.john_doe.summary,
]
}
Commit the changes and create a pull request for merging them into the master branch.
If your pull request was merged a new build should be triggered. Look for the build output and locate the
users_summary
section.
users_summary = [
{
"access_key_id" = "AKIAWS5GSEV382CPXLTL",
"name" = "john.doe",
"password" = "<base64-encrypted-password>",
"secret_access_key" = "<base64-encrypted-access-key>"
}
]
Decrypt the temporary password and the access key.
$ echo '<base64-encrypted-content>' | base64 -D | gpg --decrypt
Login to AWS console by clicking the link from the links
section in the build output. You are going to be asked to change your temporary password.
links = {
"aws_console_sign_in" = "https://<users-account-id>.signin.aws.amazon.com/console/"
"switch_role_production" = "https://signin.aws.amazon.com/switchrole?account=<production-account-id>&roleName=Developer&displayName=Developer%40production"
"switch_role_staging" = "https://signin.aws.amazon.com/switchrole?account=<staging-account-id>&roleName=Developer&displayName=Developer%40staging"
}
Follow the instructions on the official AWS User Guide to configure the MFA. Remember to sign-out and sign-in again to have MFA enabled.
From the links
section in the build output, click the links to switch_role_staging
and switch_role_production
. You should be able to successfully assume Developer
role on both staging
and production
accounts.
links = {
"aws_console_sign_in" = "https://<users-account-id>.signin.aws.amazon.com/console/"
"switch_role_production" = "https://signin.aws.amazon.com/switchrole?account=<production-account-id>&roleName=Developer&displayName=Developer%40production"
"switch_role_staging" = "https://signin.aws.amazon.com/switchrole?account=<staging-account-id>&roleName=Developer&displayName=Developer%40staging"
}