Terraform plugin development, where to specify version? best practices for go applications versioning?

时间:2017-12-02 00:31:47

标签: terraform

We developed a couple of provider plugins for terraform, we did so without specifying version. Then for our own control we started to version using ldflags at build time:

go build -ldflags '-X \"main.VersionString=#{VERSION} (#{REVISION})\"' -o '#{WS}/#{PROJECT_NAME}' main.go" 

and in the code:

package main

import(
  "github.com/hashicorp/terraform/plugin"
  ...
)

var VersionString = "unversioned"

func main(){
  if len(os.Args) == 2 && os.Args[1] == "--version" {
    fmt.Printf("Version %s\n", VersionString)
    os.Exit(0)
  }

  plugin.Serve(&plugin.ServeOpts{
    ProviderFunc: myprovider.Provider})
}

The problem is that terraform is unaware of the version, therefore we are not able to freeze version for our plugins.

What's the correct way to version custom plugins for terraform?

1 个答案:

答案 0 :(得分:1)

Terraform插件通常不知道它们在二进制文件中的版本号,而是将其声明为文件名的一部分。

例如,名为“foo”的q提供程序插件可能有一个文件名terraform-provider-foo_v1.2.0,然后告诉Terraform Core,当它找到该插件时,将其视为版本1.2.0。