Skip to content

Ensure IAM instance roles are used for AWS resource access from instances

AWS access from within AWS instances can be done by either encoding AWS keys into AWS API calls or by assigning the instance to a role which has an appropriate permissions policy for the required access. "AWS Access" means accessing the APIs of AWS in order to access AWS resources or manage AWS account resources.

How to fix

Attribute iam_instance_profile of aws_instance must be non-empty.

Implementation options

Choose the option that matches how you manage Terraform. All options satisfy this control.

Use the compliance.tf registry module to get this control enforced by default. This control is mapped to the frameworks shown in the tabs above. To begin, see get started with compliance.tf.

module "ec2_instance" {
  source  = "cisv500.compliance.tf/terraform-aws-modules/ec2-instance/aws"
  version = ">=6.0.0"

  instance_type = "t3.nano"
  subnet_id     = "subnet-abc123"
}
module "ec2_instance" {
  source  = "cisv600.compliance.tf/terraform-aws-modules/ec2-instance/aws"
  version = ">=6.0.0"

  instance_type = "t3.nano"
  subnet_id     = "subnet-abc123"
}

Option 2: Open source module (terraform-aws-modules)

If you use terraform-aws-modules/ec2-instance/aws, configure the required module inputs to satisfy this control. You can later migrate to the compliance.tf module with minimal changes because it is compatible by design.

module "ec2_instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = ">=6.0.0"

  instance_type = "t3.nano"
  subnet_id     = "subnet-abc123"
}

Option 3: Terraform AWS provider resources

If you manage resources directly, configure the relevant Terraform AWS provider resources to meet this control. See docs for the resources involved: aws_instance.

resource "aws_instance" "this" {
  ami                    = "ami-abc12345"
  instance_type          = "t4g.nano"
  subnet_id              = element(["subnet-abc123", "subnet-def456"], 0)
  vpc_security_group_ids = ["sg-abc12345"]
}
Which option should I choose?
  • Compliance.tf module (recommended): controls enforced by default and mapped to frameworks.
  • Open source module (terraform-aws-modules): compatible by design with compliance.tf. Same variable names for an easy, low-change migration path when you are ready.
  • Terraform AWS provider resources: manage Terraform resources directly.

Tool mappings

Use these identifiers to cross-reference this control across tools, reports, and evidence.

  • Compliance.tf (CTF) Control: ec2_instance_using_iam_instance_role

  • Powerpipe Controls: aws_compliance.control.cis_v500_1_17, aws_compliance.control.cis_v600_2_17, aws_compliance.control.ec2_instance_using_iam_instance_role