Skip to content

Commit 506b84a

Browse files
committed
[plugin] allow custom terraform version
1 parent f9f18fe commit 506b84a

File tree

4 files changed

+106
-18
lines changed

4 files changed

+106
-18
lines changed

example/.fluentci/plugin/src/lib.rs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,84 @@ use fluentci_pdk::dag;
33

44
#[plugin_fn]
55
pub fn init(args: String) -> FnResult<String> {
6+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
7+
8+
if tf_version.is_empty() {
9+
tf_version = "latest".to_string();
10+
}
11+
612
let stdout = dag()
13+
.pipeline("init")?
714
.pkgx()?
8-
.with_packages(vec!["terraform"])?
9-
.with_exec(vec!["terraform", "init", &args])?
15+
.with_exec(vec![
16+
"pkgx",
17+
&format!("terraform@{}", tf_version),
18+
"init",
19+
&args,
20+
])?
1021
.stdout()?;
1122
Ok(stdout)
1223
}
1324

1425
#[plugin_fn]
1526
pub fn validate(args: String) -> FnResult<String> {
27+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
28+
29+
if tf_version.is_empty() {
30+
tf_version = "latest".to_string();
31+
}
32+
1633
let stdout = dag()
34+
.pipeline("validate")?
1735
.pkgx()?
18-
.with_packages(vec!["terraform"])?
19-
.with_exec(vec!["terraform", "validate", &args])?
36+
.with_exec(vec![
37+
"pkgx",
38+
&format!("terraform@{}", tf_version),
39+
"validate",
40+
&args,
41+
])?
2042
.stdout()?;
2143
Ok(stdout)
2244
}
2345

2446
#[plugin_fn]
2547
pub fn plan(args: String) -> FnResult<String> {
48+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
49+
50+
if tf_version.is_empty() {
51+
tf_version = "latest".to_string();
52+
}
53+
2654
let stdout = dag()
55+
.pipeline("plan")?
2756
.pkgx()?
28-
.with_packages(vec!["terraform"])?
29-
.with_exec(vec!["terraform", "plan", &args])?
57+
.with_exec(vec![
58+
"pkgx",
59+
&format!("terraform@{}", tf_version),
60+
"plan",
61+
&args,
62+
])?
3063
.stdout()?;
3164
Ok(stdout)
3265
}
3366

3467
#[plugin_fn]
3568
pub fn apply(args: String) -> FnResult<String> {
69+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
70+
71+
if tf_version.is_empty() {
72+
tf_version = "latest".to_string();
73+
}
74+
3675
let stdout = dag()
76+
.pipeline("apply")?
3777
.pkgx()?
38-
.with_packages(vec!["terraform"])?
39-
.with_exec(vec!["terraform", "apply", &args])?
78+
.with_exec(vec![
79+
"pkgx",
80+
&format!("terraform@{}", tf_version),
81+
"apply",
82+
&args,
83+
])?
4084
.stdout()?;
4185
Ok(stdout)
4286
}

plugin/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "terraform"
4-
version = "0.8.0"
4+
version = "0.8.1"
55

66
[lib]
77
crate-type = ["cdylib"]

plugin/src/lib.rs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,84 @@ use fluentci_pdk::dag;
33

44
#[plugin_fn]
55
pub fn init(args: String) -> FnResult<String> {
6+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
7+
8+
if tf_version.is_empty() {
9+
tf_version = "latest".to_string();
10+
}
11+
612
let stdout = dag()
13+
.pipeline("init")?
714
.pkgx()?
8-
.with_packages(vec!["terraform"])?
9-
.with_exec(vec!["terraform", "init", &args])?
15+
.with_exec(vec![
16+
"pkgx",
17+
&format!("terraform@{}", tf_version),
18+
"init",
19+
&args,
20+
])?
1021
.stdout()?;
1122
Ok(stdout)
1223
}
1324

1425
#[plugin_fn]
1526
pub fn validate(args: String) -> FnResult<String> {
27+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
28+
29+
if tf_version.is_empty() {
30+
tf_version = "latest".to_string();
31+
}
32+
1633
let stdout = dag()
34+
.pipeline("validate")?
1735
.pkgx()?
18-
.with_packages(vec!["terraform"])?
19-
.with_exec(vec!["terraform", "validate", &args])?
36+
.with_exec(vec![
37+
"pkgx",
38+
&format!("terraform@{}", tf_version),
39+
"validate",
40+
&args,
41+
])?
2042
.stdout()?;
2143
Ok(stdout)
2244
}
2345

2446
#[plugin_fn]
2547
pub fn plan(args: String) -> FnResult<String> {
48+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
49+
50+
if tf_version.is_empty() {
51+
tf_version = "latest".to_string();
52+
}
53+
2654
let stdout = dag()
55+
.pipeline("plan")?
2756
.pkgx()?
28-
.with_packages(vec!["terraform"])?
29-
.with_exec(vec!["terraform", "plan", &args])?
57+
.with_exec(vec![
58+
"pkgx",
59+
&format!("terraform@{}", tf_version),
60+
"plan",
61+
&args,
62+
])?
3063
.stdout()?;
3164
Ok(stdout)
3265
}
3366

3467
#[plugin_fn]
3568
pub fn apply(args: String) -> FnResult<String> {
69+
let mut tf_version = dag().get_env("TF_VERSION").unwrap_or_default();
70+
71+
if tf_version.is_empty() {
72+
tf_version = "latest".to_string();
73+
}
74+
3675
let stdout = dag()
76+
.pipeline("apply")?
3777
.pkgx()?
38-
.with_packages(vec!["terraform"])?
39-
.with_exec(vec!["terraform", "apply", &args])?
78+
.with_exec(vec![
79+
"pkgx",
80+
&format!("terraform@{}", tf_version),
81+
"apply",
82+
&args,
83+
])?
4084
.stdout()?;
4185
Ok(stdout)
4286
}

0 commit comments

Comments
 (0)