Skip to content

Commit

Permalink
feat: add support for custom user agent (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
yfodil authored Apr 26, 2024
1 parent a2d0d77 commit 76830c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/clients/scaleway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 76830c3

Please sign in to comment.