Infra & Cloud
terraform
Beginner
AWS IAM Role for EC2
Terraform resource to create an IAM role with instance profile for EC2.
terraform
resource "aws_iam_role" "ec2" {
name = "myapp-ec2-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{ Action = "sts:AssumeRole", Effect = "Allow", Principal = { Service = "ec2.amazonaws.com" } }]
})
}
resource "aws_iam_instance_profile" "ec2" {
name = "myapp-profile"
role = aws_iam_role.ec2.name
}
Prerequisites
- terraform >= 1.0
- AWS provider
Pro Tips
- → Attach policies with aws_iam_role_policy_attachment.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- terraform
- Level
- Beginner
- Read time
- 3 min
- Published
- Dec 2024
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
AWS S3 Static Website
Terraform module to provision an S3 bucket for static website hosting.
terraform
·
Intermediate
AWS RDS Postgres Terraform
Terraform resource for an RDS PostgreSQL instance with encryption and backup.
terraform
·
Intermediate
ECS Task Force Stop
Force-stop all running ECS tasks in a service for emergency rollback.
bash
·
Intermediate