Skip to content

Commit

Permalink
Merge pull request #204 from HPE/metal-fix-1
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnotoole authored Feb 21, 2024
2 parents cb4f545 + 50c0c1a commit 20555fd
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 20555fd

Please sign in to comment.