Created
July 12, 2019 15:34
-
-
Save gh-mlfowler/43ead61ac60e9a230a0f4b29e5706d7e to your computer and use it in GitHub Desktop.
Handy piece of self contained Terraform for creating an AWS user with necessary exports for use with the CLI. Very useful for testing IAM permissions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_version = ">=0.11.0" | |
} | |
provider "aws" { | |
version = "~> 2.0" | |
} | |
resource "aws_iam_user" "user" { | |
name = "testuser" | |
} | |
resource "aws_iam_user_policy_attachment" "user" { | |
user = "${aws_iam_user.user.name}" | |
policy_arn = "${aws_iam_policy.user.arn}" | |
} | |
resource "aws_iam_access_key" "user" { | |
user = "${aws_iam_user.user.name}" | |
} | |
resource "aws_iam_policy" "user" { | |
policy = "${data.aws_iam_policy_document.user.json}" | |
} | |
data "aws_iam_policy_document" "user" { | |
statement { | |
actions = [ | |
"s3:CreateBucket", | |
"s3:DeleteBucket", | |
"s3:DeleteObject", | |
"s3:DeleteObjectVersion", | |
"s3:Get*", | |
"s3:ListBucket", | |
"s3:ListBucketVersions", | |
"s3:PutBucketVersioning", | |
"s3:PutObject", | |
] | |
resources = ["*"] | |
} | |
} | |
data "aws_region" "current" {} | |
output "exports" { | |
value = "\n\nexport AWS_ACCESS_KEY_ID='${aws_iam_access_key.user.id}'\nexport AWS_SECRET_ACCESS_KEY='${aws_iam_access_key.user.secret}'\nexport AWS_REGION=${data.aws_region.current.name}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment