Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vdc): change datasource schema #35

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions docs/data-sources/vdc.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "cloudavenue_vdc Data Source - cloudavenue"
subcategory: ""
description: |-
Show the vDC details.
Provides a Cloud Avenue Organization VDC data source. An Organization VDC can be used to reference a VDC and use its data within other resources or data sources.
---

# cloudavenue_vdc (Data Source)

Show the vDC details.
Provides a Cloud Avenue Organization VDC data source. An Organization VDC can be used to reference a VDC and use its data within other resources or data sources.

## Example Usage

Expand All @@ -27,37 +27,36 @@ output "example" {

### Required

- `name` (String) VDC name.
- `name` (String) The name of the org VDC. It must be unique in the organization.
The length must be between 2 and 27 characters.

### Read-Only

- `id` (String) The ID of this resource.
- `vdc` (Attributes) VDC details. (see [below for nested schema](#nestedatt--vdc))
- `vdc_group` (String)

<a id="nestedatt--vdc"></a>
### Nested Schema for `vdc`

Read-Only:

- `cpu_allocated` (Number) VDC CPU allocated.
- `description` (String) VDC UUID.
- `memory_allocated` (Number) VDC memory allocated.
- `name` (String) VDC name.
- `vcpu_in_mhz2` (Number) VDC CPU in Mhz2.
- `vdc_billing_model` (String) VDC billing model.
- `vdc_disponibility_class` (String) VDC disponibility class.
- `vdc_service_class` (String) VDC service class.
- `vdc_storage_billing_model` (String) VDC storage billing model.
- `vdc_storage_profiles` (Attributes List) VDC storage profiles. (see [below for nested schema](#nestedatt--vdc--vdc_storage_profiles))

<a id="nestedatt--vdc--vdc_storage_profiles"></a>
### Nested Schema for `vdc.vdc_storage_profiles`
- `billing_model` (String) Choose Billing model of compute resources. It can be `PAYG`, `DRAAS` or `RESERVED`.
- `cpu_allocated` (Number) CPU capacity in *MHz* that is committed to be available or used as a limit in PAYG mode.
It must be at least 5 * `cpu_speed_in_mhz` and at most 200 * `cpu_speed_in_mhz`.
*Note:* Reserved capacity is automatically set according to the service class.
- `cpu_speed_in_mhz` (Number) Specifies the clock frequency, in Mhz, for any virtual CPU that is allocated to a VM.
It must be at least 1200.
- `description` (String) The description of the org VDC.
- `disponibility_class` (String) The disponibility class of the org VDC. It can be `ONE-ROOM`, `DUAL-ROOM` or `HA-DUAL-ROOM`.
- `id` (String) ID is the Name of the VCD.
- `memory_allocated` (Number) Memory capacity in Gb that is committed to be available or used as a limit in PAYG mode.
It must be between 1 and 5000.
- `service_class` (String) The service class of the org VDC. It can be `ECO`, `STD`, `HP` or `VOIP`.
- `storage_billing_model` (String) Choose Billing model of storage resources. It can be `PAYG` or `RESERVED`.
- `storage_profile` (Block List) List of storage profiles for this VDC. (see [below for nested schema](#nestedblock--storage_profile))
- `vdc_group` (String) Name of an existing VDC group or a new one. This allows you to isolate your VDC.
VMs of VDCs which belong to the same VDC group can communicate together.

<a id="nestedblock--storage_profile"></a>
### Nested Schema for `storage_profile`

Read-Only:

- `class` (String) VDC storage profile class.
- `default` (Boolean) VDC storage profile default.
- `limit` (Number) VDC storage profile limit.
- `class` (String) The storage class of the storage profile.
It can be `silver`, `silver_r1`, `silver_r2`, `gold`, `gold_r1`, `gold_r2`, `gold_hm`, `platinum3k`, `platinum3k_r1`, `platinum3k_r2`, `platinum3k_hm`, `platinum7k`, `platinum7k_r1`, `platinum7k_r2`, `platinum7k_hm`.
- `default` (Boolean) Set this storage profile as default for this VDC. Only one storage profile can be default per VDC.
- `limit` (Number) Max number of units allocated for this storage profile. In Gb. It must be between 500 and 10000.


195 changes: 92 additions & 103 deletions internal/provider/vdc_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand All @@ -23,29 +25,18 @@ type vdcDataSource struct {
}

type vdcDataSourceModel struct {
ID types.String `tfsdk:"id"`
VdcGroup types.String `tfsdk:"vdc_group"`
Name types.String `tfsdk:"name"`
Vdc *vdcDetail `tfsdk:"vdc"`
}

type vdcDetail struct {
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
VdcServiceClass types.String `tfsdk:"vdc_service_class"`
VdcDisponibilityClass types.String `tfsdk:"vdc_disponibility_class"`
VdcBillingModel types.String `tfsdk:"vdc_billing_model"`
VcpuInMhz2 types.Float64 `tfsdk:"vcpu_in_mhz2"`
CPUAllocated types.Float64 `tfsdk:"cpu_allocated"`
MemoryAllocated types.Float64 `tfsdk:"memory_allocated"`
VdcStorageBillingModel types.String `tfsdk:"vdc_storage_billing_model"`
VdcStorageProfiles []vdcStorageProfiles `tfsdk:"vdc_storage_profiles"`
}

type vdcStorageProfiles struct {
Class types.String `tfsdk:"class"`
Limit types.Int64 `tfsdk:"limit"`
Default types.Bool `tfsdk:"default"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
VdcServiceClass types.String `tfsdk:"service_class"`
VdcDisponibilityClass types.String `tfsdk:"disponibility_class"`
VdcBillingModel types.String `tfsdk:"billing_model"`
VcpuInMhz2 types.Float64 `tfsdk:"cpu_speed_in_mhz"`
CPUAllocated types.Float64 `tfsdk:"cpu_allocated"`
MemoryAllocated types.Float64 `tfsdk:"memory_allocated"`
VdcStorageBillingModel types.String `tfsdk:"storage_billing_model"`
VdcStorageProfiles []vdcStorageProfileModel `tfsdk:"storage_profile"`
VdcGroup types.String `tfsdk:"vdc_group"`
}

func (d *vdcDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand All @@ -54,77 +45,79 @@ func (d *vdcDataSource) Metadata(ctx context.Context, req datasource.MetadataReq

func (d *vdcDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Show the vDC details.",

MarkdownDescription: "Provides a Cloud Avenue Organization VDC data source. An Organization VDC can be used to reference a VDC and use its data within other resources or data sources.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
Computed: true,
MarkdownDescription: "ID is the Name of the VCD.",
},
"name": schema.StringAttribute{
MarkdownDescription: "VDC name.",
Required: true,
Required: true,
MarkdownDescription: "The name of the org VDC. It must be unique in the organization.\n" +
"The length must be between 2 and 27 characters.",
Validators: []validator.String{
stringvalidator.LengthBetween(2, 27),
},
},
"description": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The description of the org VDC.",
},
"cpu_speed_in_mhz": schema.Float64Attribute{
Computed: true,
MarkdownDescription: "Specifies the clock frequency, in Mhz, for any virtual CPU that is allocated to a VM.\n" +
"It must be at least 1200.",
},
"cpu_allocated": schema.Float64Attribute{
Computed: true,
MarkdownDescription: "CPU capacity in *MHz* that is committed to be available or used as a limit in PAYG mode.\n" +
"It must be at least 5 * `cpu_speed_in_mhz` and at most 200 * `cpu_speed_in_mhz`.\n" +
" *Note:* Reserved capacity is automatically set according to the service class.",
},
"memory_allocated": schema.Float64Attribute{
Computed: true,
MarkdownDescription: "Memory capacity in Gb that is committed to be available or used as a limit in PAYG mode.\n" +
"It must be between 1 and 5000.",
},
"vdc_group": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Name of an existing VDC group or a new one. This allows you to isolate your VDC.\n" +
"VMs of VDCs which belong to the same VDC group can communicate together.",
},
"vdc": schema.SingleNestedAttribute{
MarkdownDescription: "VDC details.",
"service_class": schema.StringAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
MarkdownDescription: "VDC name.",
Computed: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "VDC UUID.",
Computed: true,
},
"vdc_service_class": schema.StringAttribute{
MarkdownDescription: "VDC service class.",
Computed: true,
},
"vdc_disponibility_class": schema.StringAttribute{
MarkdownDescription: "VDC disponibility class.",
Computed: true,
},
"vdc_billing_model": schema.StringAttribute{
MarkdownDescription: "VDC billing model.",
Computed: true,
},
"vcpu_in_mhz2": schema.NumberAttribute{
MarkdownDescription: "VDC CPU in Mhz2.",
Computed: true,
},
"cpu_allocated": schema.NumberAttribute{
MarkdownDescription: "VDC CPU allocated.",
Computed: true,
},
"memory_allocated": schema.NumberAttribute{
MarkdownDescription: "VDC memory allocated.",
Computed: true,
},
"vdc_storage_billing_model": schema.StringAttribute{
MarkdownDescription: "VDC storage billing model.",
Computed: true,
},
"vdc_storage_profiles": schema.ListNestedAttribute{
MarkdownDescription: "VDC storage profiles.",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"class": schema.StringAttribute{
MarkdownDescription: "VDC storage profile class.",
Computed: true,
},
"limit": schema.NumberAttribute{
MarkdownDescription: "VDC storage profile limit.",
Computed: true,
},
"default": schema.BoolAttribute{
MarkdownDescription: "VDC storage profile default.",
Computed: true,
},
},
MarkdownDescription: "The service class of the org VDC. It can be `ECO`, `STD`, `HP` or `VOIP`.",
},
"disponibility_class": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The disponibility class of the org VDC. It can be `ONE-ROOM`, `DUAL-ROOM` or `HA-DUAL-ROOM`.",
},
"billing_model": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Choose Billing model of compute resources. It can be `PAYG`, `DRAAS` or `RESERVED`.",
},
"storage_billing_model": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Choose Billing model of storage resources. It can be `PAYG` or `RESERVED`.",
},
},
Blocks: map[string]schema.Block{
"storage_profile": schema.ListNestedBlock{
MarkdownDescription: "List of storage profiles for this VDC.",
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"class": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The storage class of the storage profile.\n" +
"It can be `silver`, `silver_r1`, `silver_r2`, `gold`, `gold_r1`, `gold_r2`, `gold_hm`, `platinum3k`, `platinum3k_r1`, `platinum3k_r2`, `platinum3k_hm`, `platinum7k`, `platinum7k_r1`, `platinum7k_r2`, `platinum7k_hm`.",
},
"limit": schema.Int64Attribute{
Computed: true,
MarkdownDescription: "Max number of units allocated for this storage profile. In Gb. It must be between 500 and 10000.",
},
"default": schema.BoolAttribute{
Computed: true,
MarkdownDescription: "Set this storage profile as default for this VDC. Only one storage profile can be default per VDC.",
},
},
},
Expand Down Expand Up @@ -169,9 +162,9 @@ func (d *vdcDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
return
}

var profiles []vdcStorageProfiles
var profiles []vdcStorageProfileModel
for _, profile := range vdcs.Vdc.VdcStorageProfiles {
p := vdcStorageProfiles{
p := vdcStorageProfileModel{
Class: types.StringValue(profile.Class),
Limit: types.Int64Value(int64(profile.Limit)),
Default: types.BoolValue(profile.Default_),
Expand All @@ -180,24 +173,20 @@ func (d *vdcDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
}

data = vdcDataSourceModel{
VdcGroup: types.StringValue(vdcs.VdcGroup),
Name: types.StringValue(vdcs.Vdc.Name),
Vdc: &vdcDetail{
Name: types.StringValue(vdcs.Vdc.Name),
Description: types.StringValue(vdcs.Vdc.Description),
VdcServiceClass: types.StringValue(vdcs.Vdc.VdcServiceClass),
VdcDisponibilityClass: types.StringValue(vdcs.Vdc.VdcDisponibilityClass),
VdcBillingModel: types.StringValue(vdcs.Vdc.VdcBillingModel),
VcpuInMhz2: types.Float64Value(vdcs.Vdc.VcpuInMhz2),
CPUAllocated: types.Float64Value(vdcs.Vdc.CpuAllocated),
MemoryAllocated: types.Float64Value(vdcs.Vdc.MemoryAllocated),
VdcStorageBillingModel: types.StringValue(vdcs.Vdc.VdcStorageBillingModel),
VdcStorageProfiles: profiles,
},
ID: types.StringValue(vdcs.Vdc.Name),
VdcGroup: types.StringValue(vdcs.VdcGroup),
Name: types.StringValue(vdcs.Vdc.Name),
Description: types.StringValue(vdcs.Vdc.Description),
VdcServiceClass: types.StringValue(vdcs.Vdc.VdcServiceClass),
VdcDisponibilityClass: types.StringValue(vdcs.Vdc.VdcDisponibilityClass),
VdcBillingModel: types.StringValue(vdcs.Vdc.VdcBillingModel),
VcpuInMhz2: types.Float64Value(vdcs.Vdc.VcpuInMhz2),
CPUAllocated: types.Float64Value(vdcs.Vdc.CpuAllocated),
MemoryAllocated: types.Float64Value(vdcs.Vdc.MemoryAllocated),
VdcStorageBillingModel: types.StringValue(vdcs.Vdc.VdcStorageBillingModel),
VdcStorageProfiles: profiles,
}

data.ID = types.StringValue("frangipane")

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
if resp.Diagnostics.HasError() {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/vdc_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccVdcDataSource(t *testing.T) {
{
Config: testAccVdcDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "id", "frangipane"),
resource.TestCheckResourceAttr(dataSourceName, "id", "VDC_Frangipane"),
),
},
},
Expand Down