Created
November 4, 2018 12:40
-
-
Save mlabouardy/f7d82f76695b73cd2390ca06146fb8fe to your computer and use it in GitHub Desktop.
IAM instance profile with S3 and Lambda permissions
This file contains hidden or 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
| // Jenkins slave instance profile | |
| resource "aws_iam_instance_profile" "worker_profile" { | |
| name = "JenkinsWorkerProfile" | |
| role = "${aws_iam_role.worker_role.name}" | |
| } | |
| resource "aws_iam_role" "worker_role" { | |
| name = "JenkinsBuildRole" | |
| path = "/" | |
| assume_role_policy = <<EOF | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": "sts:AssumeRole", | |
| "Principal": { | |
| "Service": "ec2.amazonaws.com" | |
| }, | |
| "Effect": "Allow", | |
| "Sid": "" | |
| } | |
| ] | |
| } | |
| EOF | |
| } | |
| resource "aws_iam_policy" "s3_policy" { | |
| name = "PushToS3Policy" | |
| path = "/" | |
| policy = <<EOF | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": [ | |
| "s3:PutObject", | |
| "s3:GetObject" | |
| ], | |
| "Effect": "Allow", | |
| "Resource": "${aws_s3_bucket.bucket.arn}/*" | |
| } | |
| ] | |
| } | |
| EOF | |
| } | |
| resource "aws_iam_policy" "lambda_policy" { | |
| name = "DeployLambdaPolicy" | |
| path = "/" | |
| policy = <<EOF | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": [ | |
| "lambda:UpdateFunctionCode", | |
| "lambda:PublishVersion", | |
| "lambda:UpdateAlias" | |
| ], | |
| "Effect": "Allow", | |
| "Resource": "*" | |
| } | |
| ] | |
| } | |
| EOF | |
| } | |
| resource "aws_iam_role_policy_attachment" "worker_s3_attachment" { | |
| role = "${aws_iam_role.worker_role.name}" | |
| policy_arn = "${aws_iam_policy.s3_policy.arn}" | |
| } | |
| resource "aws_iam_role_policy_attachment" "worker_lambda_attachment" { | |
| role = "${aws_iam_role.worker_role.name}" | |
| policy_arn = "${aws_iam_policy.lambda_policy.arn}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment