Skip to content

Commit

Permalink
Update metal client initialisation to use GLP workspace and role (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnotoole authored May 30, 2024
1 parent 7ffec69 commit ab7da5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.19.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/hewlettpackard/hpegl-metal-terraform-resources v1.3.54
github.com/hewlettpackard/hpegl-provider-lib v0.0.15
github.com/hewlettpackard/hpegl-provider-lib v0.0.16
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ github.com/hewlettpackard/hpegl-metal-client v1.5.13 h1:c4Gb9Gu449LmN0eoDVTwGgkg
github.com/hewlettpackard/hpegl-metal-client v1.5.13/go.mod h1:E72/o32a5WwVAUhXvXEUKZOGiSA84hsTS+xezFqtbgU=
github.com/hewlettpackard/hpegl-metal-terraform-resources v1.3.54 h1:kJGLQlrqi1VxXkGvvyclt8EST38mV0WQ/+VkQh10X14=
github.com/hewlettpackard/hpegl-metal-terraform-resources v1.3.54/go.mod h1:q1rzaxEJL+9K3/E8NzFzBq9POxOYr4kU1ePSPKJufI8=
github.com/hewlettpackard/hpegl-provider-lib v0.0.15 h1:yDqJNUYDq37LjpwoqvNKv2RS2s5gCEL+qQ3MD0WXIdw=
github.com/hewlettpackard/hpegl-provider-lib v0.0.15/go.mod h1:9lEPIb9rKqxZNPkwcgRN+3/rAkpyXCk3KR8GFO5xaZ4=
github.com/hewlettpackard/hpegl-provider-lib v0.0.16 h1:d2Thflf2n4Ew+R/GbMjOuMbxVY1CJjs3htX//qTEdFg=
github.com/hewlettpackard/hpegl-provider-lib v0.0.16/go.mod h1:9lEPIb9rKqxZNPkwcgRN+3/rAkpyXCk3KR8GFO5xaZ4=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
Expand Down
13 changes: 12 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ 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 cfg, err := gltform.GetGLConfig(); err == nil {
// Initialise the metal client
metalConfig, err := metal.NewConfig("", metal.WithTRF(trf))
metalConfig, err := createMetalConfig(cfg, trf)
if err != nil {
return nil, diag.Errorf("error in creating metal client: %s", err)
}
// Refresh available resources if project ID is provided
if cfg.ProjectID != "" {
if err := metalConfig.RefreshAvailableResources(); err != nil {
return nil, diag.Errorf("error in refreshing available resources for metal: %s", err)
Expand All @@ -89,3 +90,13 @@ func NewClientMap(ctx context.Context, d *schema.ResourceData) (map[string]inter

return c, nil
}

// createMetalConfig creates a metal config
func createMetalConfig(cfg *gltform.Gljwt, trf retrieve.TokenRetrieveFuncCtx) (*metal.Config, error) {
// If GLP role and workspace are provided, use them
if cfg.GLPRole != "" && cfg.GLPWorkspace != "" {
return metal.NewConfig("", metal.WithTRF(trf), metal.WithRole(cfg.GLPRole), metal.WithWorkspace(cfg.GLPWorkspace))
}

return metal.NewConfig("", metal.WithTRF(trf))
}

0 comments on commit ab7da5c

Please sign in to comment.