Skip to content

Commit

Permalink
feat: add resource & datasource vdcg
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Dec 6, 2024
1 parent fec45e0 commit 4ee2c3f
Show file tree
Hide file tree
Showing 24 changed files with 938 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changelog/867.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
`resource/cloudavenue_vdcg` - New resource to manage the virtual datacenter group. (This resource replace `cloudavenue_vdc_group`)
```

```release-note:new-data-source
`datasource/cloudavenue_vdcg` - New data source to get information about the virtual datacenter group. (This data source replace `cloudavenue_vdc_group`)
```
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@ linters-settings:
"NAT",
"VPN",
"BMS",
"SAML"
"SAML",
"VDCG"
]
33 changes: 33 additions & 0 deletions docs/data-sources/vdcg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
page_title: "cloudavenue_vdcg Data Source - cloudavenue"
subcategory: "vDC Group (Virtual Datacenter Group)"
description: |-
The cloudavenue_vdcg data source allows you to retrieve informations about an existing virtual datacenter group.
---

# cloudavenue_vdcg (Data Source)

The `cloudavenue_vdcg` data source allows you to retrieve informations about an existing virtual datacenter group.

## Example Usage

```terraform
data "cloudavenue_vdcg" "example" {
name = "example"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of the VDC Group. Ensure that one and only one attribute from this collection is set : `name`, `id`.
- `name` (String) The name of the VDC Group. Ensure that one and only one attribute from this collection is set : `name`, `id`.

### Read-Only

- `description` (String) The description of the VDC Group.
- `status` (String) The status of the VDC Group. Value must be one of : `SAVING`, `SAVED`, `CONFIGURING`, `REALIZED`, `REALIZATION_FAILED`, `DELETING`, `DELETE_FAILED`, `OBJECT_NOT_FOUND`, `UNCONFIGURED`.
- `type` (String) The type of the VDC Group. Value must be one of : `LOCAL`, `UNIVERSAL`.
- `vdc_ids` (Set of String) List of VDC IDs attached to the VDC Group.
46 changes: 46 additions & 0 deletions docs/resources/vdcg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
page_title: "cloudavenue_vdcg Resource - cloudavenue"
subcategory: "vDC Group (Virtual Datacenter Group)"
description: |-
The cloudavenue_vdcg resource allows you to manage a virtual datacenter group.
---

# cloudavenue_vdcg (Resource)

The `cloudavenue_vdcg` resource allows you to manage a virtual datacenter group.

## Example Usage

```terraform
resource "cloudavenue_vdcg" "example" {
name = "example"
vdc_ids = [
cloudavenue_vdc.example.id,
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the VDC Group.
- `vdc_ids` (Set of String) List of VDC IDs attached to the VDC Group. Set must contain at least 1 elements.

### Optional

- `description` (String) The description of the VDC Group.

### Read-Only

- `id` (String) The ID of the VDC Group.
- `status` (String) The status of the VDC Group. Value must be one of : `SAVING`, `SAVED`, `CONFIGURING`, `REALIZED`, `REALIZATION_FAILED`, `DELETING`, `DELETE_FAILED`, `OBJECT_NOT_FOUND`, `UNCONFIGURED`.
- `type` (String) The type of the VDC Group. Value must be one of : `LOCAL`, `UNIVERSAL`.

## Import

Import is supported using the following syntax:
```shell
terraform import cloudavenue_vdcg.example vdcGroupNameOrID
```
3 changes: 3 additions & 0 deletions examples/data-sources/cloudavenue_vdcg/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "cloudavenue_vdcg" "example" {
name = "example"
}
1 change: 1 addition & 0 deletions examples/resources/cloudavenue_vdcg/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import cloudavenue_vdcg.example vdcGroupNameOrID
6 changes: 6 additions & 0 deletions examples/resources/cloudavenue_vdcg/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "cloudavenue_vdcg" "example" {
name = "example"
vdc_ids = [
cloudavenue_vdc.example.id,
]
}
1 change: 1 addition & 0 deletions internal/provider/common/adminorg/vdc_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

// GetVDCGroupByNameOrID returns the VDC group using the name or ID provided in the argument.
// Deprecated: Use GetVdcGroupByName or GetVdcGroupById instead.
func (ao *AdminOrg) GetVDCGroupByNameOrID(nameOrID string) (*govcd.VdcGroup, error) {
if urn.IsVDCGroup(nameOrID) {
return ao.GetVdcGroupById(nameOrID)
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/provider_datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/storage"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vapp"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdc"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdcg"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vrf"
)
Expand Down Expand Up @@ -51,6 +52,9 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource
vdc.NewVDCDataSource,
vdc.NewGroupDataSource,

// * VDC GROUP
vdcg.NewVDCGDataSource,

// * VAPP
vapp.NewVappDataSource,
vapp.NewOrgNetworkDataSource,
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/provider_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vapp"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vcda"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdc"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdcg"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm"
)

Expand All @@ -41,6 +42,9 @@ func (p *cloudavenueProvider) Resources(_ context.Context) []func() resource.Res
vdc.NewACLResource,
vdc.NewGroupResource,

// * VDC Group
vdcg.NewVDCGResource,

// * VCDA
vcda.NewVCDAIPResource,

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/vdcg/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package vdcg

const (
categoryName = "vdcg"
)
102 changes: 102 additions & 0 deletions internal/provider/vdcg/vdcg_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package vdcg

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/diag"

"github.com/hashicorp/terraform-plugin-framework/datasource"

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/adminorg"
)

var (
_ datasource.DataSource = &vdcgDataSource{}
_ datasource.DataSourceWithConfigure = &vdcgDataSource{}
)

func NewVDCGDataSource() datasource.DataSource {
return &vdcgDataSource{}
}

type vdcgDataSource struct {
client *client.CloudAvenue
adminOrg adminorg.AdminOrg
}

func (d *vdcgDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + categoryName
}

// Init Initializes the resource.
func (d *vdcgDataSource) Init(ctx context.Context, rm *vdcgModel) (diags diag.Diagnostics) {
d.adminOrg, diags = adminorg.Init(d.client)
return
}

func (d *vdcgDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = vdcgSchema(ctx).GetDataSource(ctx)
}

func (d *vdcgDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}

client, ok := req.ProviderData.(*client.CloudAvenue)

if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
fmt.Sprintf("Expected *client.CloudAvenue, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

d.client = client
}

func (d *vdcgDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
defer metrics.New("data.cloudavenue_vdcg", d.client.GetOrgName(), metrics.Read)()

config := &vdcgModel{}

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, config)...)
if resp.Diagnostics.HasError() {
return
}
// Init the resource
resp.Diagnostics.Append(d.Init(ctx, config)...)
if resp.Diagnostics.HasError() {
return
}

/*
Implement the data source read logic here.
*/

s := &vdcgResource{
client: d.client,
adminOrg: d.adminOrg,
}

// Read data from the API
data, found, diags := s.read(ctx, config)
if !found {
resp.Diagnostics.AddError("Resource not found", fmt.Sprintf("The VDC Group %s(%s) was not found", config.Name.Get(), config.ID.Get()))
return
}
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading

0 comments on commit 4ee2c3f

Please sign in to comment.