Note: Scroll down this article to download the terrafom files in zip format. |
Terraform AWS IAM Role for EC2
This Terraform module provisions an AWS IAM Role and an associated Instance Profile. The role is configured with a custom IAM policy that grants specific permissions for EC2 and SNS services. The role is designed to be assumed by the EC2 service, making it suitable for attachment to an EC2 instance.
Resources Created
This configuration creates the following AWS resources:
aws_iam_policy.custom_permissions_policy
aws_iam_role.custom_role
aws_iam_role_policy_attachment.custom_attachment
aws_iam_instance_profile.instance_profile
Prerequisites
- Terraform installed on your local machine.
- AWS Credentials configured for your environment (e.g., via AWS CLI, environment variables).
Deployment
- Initialize Terraform:
terraform init
- (Optional) Plan the deployment:
terraform plan
- Apply the configuration:
terraform apply
You can customize the resource names and AWS region by modifying the terraform.auto.tfvars
file.
Inputs
The following input variables are defined in variables.tf
:
Name | Description | Type | Default Value |
---|---|---|---|
aws_region | The AWS region where resources will be created. | string | "us-east-1" |
policy_name | The name for the custom IAM policy. | string | "csc-EC2-Permissions-Policy" |
role_name | The name for the custom IAM role. | string | "csc-EC2-Instance-Role" |
Outputs
The following outputs will be displayed after the configuration is applied:
Name | Description |
---|---|
iam_role_name | The name of the created IAM role. |
instance_profile_name | The name of the created IAM instance profile. |