Created
March 5, 2025 14:28
-
-
Save jwkidd3/bd924f58ef4cca4bbe08094bb24d9bc7 to your computer and use it in GitHub Desktop.
Revisions
-
jwkidd3 created this gist
Mar 5, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ resource "aws_iam_role" "example" { name = "example-role" assume_role_policy = jsonencode({ Version = "2012-10-17", Statement = [ { Action = "sts:AssumeRole", Effect = "Allow", Principal = { Service = "ec2.amazonaws.com" # Or another service, like lambda.amazonaws.com } }, ], }) tags = { TagKey = "TagValue" } } resource "aws_iam_policy" "example" { name = "example-policy" description = "Example policy" policy = jsonencode({ Version = "2012-10-17", Statement = [ { Action = [ "s3:GetObject", "s3:ListBucket", ], Effect = "Allow", Resource = [ "arn:aws:s3:::example-bucket/*", "arn:aws:s3:::example-bucket", ], }, ], }) } resource "aws_iam_role_policy_attachment" "example" { role = aws_iam_role.example.name policy_arn = aws_iam_policy.example.arn } #Optional: Instance Profile, to use the role with EC2 instances. resource "aws_iam_instance_profile" "example" { name = "example-instance-profile" role = aws_iam_role.example.name } output "iam_role_arn" { value = aws_iam_role.example.arn } output "iam_instance_profile_arn" { value = aws_iam_instance_profile.example.arn }