diff --git a/go.mod b/go.mod index 3899479b..56019061 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 679486ba..c5490703 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/client/admin_org.go b/internal/client/admin_org.go deleted file mode 100644 index ff6a1a55..00000000 --- a/internal/client/admin_org.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/vmware/go-vcloud-director/v2/govcd" - govcdtypes "github.com/vmware/go-vcloud-director/v2/types/v56" -) - -type AdminOrg struct { - *govcd.AdminOrg -} - -// GetAdminOrg return the admin org using the name provided in the provider. -func (c *CloudAvenue) GetAdminOrg() (*AdminOrg, error) { - x, err := c.Vmware.GetAdminOrgByNameOrId(c.GetOrgName()) - if err != nil { - return nil, fmt.Errorf("%w: %w", ErrRetrievingOrg, err) - } - - return &AdminOrg{x}, nil -} - -/* -ListCatalogs - -Get the catalogs list from the admin org. -*/ -func (ao *AdminOrg) ListCatalogs() *govcdtypes.CatalogsList { - return ao.AdminOrg.AdminOrg.Catalogs -} - -// GetOrgVAppLeaseSettings retrieves the lease settings for a vApp in the specified organization. -func (ao *AdminOrg) GetOrgVAppLeaseSettings() *govcdtypes.VAppLeaseSettings { - return ao.AdminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings -} diff --git a/internal/client/admin_vdc.go b/internal/client/admin_vdc.go deleted file mode 100644 index ea646417..00000000 --- a/internal/client/admin_vdc.go +++ /dev/null @@ -1,61 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/vmware/go-vcloud-director/v2/govcd" -) - -type AdminVDC struct { - name string - *govcd.AdminVdc -} - -func (c *CloudAvenue) DefaultAdminVDCExist() bool { - return c.DefaultVDCExist() -} - -type GetAdminVDCOpts func(*AdminVDC) - -func WithAdminVDCName(name string) GetAdminVDCOpts { - return func(AdminVdc *AdminVDC) { - AdminVdc.name = name - } -} - -func (v AdminVDC) GetName() string { - return v.AdminVdc.AdminVdc.Name -} - -func (v AdminVDC) GetID() string { - return v.AdminVdc.AdminVdc.ID -} - -// GetAdminVdc return the admin vdc using the name provided in the provider. -func (c CloudAvenue) GetAdminVDC(opts ...GetAdminVDCOpts) (*AdminVDC, error) { - v := &AdminVDC{} - - for _, opt := range opts { - opt(v) - } - - if v.name == "" { - if c.DefaultVDCExist() { - v.name = c.GetDefaultVDC() - } else { - return nil, fmt.Errorf("%w", ErrEmptyVDCNameProvided) - } - } - - org, err := c.GetAdminOrg() - if err != nil { - return nil, fmt.Errorf("%w: %w", ErrRetrievingOrgAdmin, err) - } - - v.AdminVdc, err = org.GetAdminVDCByName(v.name, false) - if err != nil { - return nil, fmt.Errorf("%w: %s %w", ErrRetrievingAdminVDC, v.name, err) - } - - return v, nil -} diff --git a/internal/client/org.go b/internal/client/org.go deleted file mode 100644 index d27402cd..00000000 --- a/internal/client/org.go +++ /dev/null @@ -1,67 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/vmware/go-vcloud-director/v2/govcd" - govcdtypes "github.com/vmware/go-vcloud-director/v2/types/v56" -) - -type Org struct { - *govcd.Org -} - -// Returns the name of the organization. -func (o *Org) GetName() string { - return o.Org.Org.Name -} - -// Returns the ID of the organization. -func (o *Org) GetID() string { - return o.Org.Org.ID -} - -// GetNetworkDHCP returns the DHCP object for the org network provided in parameter. -func (o *Org) GetNetworkDHCP(orgNetworkID string) (*govcd.OpenApiOrgVdcNetworkDhcp, error) { - if err := o.Refresh(); err != nil { - return nil, err - } - - orgNetwork, err := o.GetOpenApiOrgVdcNetworkById(orgNetworkID) - if err != nil { - return nil, err - } - - return orgNetwork.GetOpenApiOrgVdcNetworkDhcp() -} - -// UpdateNetworkDHCP updates the DHCP object for the org network provided in parameter. -func (o *Org) UpdateNetworkDHCP(orgNetworkID string, dhcpParameters *govcdtypes.OpenApiOrgVdcNetworkDhcp) error { - orgNetwork, err := o.GetOpenApiOrgVdcNetworkById(orgNetworkID) - if err != nil { - return err - } - - _, err = orgNetwork.UpdateDhcp(dhcpParameters) - return err -} - -// DeleteNetworkDHCP deletes the DHCP object for the org network provided in parameter. -func (o *Org) DeleteNetworkDHCP(orgNetworkID string) error { - orgNetwork, err := o.GetOpenApiOrgVdcNetworkById(orgNetworkID) - if err != nil { - return err - } - - return orgNetwork.DeletNetworkDhcp() -} - -// GetOrg return the org using the name provided in the provider. -func (c *CloudAvenue) GetOrg() (*Org, error) { - x, err := c.Vmware.GetOrgByName(c.GetOrgName()) - if err != nil { - return nil, fmt.Errorf("%w: %w", ErrRetrievingOrg, err) - } - - return &Org{x}, nil -} diff --git a/internal/client/vdc.go b/internal/client/vdc.go index 3b694778..2014f431 100644 --- a/internal/client/vdc.go +++ b/internal/client/vdc.go @@ -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 diff --git a/internal/provider/common/adminorg/admin_org.go b/internal/provider/common/adminorg/admin_org.go index 03db3807..b0a41756 100644 --- a/internal/provider/common/adminorg/admin_org.go +++ b/internal/provider/common/adminorg/admin_org.go @@ -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 } diff --git a/internal/provider/common/adminvdc/admin_vdc.go b/internal/provider/common/adminvdc/admin_vdc.go index b5b3a404..a6a71959 100644 --- a/internal/provider/common/adminvdc/admin_vdc.go +++ b/internal/provider/common/adminvdc/admin_vdc.go @@ -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 } diff --git a/internal/provider/common/org/org.go b/internal/provider/common/org/org.go index c519c87f..49ad44d2 100644 --- a/internal/provider/common/org/org.go +++ b/internal/provider/common/org/org.go @@ -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 } diff --git a/internal/provider/common/vdc/vdc.go b/internal/provider/common/vdc/vdc.go index 18e86a27..de6ea8b9 100644 --- a/internal/provider/common/vdc/vdc.go +++ b/internal/provider/common/vdc/vdc.go @@ -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