Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for custom user agent #60

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading