Skip to content

Commit

Permalink
chore: cleanup org/adminorg/adminvdc common (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod authored Nov 25, 2024
1 parent 801fe32 commit 1174cfb
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 239 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.6
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.7
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339
github.com/rs/zerolog v1.33.0
github.com/thanhpk/randstr v1.0.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.6 h1:OZ3mYkp5sj+zp8SRHV3B15DtEJoAfJdUFCtiDmA7ubM=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.6/go.mod h1:CTQO1VIVFvImvmKoR4ntL3HxBi5REm6ssLzUj3kv1sc=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.7 h1:dFjSUbrE9mXjfN96zP6NLNHi7wCrcwx4fZkm/ZbaC+8=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.12.7/go.mod h1:CTQO1VIVFvImvmKoR4ntL3HxBi5REm6ssLzUj3kv1sc=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339 h1:DEKcWLGbEhu/I6kn9NAXhVCFrbPhR+Ef7oLmpLVnnPM=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339/go.mod h1:11JAFfGWVmhoT4AAORKsIC5M6nI+uDGSEOScMzavgPA=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
Expand Down
36 changes: 0 additions & 36 deletions internal/client/admin_org.go

This file was deleted.

61 changes: 0 additions & 61 deletions internal/client/admin_vdc.go

This file was deleted.

67 changes: 0 additions & 67 deletions internal/client/org.go

This file was deleted.

10 changes: 5 additions & 5 deletions internal/client/vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
// GetVDC
// return the vdc using the name provided in the argument.
// If the name is empty, it will try to use the default vdc provided in the provider.
func (c *CloudAvenue) GetVDC(vdcNamestring string) (vdc *v1.VDC, err error) {
if vdcNamestring == "" {
func (c *CloudAvenue) GetVDC(vdcName string) (vdc *v1.VDC, err error) {
if vdcName == "" {
if c.DefaultVDCExist() {
vdcNamestring = c.GetDefaultVDC()
vdcName = c.GetDefaultVDC()
} else {
return nil, fmt.Errorf("%w", ErrEmptyVDCNameProvided)
}
}

vdc, err = c.CAVSDK.V1.VDC().GetVDC(vdcNamestring)
vdc, err = c.CAVSDK.V1.VDC().GetVDC(vdcName)
if err != nil {
return nil, fmt.Errorf("%w: %s %w", ErrRetrievingVDC, vdcNamestring, err)
return nil, fmt.Errorf("%w: %s %w", ErrRetrievingVDC, vdcName, err)
}

return vdc, nil
Expand Down
24 changes: 10 additions & 14 deletions internal/provider/common/adminorg/admin_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ package adminorg
import (
"github.com/hashicorp/terraform-plugin-framework/diag"

v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
)

type AdminOrg struct {
*client.AdminOrg
*v1.AdminOrg
c *client.CloudAvenue
}

// Init.
func Init(c *client.CloudAvenue) (AdminOrg, diag.Diagnostics) {
var (
d = diag.Diagnostics{}
o = AdminOrg{
c: c,
}
err error
)

o.AdminOrg, err = c.GetAdminOrg()
func Init(c *client.CloudAvenue) (adminOrg AdminOrg, diags diag.Diagnostics) {
o, err := c.CAVSDK.V1.AdminOrg()
if err != nil {
d.AddError("Unable to get ORG", err.Error())
return o, d
diags.AddError("Unable to get ORG", err.Error())
return adminOrg, diags
}

return o, nil
return AdminOrg{
AdminOrg: o,
c: c,
}, nil
}
39 changes: 20 additions & 19 deletions internal/provider/common/adminvdc/admin_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"

v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
)

type AdminVDC struct {
*client.AdminVDC
adminOrg *client.AdminOrg
*v1.AdminVDC
adminOrg *v1.AdminOrg
}

func Init(c *client.CloudAvenue, adminvdc types.String) (AdminVDC, diag.Diagnostics) {
var (
d = diag.Diagnostics{}
opts = make([]client.GetAdminVDCOpts, 0)
v = AdminVDC{}
func Init(c *client.CloudAvenue, adminvdc types.String) (avdc AdminVDC, diags diag.Diagnostics) {
var err error

err error
)

v.adminOrg, err = c.GetAdminOrg()
avdc.adminOrg, err = c.CAVSDK.V1.AdminOrg()
if err != nil {
d.AddError("Unable to get AdminORG", err.Error())
return AdminVDC{}, d
diags.AddError("Unable to get AdminOrg", err.Error())
return AdminVDC{}, diags
}

if !adminvdc.IsNull() && !adminvdc.IsUnknown() {
opts = append(opts, client.WithAdminVDCName(adminvdc.ValueString()))
vdcName := adminvdc.ValueString()
if vdcName == "" {
if c.DefaultVDCExist() {
vdcName = c.GetDefaultVDC()
} else {
diags.AddError("Empty VDC name provided", client.ErrEmptyVDCNameProvided.Error())
return
}
}

v.AdminVDC, err = c.GetAdminVDC(opts...)
avdc.AdminVDC, err = c.CAVSDK.V1.AdminVDC().Get(vdcName)
if err != nil {
d.AddError("Unable to get AdminVDC", err.Error())
return AdminVDC{}, d
diags.AddError("Unable to get AdminVDC", err.Error())
return AdminVDC{}, diags
}

return v, nil
return avdc, nil
}
24 changes: 10 additions & 14 deletions internal/provider/common/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ package org
import (
"github.com/hashicorp/terraform-plugin-framework/diag"

v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
)

type Org struct {
*client.Org
*v1.Org
c *client.CloudAvenue
}

// Init.
func Init(c *client.CloudAvenue) (Org, diag.Diagnostics) {
var (
d = diag.Diagnostics{}
o = Org{
c: c,
}
err error
)

o.Org, err = c.GetOrg()
func Init(c *client.CloudAvenue) (org Org, diags diag.Diagnostics) {
o, err := c.CAVSDK.V1.Org()
if err != nil {
d.AddError("Unable to get ORG", err.Error())
return Org{}, d
diags.AddError("Unable to get ORG", err.Error())
return org, diags
}

return o, nil
return Org{
Org: o,
c: c,
}, nil
}
20 changes: 0 additions & 20 deletions internal/provider/common/vdc/vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@ type VDC struct {
*v1.VDC
}

/*
Schema
Optional: true
Computed: true
RequiresReplace
UseStateForUnknown
*/
func Schema() schemaR.StringAttribute {
return schemaR.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
MarkdownDescription: "(ForceNew) The name of vDC to use, optional if defined at provider level.",
}
}

/*
SuperSchema
Expand Down

0 comments on commit 1174cfb

Please sign in to comment.