[jsonnet] Add vars and code_vars attributes to jsonnet_to_json to allow passing external variables to Jsonnet via --var and --code_var.

RELNOTES: [jsonnet] Add vars and code_vars attributes to jsonnet_to_json to allow passing external variables to Jsonnet via --var and --code_var.

--
MOS_MIGRATED_REVID=105305323
diff --git a/tools/build_defs/jsonnet/README.md b/tools/build_defs/jsonnet/README.md
index 6d40df7..32865a8 100644
--- a/tools/build_defs/jsonnet/README.md
+++ b/tools/build_defs/jsonnet/README.md
@@ -105,7 +105,7 @@
 ## jsonnet_to_json
 
 ```python
-jsonnet_to_json(name, src, deps, outs, multiple_outputs, imports)
+jsonnet_to_json(name, src, deps, outs, multiple_outputs, imports, vars, code_vars)
 ```
 
 <table>
@@ -204,6 +204,25 @@
         </p>
       </td>
     </tr>
+    <tr>
+      <td><code>vars</code></td>
+      <td>
+        <code>String dict, optional</code>
+        <p>
+          Map of variables to pass to jsonnet via <code>--var key=value</code>.
+        </p>
+      </td>
+    </tr>
+    <tr>
+      <td><code>code_vars</code></td>
+      <td>
+        <code>String dict, optional</code>
+        <p>
+          Map of code variables to pass to jsonnet via
+          <code>--code-var key=value</code>.
+        </p>
+      </td>
+    </tr>
   </tbody>
 </table>
 
diff --git a/tools/build_defs/jsonnet/jsonnet.bzl b/tools/build_defs/jsonnet/jsonnet.bzl
index 91f371f..2689eb7 100644
--- a/tools/build_defs/jsonnet/jsonnet.bzl
+++ b/tools/build_defs/jsonnet/jsonnet.bzl
@@ -57,6 +57,8 @@
   """Implementation of the jsonnet_to_json rule."""
   depinfo = _setup_deps(ctx.attr.deps)
   toolchain = _jsonnet_toolchain(ctx)
+  jsonnet_vars = ctx.attr.vars
+  jsonnet_code_vars = ctx.attr.code_vars
   command = (
       [
           "set -e;",
@@ -65,7 +67,11 @@
       ["-J %s/%s" % (ctx.label.package, im) for im in ctx.attr.imports] +
       ["-J %s" % im for im in depinfo.imports] +
       toolchain.imports +
-      ["-J ."])
+      ["-J ."] +
+      ["--var '%s'='%s'"
+          % (var, jsonnet_vars[var]) for var in jsonnet_vars.keys()] +
+      ["--code-var '%s'='%s'"
+          % (var, jsonnet_code_vars[var]) for var in jsonnet_vars.keys()])
 
   outputs = []
   # If multiple_outputs is set to true, then jsonnet will be invoked with the
@@ -119,9 +125,14 @@
     attrs = _jsonnet_library_attrs + _jsonnet_common_attrs,
 )
 
-_jsonnet_to_json_attrs = {
+_jsonnet_compile_attrs = {
     "src": attr.label(allow_files = JSONNET_FILETYPE,
                       single_file = True),
+    "vars": attr.string_dict(),
+    "code_vars": attr.string_dict(),
+}
+
+_jsonnet_to_json_attrs = _jsonnet_compile_attrs + {
     "outs": attr.output_list(mandatory = True),
     "multiple_outputs": attr.bool(),
 }