Skip to content

Commit 40592d4

Browse files
authored
Merge pull request #8 from haodeon/feat/0.7.0
Update terraform to 1.6.6
2 parents 4b9eae5 + 9407148 commit 40592d4

File tree

12 files changed

+84
-16
lines changed

12 files changed

+84
-16
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
- name: Check out repository code
1717
uses: actions/checkout@v2
1818
- name: Set up GoLang
19-
uses: actions/setup-go@v2
19+
uses: actions/setup-go@v4
2020
with:
21-
go-version: '1.18'
21+
go-version: '^1.21.5'
2222
- name: Set up Python ${{ matrix.python-version }}
2323
uses: actions/setup-python@v2
2424
with:

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
- name: Check out repository code
1414
uses: actions/checkout@v2
1515
- name: Set up GoLang
16-
uses: actions/setup-go@v2
16+
uses: actions/setup-go@v4
1717
with:
18-
go-version: '1.18'
18+
go-version: '^1.21.5'
1919
- name: Set up Python ${{ matrix.python-version }}
2020
uses: actions/setup-python@v2
2121
with:

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ dict_keys(['time_sleep.wait1', 'time_sleep.wait2'])
8989

9090
| libterraform | Terraform |
9191
|-------------------------------------------------------|-------------------------------------------------------------|
92+
| [0.7.0](https://pypi.org/project/libterraform/0.7.0/) | [1.6.6](https://github.com/hashicorp/terraform/tree/v1.6.6) |
9293
| [0.6.0](https://pypi.org/project/libterraform/0.6.0/) | [1.5.7](https://github.com/hashicorp/terraform/tree/v1.5.7) |
9394
| [0.5.0](https://pypi.org/project/libterraform/0.5.0/) | [1.3.0](https://github.com/hashicorp/terraform/tree/v1.3.0) |
9495
| [0.4.0](https://pypi.org/project/libterraform/0.4.0/) | [1.2.2](https://github.com/hashicorp/terraform/tree/v1.2.2) |
@@ -98,7 +99,7 @@ dict_keys(['time_sleep.wait1', 'time_sleep.wait2'])
9899

99100
If you want to develop this library, should first prepare the following environments:
100101

101-
- [GoLang](https://go.dev/dl/) (Version 1.18+)
102+
- [GoLang](https://go.dev/dl/) (Version 1.21.5+)
102103
- [Python](https://www.python.org/downloads/) (Version 3.7~3.11)
103104
- GCC
104105

build.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def build(setup_kwargs):
5252
try:
5353
print(' - Building libterraform')
5454
subprocess.check_call(
55-
['go', 'build', '-buildmode=c-shared', f'-o={lib_filename}', tf_package_name],
55+
['go', 'build', '-buildmode=c-shared', f'-o={lib_filename}',
56+
"-ldflags", "-X github.com/hashicorp/terraform/version.dev=no", tf_package_name],
5657
cwd=terraform_dirname
5758
)
5859
shutil.move(lib_path, os.path.join(root, 'libterraform', lib_filename))

libterraform.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
7+
"github.com/apparentlymart/go-shquot/shquot"
68
"github.com/hashicorp/go-plugin"
79
svchost "github.com/hashicorp/terraform-svchost"
810
"github.com/hashicorp/terraform-svchost/disco"
@@ -23,6 +25,7 @@ import (
2325
"github.com/hashicorp/terraform/version"
2426
"github.com/mitchellh/cli"
2527
"github.com/mitchellh/colorstring"
28+
"go.opentelemetry.io/otel/trace"
2629
"log"
2730
"os"
2831
"os/signal"
@@ -100,6 +103,24 @@ func RunCli(cArgc C.int, cArgv **C.char, cStdOutFd C.int, cStdErrFd C.int) C.int
100103
}
101104
}()
102105

106+
err = openTelemetryInit()
107+
if err != nil {
108+
// openTelemetryInit can only fail if Terraform was run with an
109+
// explicit environment variable to enable telemetry collection,
110+
// so in typical use we cannot get here.
111+
Ui.Error(fmt.Sprintf("Could not initialize telemetry: %s", err))
112+
Ui.Error(fmt.Sprintf("Unset environment variable %s if you don't intend to collect telemetry from Terraform.", openTelemetryExporterEnvVar))
113+
return 1
114+
}
115+
var ctx context.Context
116+
var otelSpan trace.Span
117+
{
118+
// At minimum we emit a span covering the entire command execution.
119+
_, displayArgs := shquot.POSIXShellSplit(os.Args)
120+
ctx, otelSpan = tracer.Start(context.Background(), fmt.Sprintf("terraform %s", displayArgs))
121+
defer otelSpan.End()
122+
}
123+
103124
tmpLogPath := os.Getenv(envTmpLogPath)
104125
if tmpLogPath != "" {
105126
f, err := os.OpenFile(tmpLogPath, os.O_RDWR|os.O_APPEND, 0666)
@@ -262,7 +283,7 @@ func RunCli(cArgc C.int, cArgv **C.char, cStdOutFd C.int, cStdErrFd C.int) C.int
262283
commands := NewCommands(meta)
263284

264285
// Run checkpoint
265-
go runCheckpoint(config)
286+
go runCheckpoint(ctx, config)
266287

267288
// Make sure we clean up any managed plugins at the end of this
268289
defer func() {

libterraform/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ctypes import cdll, c_void_p
33
from libterraform.common import WINDOWS
44

5-
__version__ = '0.6.0'
5+
__version__ = '0.7.0'
66

77
root = os.path.dirname(os.path.abspath(__file__))
88
_lib_filename = 'libterraform.dll' if WINDOWS else 'libterraform.so'

libterraform/cli.py

+3
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ def untaint(
14521452
def test(
14531453
self,
14541454
check: bool = False,
1455+
vars: dict = None,
14551456
no_color: bool = True,
14561457
compact_warnings: bool = None,
14571458
junit_xml: str = None,
@@ -1508,6 +1509,7 @@ def test(
15081509
able to write but that were difficult to model in some way.
15091510
15101511
:param check: Whether to check return code.
1512+
:param vars: Set variables in the root module of the configuration.
15111513
:param no_color: True to output not contain any color.
15121514
:param compact_warnings: Use a more compact representation for warnings, if
15131515
this command produces only warnings and no errors.
@@ -1519,6 +1521,7 @@ def test(
15191521
:param options: More command options.
15201522
"""
15211523
options.update(
1524+
var=vars,
15221525
no_color=flag(no_color),
15231526
compact_warnings=flag(compact_warnings),
15241527
junit_xml=junit_xml,

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "libterraform"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
description = "Python binding for Terraform."
55
authors = ["Prodesire <[email protected]>"]
66
license = "MIT"

terraform

Submodule terraform updated 1778 files

tests/cli/test_test.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1+
import os.path
2+
13
from libterraform import TerraformCommand
4+
from tests.consts import TF_SLEEP2_DIR
25

36

47
class TestTerraformCommandTest:
58
def test_test(self, cli: TerraformCommand):
69
r = cli.test()
710
assert r.retcode == 0, r.error
8-
assert 'The "terraform test" command is experimental' in r.value
9-
assert 'No tests defined' in r.error
11+
assert "Success! 0 passed, 0 failed." in r.value
12+
assert "".__eq__(r.error)
13+
14+
def test_test_run(self):
15+
cwd = TF_SLEEP2_DIR
16+
tf = os.path.join(cwd, ".terraform")
17+
18+
cli = TerraformCommand(cwd)
19+
if not os.path.exists(tf):
20+
cli.init()
21+
r = cli.test()
22+
assert r.retcode == 0, r.error
23+
assert "Success! 1 passed, 0 failed." in r.value
24+
25+
def test_test_assertion_error(self):
26+
cwd = TF_SLEEP2_DIR
27+
tf = os.path.join(cwd, ".terraform")
28+
29+
cli = TerraformCommand(cwd)
30+
if not os.path.exists(tf):
31+
cli.init()
32+
r = cli.test(vars={"sleep2_time1": "2s"})
33+
assert r.retcode == 1
34+
assert "libterraform test success!" in r.error

tests/tf/sleep2/main.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ variable "sleep2_time2" {
99
}
1010

1111
resource "time_sleep" "sleep2_wait1" {
12-
create_duration = var.time1
12+
create_duration = var.sleep2_time1
1313
}
1414

1515
resource "time_sleep" "sleep2_wait2" {
16-
create_duration = var.time2
16+
create_duration = var.sleep2_time2
1717
}
1818

1919
output "sleep2_wait1_id" {
20-
value = time_sleep.wait1.id
20+
value = time_sleep.sleep2_wait1.id
2121
}
2222

2323
output "sleep2_wait2_id" {
24-
value = time_sleep.wait2.id
24+
value = time_sleep.sleep2_wait2.id
2525
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variables {
2+
sleep2_time2 = "2s"
3+
}
4+
5+
run "valid_sleep_duration" {
6+
7+
assert {
8+
condition = time_sleep.sleep2_wait1.create_duration == "1s"
9+
error_message = "libterraform test success!"
10+
}
11+
12+
assert {
13+
condition = time_sleep.sleep2_wait2.create_duration == "2s"
14+
error_message = "Duration did not match expected"
15+
}
16+
17+
}

0 commit comments

Comments
 (0)