From 5ad9bda88813e493e83405c918097a3870e6250e Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Wed, 7 Feb 2024 10:25:40 -0800 Subject: [PATCH] Honor the org and project picked up from env (like HCPConfig) --- internal/pkg/profile/loader.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/pkg/profile/loader.go b/internal/pkg/profile/loader.go index 881e6573..55a664e0 100644 --- a/internal/pkg/profile/loader.go +++ b/internal/pkg/profile/loader.go @@ -218,8 +218,29 @@ func (l *Loader) DeleteProfile(name string) error { return nil } -// DefaultProfile returns the minimal default profile. +// These are pulled over from hcp-sdk-go. We honor the same env vars +// it does, but do it directly here. + +const ( + envVarHCPOrganizationID = "HCP_ORGANIZATION_ID" + envVarHCPProjectID = "HCP_PROJECT_ID" +) + +// DefaultProfile returns the minimal default profile. If environment +// variables related to organization and project are set, they are honored here. func (l *Loader) DefaultProfile() *Profile { + hcpOrganizationID, hcpOrganizationIDOK := os.LookupEnv(envVarHCPOrganizationID) + hcpProjectID, hcpProjectIDOK := os.LookupEnv(envVarHCPProjectID) + + if hcpOrganizationIDOK && hcpProjectIDOK { + return &Profile{ + Name: "default", + OrganizationID: hcpOrganizationID, + ProjectID: hcpProjectID, + dir: l.profilesDir, + } + } + return &Profile{ Name: "default", dir: l.profilesDir,