Skip to content

Commit 5261c42

Browse files
ccushingcodycushing
authored andcommitted
Emit plugin version number to debug output
* printed in all verbose terraform execution `TF_LOG=DEBUG terraform apply` * printed when running `terraform-provider-baremetal` plugin directly
1 parent c9d8d56 commit 5261c42

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ test_acceptance:
2121
build:
2222
go build -o terraform-provider-baremetal
2323

24-
cross: test_acceptance
24+
version:
25+
sed -i '' -e 's/version = ".*"/version = "\
26+
$(shell curl -s https://api.github.com/repos/oracle/terraform-provider-baremetal/releases/latest | \
27+
jq -r '.tag_name')\
28+
"/g' version.go
29+
30+
release: version test_acceptance
2531
gox -output "./bin/{{.OS}}_{{.Arch}}/terraform-provider-baremetal"
2632

2733
zip:
@@ -32,4 +38,4 @@ zip:
3238
&& tar -czvf linux.tar.gz linux_386 linux_amd64 linux_arm \
3339
&& tar -czvf openbsd.tar.gz openbsd_386 openbsd_amd64
3440

35-
.PHONY: clean fmt build cross test test_unit zip
41+
.PHONY: clean fmt build release test test_unit zip version

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
func main() {
11+
printVersion()
12+
1113
plugin.Serve(&plugin.ServeOpts{
1214
ProviderFunc: func() terraform.ResourceProvider {
1315
return Provider(providerConfig)

version.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"strconv"
6+
"strings"
7+
)
8+
9+
// Current public release available on github, overwritten as build step, do not alter, see Makefile
10+
const version = "v0.0.0"
11+
12+
func printVersion() {
13+
// increment build number programatically since this will be the next public release
14+
strs := strings.Split(version, ".")
15+
build, _ := strconv.ParseInt(strs[2], 10, 64)
16+
strs[2] = strconv.FormatInt(build+1, 10)
17+
log.Printf("[INFO] terraform-provider-baremetal %s\n", strings.Join(strs, "."))
18+
}

0 commit comments

Comments
 (0)