Aws_ec2_instance resource property not working as per the documentation

Hello

As per the link for additional properties for resource "aws_ec2_instance" in the docs give the attribute
name for checking the monitoring status of instance but on using it it throws error as undefined method. please help

describe aws_ec2_instance(instanceid) do
its('monitoring') { should cmp "enabled"}
end

the above test throws error as "monitoring method is undefined"

what should i use?

Thanks in advance.

Hi sudhakar,
It looks like you have two issues.
First, and most importantly, you are not importing the inspec-aws resource pack as a dependency. You must do this to get access to the current methods and features documented. To include inspec-aws, add the following to your inspec.yml file:

depends:
  - name: inspec-aws
    url: https://github.com/inspec/inspec-aws/archive/master.tar.gz

This will cause your profile to rely on the new resource definitions included in the inspec-aws resource pack, and your experience will be much smoother.

Secondly, the syntax for checking the status of monitoring is:

control "my_control" do
  describe aws_ec2_instance(instance_id) do
    it { should exist } # It is recommended to perform an existence check before checking a property
    its("monitoring.state") { should cmp "enabled" }  # Note ".state"
  end
end

Happy auditing!

Thanks @cwolfe. I am beginner to this...

But appreciate your valuable response.