10
10
terraform_dirname = os .path .join (root , 'terraform' )
11
11
tf_path = os .path .join (root , tf_filename )
12
12
tf_package_name = 'github.com/hashicorp/terraform'
13
+ plugin_patch_filename = 'plugin_patch.go'
14
+ plugin_dirname = os .path .join (root , 'go-plugin' )
15
+ plugin_patch_path = os .path .join (root , plugin_patch_filename )
16
+ plugin_package_name = 'github.com/hashicorp/go-plugin'
13
17
14
18
15
19
class BuildError (Exception ):
@@ -23,10 +27,27 @@ def build(setup_kwargs):
23
27
if not os .path .exists (os .path .join (terraform_dirname , '.git' )):
24
28
raise BuildError (f'The directory { terraform_dirname } not exists or init. '
25
29
f'Please execute `git submodule init && git submodule update` to init it.' )
30
+ if not os .path .exists (os .path .join (plugin_dirname , '.git' )):
31
+ raise BuildError (f'The directory { plugin_dirname } not exists or init. '
32
+ f'Please execute `git submodule init && git submodule update` to init it.' )
26
33
34
+ target_plugin_patch_path = os .path .join (plugin_dirname , plugin_patch_filename )
27
35
target_tf_path = os .path .join (terraform_dirname , tf_filename )
36
+ target_tf_mod_path = os .path .join (terraform_dirname , 'go.mod' )
28
37
lib_path = os .path .join (terraform_dirname , lib_filename )
29
38
header_path = os .path .join (terraform_dirname , header_filename )
39
+
40
+ # Patch go-plugin
41
+ print (' - Patching go-plugin package' )
42
+ shutil .copyfile (plugin_patch_path , target_plugin_patch_path )
43
+ with open (target_tf_mod_path ) as f :
44
+ mod_content = f .read ()
45
+ with open (target_tf_mod_path , 'w' ) as f :
46
+ modified_mod_content = f'{ mod_content } \n ' \
47
+ f'replace github.com/hashicorp/go-plugin v1.4.3 => ../go-plugin'
48
+ f .write (modified_mod_content )
49
+
50
+ # Build libterraform
30
51
shutil .copyfile (tf_path , target_tf_path )
31
52
try :
32
53
print (' - Building libterraform' )
@@ -36,9 +57,13 @@ def build(setup_kwargs):
36
57
)
37
58
shutil .move (lib_path , os .path .join (root , 'libterraform' , lib_filename ))
38
59
finally :
39
- for path in (target_tf_path , header_path , lib_path ):
60
+ # Remove external files
61
+ for path in (target_plugin_patch_path , target_tf_path , header_path , lib_path ):
40
62
if os .path .exists (path ):
41
63
os .remove (path )
64
+ # Recover go.mod
65
+ with open (target_tf_mod_path , 'w' ) as f :
66
+ f .write (mod_content )
42
67
43
68
return setup_kwargs
44
69
0 commit comments