|
1 |
| -load( |
2 |
| - "//terraform/internal:terraform.bzl", |
3 |
| - "terraform_plugin", |
4 |
| - _terraform_module = "terraform_module", |
5 |
| - _terraform_workspace = "terraform_workspace", |
6 |
| -) |
7 |
| -load("//terraform/internal:test.bzl", "terraform_integration_test") |
8 |
| -load( |
9 |
| - "//terraform/internal:distribution.bzl", |
10 |
| - "terraform_distribution_publisher", |
11 |
| - "terraform_module_publisher", |
12 |
| - _terraform_distribution_dir = "terraform_distribution_dir", |
13 |
| -) |
14 |
| -load("//terraform:providers.bzl", "tf_workspace_files_prefix") |
15 |
| - |
16 |
| -def terraform_distribution_dir(name, deps, **kwargs): |
17 |
| - srcs_name = "%s.srcs-list" % name |
18 |
| - module_name = "%s.module" % name |
19 |
| - |
20 |
| - # change "relative" deps to absolute deps |
21 |
| - deps_abs = [ |
22 |
| - "//" + native.package_name() + dep if dep.startswith(":") else dep |
23 |
| - for dep in deps |
24 |
| - ] |
25 |
| - native.genquery( |
26 |
| - name = srcs_name, |
27 |
| - opts = ["--noimplicit_deps"], |
28 |
| - expression = """kind("source file", deps(set(%s)))""" % " ".join(deps_abs), |
29 |
| - scope = deps_abs, |
30 |
| - ) |
31 |
| - |
32 |
| - terraform_module( |
33 |
| - name = module_name, |
34 |
| - deps = deps_abs, |
35 |
| - ) |
36 |
| - |
37 |
| - _terraform_distribution_dir( |
38 |
| - name = name, |
39 |
| - srcs_list = ":" + srcs_name, |
40 |
| - module = ":" + module_name, |
41 |
| - **kwargs |
42 |
| - ) |
43 |
| - |
44 |
| -def _flip_modules_attr(modules): |
45 |
| - """ |
46 |
| - Translate modules attr from a 'name=>label' dict to 'label=>name' |
47 |
| - """ |
48 |
| - flipped = {} |
49 |
| - for name, label in modules.items(): |
50 |
| - if not (label.startswith("@") or label.startswith("//") or label.startswith(":")): |
51 |
| - fail("Modules are now specified as 'name=>label'", attr="modules") |
52 |
| - # append package path & workspace name as necessary |
53 |
| - abs_label = "//" + native.package_name() + label if label.startswith(":") else label |
54 |
| - abs_label = native.repository_name() + abs_label if abs_label.startswith("//") else abs_label |
55 |
| - if abs_label in flipped: |
56 |
| - fail("Modules may only be specified once (%s)" % label, attr = "modules") |
57 |
| - flipped[abs_label] = name |
58 |
| - return flipped |
59 |
| - |
60 |
| -def terraform_module(name, modules = {}, **kwargs): |
61 |
| - _terraform_module( |
62 |
| - name = name, |
63 |
| - modules = _flip_modules_attr(modules), |
64 |
| - **kwargs |
65 |
| - ) |
66 |
| - |
67 |
| -def terraform_workspace(name, modules = {}, **kwargs): |
68 |
| - _terraform_workspace( |
69 |
| - name = name, |
70 |
| - modules = _flip_modules_attr(modules), |
71 |
| - **kwargs |
72 |
| - ) |
73 |
| - |
74 |
| - # create a convenient destroy target which |
75 |
| - # CDs to the package dir and runs terraform destroy |
76 |
| - native.genrule( |
77 |
| - name = "%s.destroy" % name, |
78 |
| - outs = ["%s.destroy.sh" % name], |
79 |
| - cmd = """echo ' |
80 |
| - #!/bin/sh |
81 |
| - set -eu |
82 |
| - tf_workspace_dir="$$BUILD_WORKSPACE_DIRECTORY/{package}/{tf_workspace_files_prefix}" |
83 |
| - if [ -e "$$tf_workspace_dir" ]; then |
84 |
| - cd "$$tf_workspace_dir" |
85 |
| - exec terraform destroy "$$@" .terraform/tfroot |
86 |
| - else |
87 |
| - >&2 echo "Could not find terraform workspace dir, so there is nothing to destroy ($$tf_workspace_dir)" |
88 |
| - fi |
89 |
| - ' > $@""".format( |
90 |
| - package = native.package_name(), |
91 |
| - tf_workspace_files_prefix = tf_workspace_files_prefix(name), |
92 |
| - ), |
93 |
| - executable = True, |
94 |
| - ) |
| 1 | +load("//terraform/internal:terraform.bzl", "terraform_plugin") |
| 2 | +load("//terraform/internal:workspace.bzl", "terraform_workspace") |
| 3 | +load("//terraform/internal:module.bzl", "terraform_module") |
| 4 | +load("//terraform/internal:integration_test.bzl", "terraform_integration_test") |
0 commit comments