require 'awspec'

bucket_name = attribute "bucket_name", {}
iam_group_name = attribute "iam_group_name", {}
iam_policy_document = attribute "iam_policy_document", {}
iam_policy_name = attribute "iam_policy_name", {}

control "s3_bucket_and_iam" do
  describe "the s3 bucket" do
    let :the_s3_bucket do
      s3_bucket bucket_name
    end
    describe bucket_name do
      subject do the_s3_bucket end
        it { should exist }
      end
    end

  describe "the iam group" do
    let :the_iam_group do
      iam_group iam_group_name
    end
    describe iam_group_name do
      subject do
        the_iam_group
      end
      it { should exist }
    end
  end

  describe "the iam group" do
    let :the_iam_group do
      iam_group iam_group_name
    end
    describe iam_group_name do
      subject do
        the_iam_group
      end
      it { should have_inline_policy(iam_policy_name) }
      it do
      should have_inline_policy(iam_policy_name).policy_document(iam_policy_document)
      end
    end
  end
end
