-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resource & datasource
vdcg
(#867)
- Loading branch information
Showing
24 changed files
with
938 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,5 +181,6 @@ linters-settings: | |
"NAT", | ||
"VPN", | ||
"BMS", | ||
"SAML" | ||
"SAML", | ||
"VDCG" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "cloudavenue_vdcg" "example" { | ||
name = "example" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import cloudavenue_vdcg.example vdcGroupNameOrID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package vdcg | ||
|
||
const ( | ||
categoryName = "vdcg" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)...) | ||
} |
Oops, something went wrong.