Skip to content

Commit 3578fd2

Browse files
add project support
1 parent 22f4ba2 commit 3578fd2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

internal/authctx/client.go

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
const (
1616
ServerEndpointEnvVar = "TMC_ENDPOINT"
17+
ProjectIDEnvVar = "PROJECT_ID"
1718

1819
// TMC SaaS env variables.
1920
VMWCloudEndpointEnvVar = "VMW_CLOUD_ENDPOINT"
@@ -37,6 +38,7 @@ const (
3738
type TanzuContext struct {
3839
SelfManaged bool
3940
ServerEndpoint string
41+
ProjectID string
4042
SMUsername string
4143
Token string // selfmanaged password is stored here
4244
VMWCloudEndPoint string // selfmanaged odic issuer is stored here
@@ -75,6 +77,10 @@ func setup(cfg *TanzuContext) (err error) {
7577
cfg.TMCConnection.WithHost(cfg.ServerEndpoint)
7678
cfg.TMCConnection.Headers.Set("Host", cfg.ServerEndpoint)
7779

80+
if cfg.ProjectID != "" {
81+
cfg.TMCConnection.Headers.Set("X-Project-Id", cfg.ProjectID)
82+
}
83+
7884
if cfg.IsSelfManaged() {
7985
// We need to add this only for self-managed flow because the SaaS token has a longer ttl.
8086
cfg.TMCConnection.WithRefreshAuthCtx(fetchAuthHeaders)

internal/authctx/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package authctx
77

88
const (
99
endpoint = "endpoint"
10+
projectID = "project_id"
1011
vmwCloudEndpoint = "vmw_cloud_endpoint"
1112
vmwCloudAPIToken = "vmw_cloud_api_token"
1213
defaultCSPEndpoint = "console.cloud.vmware.com"

internal/authctx/helper.go

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func ProviderAuthSchema() map[string]*schema.Schema {
2525
Required: true,
2626
DefaultFunc: schema.EnvDefaultFunc(ServerEndpointEnvVar, ""),
2727
},
28+
projectID: {
29+
Type: schema.TypeString,
30+
Optional: true,
31+
DefaultFunc: schema.EnvDefaultFunc(ProjectIDEnvVar, ""),
32+
},
2833
vmwCloudEndpoint: {
2934
Type: schema.TypeString,
3035
Required: true,
@@ -131,6 +136,7 @@ func ProviderConfigureContext(_ context.Context, d *schema.ResourceData) (interf
131136
_, smAuth := d.GetOk(selfManaged)
132137

133138
config.ServerEndpoint, _ = d.Get(endpoint).(string)
139+
config.ProjectID, _ = d.Get(projectID).(string)
134140
config.VMWCloudEndPoint, _ = d.Get(vmwCloudEndpoint).(string)
135141
config.Token, _ = d.Get(vmwCloudAPIToken).(string)
136142

0 commit comments

Comments
 (0)