Skip to content

Commit

Permalink
Fix behaviour of metal when creating a new project
Browse files Browse the repository at this point in the history
In this PR we apply a change due to Denis Bozzato to fix a bug when
using hpegl to create a new metal project.  This is the first in an
anticipated series of fixes to metal support.  With this change, the
call to RefreshResources when creating the metal client is only issued
if the project_id is not empty. In this way metal project creation will
succeed.
  • Loading branch information
eamonnotoole committed Feb 21, 2024
1 parent cb4f545 commit 50c0c1a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions internal/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
// (C) Copyright 2020-2024 Hewlett Packard Enterprise Development LP

package client

Expand Down Expand Up @@ -49,10 +49,10 @@ func NewClientMap(ctx context.Context, d *schema.ResourceData) (map[string]inter
}

// Metal. A special case at the moment.
// Metal requires that we both initialise the client and use it to "refresh resources" before
// we hand it off to the provider code.
// In addition the Metal provider code uses a .gltform file to read the GreenLake project-id and
// portal URL.
// If a project ID is required, metal requires that we both initialise the client and use it to
// "refresh resources" before we hand it off to the provider code.
// In addition the Metal provider code uses a .gltform file to read the GreenLake project ID, space
// and portal URL.
// There are two possibilities:
// - The information needed to populate the .gltform file is provided in a hpegl metal block
// - A .gltform file is provided outside of the terraform environment
Expand All @@ -73,14 +73,16 @@ func NewClientMap(ctx context.Context, d *schema.ResourceData) (map[string]inter
}

// Now check if there is a .gltform file, if so proceed with Metal initialisation.
if _, err := gltform.GetGLConfig(); err == nil {
if cfg, err := gltform.GetGLConfig(); err == nil {
// Initialise the metal client
metalConfig, err := metal.NewConfig("", metal.WithTRF(trf))
if err != nil {
return nil, diag.Errorf("error in creating metal client: %s", err)
}
if err := metalConfig.RefreshAvailableResources(); err != nil {
return nil, diag.Errorf("error in refreshing available resources for metal: %s", err)
if cfg.ProjectID != "" {
if err := metalConfig.RefreshAvailableResources(); err != nil {
return nil, diag.Errorf("error in refreshing available resources for metal: %s", err)
}
}
c[metal.KeyForGLClientMap()] = metalConfig
}
Expand Down

0 comments on commit 50c0c1a

Please sign in to comment.