Skip to content

Instantly share code, notes, and snippets.

@big-samantha
Created June 29, 2017 21:27
Show Gist options
  • Save big-samantha/85083604d51afb8731f493140a96f99a to your computer and use it in GitHub Desktop.
Save big-samantha/85083604d51afb8731f493140a96f99a to your computer and use it in GitHub Desktop.
Wrapping the AWS CLI with a defined resource type.
# modules/womply/manifests/iam_user.pp
define womply::iam_user (
String $username = $title,
) {
$create = "/usr/bin/aws iam create-user --user-name ${user}"
$check = "bash -c '/usr/bin/aws iam list-users --output text | grep ${user}'"
exec { "AWS_IAM_user-${title}":
# This command creates the user.
command => $create,
# This command is run first to check if the user exists. If it exits 0 then the creation command won't be run.
unless => $check,
}
}
# profile/manifests/whatever.pp
class profile::whatever {
# Creating a user can now be done in one line of Puppet, idempotently.
womply::iam_user { 'jane': }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment