Skip to content

Instantly share code, notes, and snippets.

@msfidelis
Created September 4, 2024 15:47
Show Gist options
  • Save msfidelis/dde603130e8bd11b305fe51cc71e47ce to your computer and use it in GitHub Desktop.
Save msfidelis/dde603130e8bd11b305fe51cc71e47ce to your computer and use it in GitHub Desktop.
resource "aws_iam_role" "main" {
name = format("%s-instance-profile", var.project_name)
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy_attachment" "ec2_role" {
role = aws_iam_role.main.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}
resource "aws_iam_role_policy_attachment" "ec2_ssm" {
role = aws_iam_role.main.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
}
resource "aws_iam_instance_profile" "main" {
name = format("%s-instance-profile", var.project_name)
role = aws_iam_role.main.name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment