Skip to content

Commit

Permalink
Honor the org and project picked up from env (like HCPConfig)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Feb 28, 2024
1 parent 611e6c7 commit b6cc155
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion internal/pkg/profile/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 enviroment
// 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,
Expand Down

0 comments on commit b6cc155

Please sign in to comment.