Skip to content

Instantly share code, notes, and snippets.

@bmwitcher
Created October 19, 2020 21:24
Show Gist options
  • Save bmwitcher/5e6d1b4a0b7a629f311a6d90e227676c to your computer and use it in GitHub Desktop.
Save bmwitcher/5e6d1b4a0b7a629f311a6d90e227676c to your computer and use it in GitHub Desktop.
creating iam roles, polcies, and attachemts for vpc endpoint lab
resource "aws_iam_role" "ec2_s3_access_role" {
name = "ec2-s3"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_instance_profile" "ec2profile" {
name = "ec2profile"
role = aws_iam_role.ec2_s3_access_role.name
}
resource "aws_iam_policy" "policy" {
name = "ec2_S3policy"
description = "Access to s3 policy from ec2"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "ec2-attach" {
role = aws_iam_role.ec2_s3_access_role.name
policy_arn = aws_iam_policy.policy.arn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment