2018-01-26 20:21:49 +00:00
---
title: About the aws_iam_policy Resource
2018-02-14 01:42:39 +00:00
platform: aws
2018-01-26 20:21:49 +00:00
---
2018-02-15 04:31:56 +00:00
# aws\_iam\_policy
2018-01-26 20:21:49 +00:00
Use the `aws_iam_policy` InSpec audit resource to test properties of a single managed AWS IAM Policy.
2018-02-26 16:11:06 +00:00
A policy is an entity in AWS that, when attached to an identity or resource, defines their permissions. AWS evaluates these policies when a principal, such as a user, makes a request. Permissions in the policies determine if the request is allowed or denied.
2018-01-26 20:21:49 +00:00
2018-02-26 16:11:06 +00:00
Each IAM Policy is uniquely identified by either its policy\_name or arn.
2018-01-26 20:21:49 +00:00
<br>
## Syntax
An `aws_iam_policy` resource block identifies a policy by policy name.
# Find a policy by name
describe aws_iam_policy('AWSSupportAccess') do
it { should exist }
end
# Find a customer-managed by name
describe aws_iam_policy('customer-managed-policy') do
it { should exist }
end
# Hash syntax for policy name
describe aws_iam_policy(policy_name: 'AWSSupportAccess') do
it { should exist }
end
<br>
## Examples
The following examples show how to use this InSpec audit resource.
### Test that a policy does exist
describe aws_iam_policy('AWSSupportAccess') do
it { should exist }
end
### Test that a policy is attached to at least one entity
describe aws_iam_policy('AWSSupportAccess') do
it { should be_attached }
end
<br>
## Properties
2018-02-14 01:42:39 +00:00
* `arn`, `attachment_count`, `attached_groups`, `attached_roles`,`attached_users`, `default_version_id`
## Property Examples
2018-01-26 20:21:49 +00:00
### arn
"The ARN identifier of the specified policy. An ARN uniquely identifies the policy within AWS."
describe aws_iam_policy('AWSSupportAccess') do
its('arn') { should cmp "arn:aws:iam::aws:policy/AWSSupportAccess" }
end
2018-02-15 02:23:29 +00:00
### attachment\_count
2018-01-26 20:21:49 +00:00
2018-02-14 01:42:39 +00:00
The count of attached entities for the specified policy.
2018-01-26 20:21:49 +00:00
describe aws_iam_policy('AWSSupportAccess') do
2018-02-14 01:42:39 +00:00
its('attachment_count') { should cmp 1 }
2018-01-26 20:21:49 +00:00
end
2018-02-15 02:23:29 +00:00
### attached\_groups
2018-01-26 20:21:49 +00:00
2018-02-14 01:42:39 +00:00
The list of groupnames of the groups attached to the policy.
2018-01-26 20:21:49 +00:00
describe aws_iam_policy('AWSSupportAccess') do
2018-02-14 01:42:39 +00:00
its('attached_groups') { should include "test-group" }
2018-01-26 20:21:49 +00:00
end
2018-02-15 02:23:29 +00:00
### attached\_roles
2018-01-26 20:21:49 +00:00
2018-02-14 01:42:39 +00:00
The list of rolenames of the roles attached to the policy.
2018-01-26 20:21:49 +00:00
describe aws_iam_policy('AWSSupportAccess') do
2018-02-14 01:42:39 +00:00
its('attached_roles') { should include "test-role" }
2018-01-26 20:21:49 +00:00
end
2018-02-15 02:23:29 +00:00
### attached\_users
2018-01-26 20:21:49 +00:00
2018-02-14 01:42:39 +00:00
The list of usernames of the users attached to the policy.
2018-01-26 20:21:49 +00:00
describe aws_iam_policy('AWSSupportAccess') do
2018-02-14 01:42:39 +00:00
its('attached_users') { should include "test-user" }
2018-01-26 20:21:49 +00:00
end
2018-02-15 02:23:29 +00:00
### default\_version\_id
2018-01-26 20:21:49 +00:00
2018-02-15 02:23:29 +00:00
The 'default_version_id' value of the specified policy.
2018-01-26 20:21:49 +00:00
describe aws_iam_policy('AWSSupportAccess') do
2018-02-14 01:42:39 +00:00
its('default_version_id') { should cmp "v1" }
2018-01-26 20:21:49 +00:00
end
2018-02-14 01:42:39 +00:00
2018-01-26 20:21:49 +00:00
## Matchers
2018-02-16 03:07:18 +00:00
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-01-26 20:21:49 +00:00
2018-02-15 02:23:29 +00:00
### be\_attached
2018-01-26 20:21:49 +00:00
The test will pass if the identified policy is attached to at least one IAM user, group, or role.
describe aws_iam_policy('AWSSupportAccess') do
it { should be_attached }
end
2018-02-15 02:23:29 +00:00
### be\_attached\_to\_group(GROUPNAME)
2018-02-14 01:42:39 +00:00
The test will pass if the identified policy attached the specified group.
describe aws_iam_policy('AWSSupportAccess') do
it { should be_attached_to_group(GROUPNAME) }
end
2018-02-15 02:23:29 +00:00
### be\_attached\_to\_user(USERNAME)
2018-01-26 20:21:49 +00:00
The test will pass if the identified policy attached the specified user.
describe aws_iam_policy('AWSSupportAccess') do
it { should be_attached_to_user(USERNAME) }
end
2018-02-15 02:23:29 +00:00
### be\_attached\_to\_role(ROLENAME)
2018-01-26 20:21:49 +00:00
The test will pass if the identified policy attached the specified role.
describe aws_iam_policy('AWSSupportAccess') do
it { should be_attached_to_role(ROLENAME) }
end