Created
March 6, 2023 09:13
-
-
Save jedberg/dd31783e13521a69aa8923cb514276d8 to your computer and use it in GitHub Desktop.
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
# Configure the AWS provider | |
provider "aws" { | |
region = "us-east-1" | |
} | |
# Create the IAM admin user | |
resource "aws_iam_user" "admin" { | |
name = "admin" | |
} | |
# Create the IAM admin group | |
resource "aws_iam_group" "admins" { | |
name = "admins" | |
} | |
# Add the admin user to the admin group | |
resource "aws_iam_group_membership" "admin" { | |
name = "${aws_iam_group.admins.name}-${aws_iam_user.admin.name}" | |
users = [aws_iam_user.admin.name] | |
group = aws_iam_group.admins.name | |
} | |
# Attach admin policy to admin group | |
resource "aws_iam_policy_attachment" "admin" { | |
name = "admin" | |
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" | |
groups = [aws_iam_group.admins.name] | |
} | |
# Create the IAM Alice user | |
resource "aws_iam_user" "alice" { | |
name = "alice" | |
} | |
# Create the IAM Alice group | |
resource "aws_iam_group" "alice_group" { | |
name = "alice_group" | |
} | |
# Add the Alice user to the Alice group | |
resource "aws_iam_group_membership" "alice" { | |
name = "${aws_iam_group.alice_group.name}-${aws_iam_user.alice.name}" | |
users = [aws_iam_user.alice.name] | |
group = aws_iam_group.alice_group.name | |
} | |
# Attach policy to Alice group | |
resource "aws_iam_policy_attachment" "alice" { | |
name = "alice" | |
policy_arn = "arn:aws:iam::aws:policy/AmazonS3FullAccess" | |
groups = [aws_iam_group.alice_group.name] | |
} | |
# Create the IAM Bob user | |
resource "aws_iam_user" "bob" { | |
name = "bob" | |
} | |
# Create the IAM Bob group | |
resource "aws_iam_group" "bob_group" { | |
name = "bob_group" | |
} | |
# Add the Bob user to the Bob group | |
resource "aws_iam_group_membership" "bob" { | |
name = "${aws_iam_group.bob_group.name}-${aws_iam_user.bob.name}" | |
users = [aws_iam_user.bob.name] | |
group = aws_iam_group.bob_group.name | |
} | |
# Attach policy to Bob group | |
resource "aws_iam_policy_attachment" "bob" { | |
name = "bob" | |
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2FullAccess" | |
groups = [aws_iam_group.bob_group.name] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment