diff --git a/internal/clients/scaleway.go b/internal/clients/scaleway.go index 38400a3..dedab3d 100644 --- a/internal/clients/scaleway.go +++ b/internal/clients/scaleway.go @@ -7,12 +7,15 @@ package clients import ( "context" "encoding/json" + "fmt" + "os" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/crossplane/crossplane-runtime/pkg/resource" "github.com/pkg/errors" + "github.com/scaleway/provider-scaleway/internal/version" "github.com/crossplane/upjet/pkg/terraform" @@ -37,10 +40,10 @@ const ( // TerraformSetupBuilder builds Terraform a terraform.SetupFn function which // returns Terraform provider setup configuration -func TerraformSetupBuilder(version, providerSource, providerVersion string) terraform.SetupFn { +func TerraformSetupBuilder(tfversion, providerSource, providerVersion string) terraform.SetupFn { return func(ctx context.Context, client client.Client, mg resource.Managed) (terraform.Setup, error) { ps := terraform.Setup{ - Version: version, + Version: tfversion, Requirement: terraform.ProviderRequirement{ Source: providerSource, Version: providerVersion, @@ -89,6 +92,13 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr } } + // Set the custom user agent + userAgent := fmt.Sprintf("crossplane-provider-scaleway/%s", version.Version) + err = os.Setenv("TF_APPEND_USER_AGENT", userAgent) + if err != nil { + return ps, errors.Wrap(err, "cannot set user agent") + } + return ps, nil } } diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..c7ac359 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,4 @@ +package version + +// Version will be overridden with the current version at build time using the -X linker flag +var Version = "develop"