Skip to main content

opa_api resource

Use the opa_api Chef InSpec audit resource to query Open Policy Agent (OPA) using the OPA URL and data.



This resource is distributed with Chef InSpec and is automatically available for use.


An opa_api resource block declares OPA policy configurations that can be tested.

describe opa_api(url: "localhost:8181/v1/data/example/violation", data: "input.json") do
  its(["result"]) { should eq 'value' }


  • 'url' specifies the url of the OPA server on which OPA is running.
  • 'data' specifies the json formatted data or json file.
  • its(["returned_result"]) { should eq 'expected_result' } compares the results of the query against the expected result in the test.


The opa_api resource InSpec resource requires a url and data as a JSON file or a string in JSON format.

url (required)

The URL of the OPA API server.

data (required)

An OPA query as a JSON data file or a string in JSON format.



The result property checks whether the resource query returns an empty result.

its('result') { should be nil }


The allow property checks if a specific input matches the policy defined in OPA. This matcher will not work if allow is not defined in the policy file.

its('allow') { should eq 'value' }


The following examples show how to use this Chef InSpec audit resource.

describe opa_api(url: "localhost:8181/v1/data/example/allow", data: "input.json") do
  its("result") { shoule_not be nil }
  its(["result"]) { should eq true }
  its("allow") { should eq "true" }

The above example shows how the allow value can be fetched in two ways.


For a full list of available matchers, see our Universal Matchers page.
Edit this page on GitHub

Thank you for your feedback!


Search Results