Skip to content

Commit

Permalink
Merge pull request #31 from orange-cloudavenue/18-new-resource-vcd
Browse files Browse the repository at this point in the history
feat: add vdc resource
  • Loading branch information
gaetanars authored Feb 10, 2023
2 parents 126e88a + 3f3ae5f commit a857814
Show file tree
Hide file tree
Showing 7 changed files with 765 additions and 9 deletions.
103 changes: 103 additions & 0 deletions docs/resources/vdc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cloudavenue_vdc Resource - cloudavenue"
subcategory: ""
description: |-
Provides a Cloud Avenue Organization VDC resource. This can be used to create and delete an Organization VDC.
---

# cloudavenue_vdc (Resource)

Provides a Cloud Avenue Organization VDC resource. This can be used to create and delete an Organization VDC.

## Example Usage

```terraform
resource "cloudavenue_vdc" "example" {
name = "MyVDC"
vdc_group = "MyVDCGroup"
description = "Example VDC created by Terraform"
cpu_allocated = 6000
memory_allocated = 10
cpu_speed_in_mhz = 1200
billing_model = "PAYG"
disponibility_class = "ONE-ROOM"
service_class = "STD"
storage_billing_model = "PAYG"
storage_profile {
class = "gold"
default = true
limit = 500
}
storage_profile {
class = "silver"
default = false
limit = 500
}
}
```

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

### Required

- `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.
- `disponibility_class` (String) The disponibility class of the org VDC. It can be `ONE-ROOM`, `DUAL-ROOM` or `HA-DUAL-ROOM`.
- `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.
- `name` (String) The name of the org VDC. It must be unique in the organization.
The length must be between 2 and 27 characters.
- `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`.
- `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.

### Optional

- `description` (String) The description of the org VDC.
- `storage_profile` (Block List) List of storage profiles for this VDC. (see [below for nested schema](#nestedblock--storage_profile))
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) ID is the Name of the VCD.

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

Required:

- `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.


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

Optional:

- `create` (String)
- `delete` (String)
- `read` (String)
- `update` (String)

## Import

Import is supported using the following syntax:

```shell
# VDC can be imported using the name.

terraform import cloudavenue_vdc.vdc name
```
3 changes: 3 additions & 0 deletions examples/resources/cloudavenue_vdc/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# VDC can be imported using the name.

terraform import cloudavenue_vdc.vdc name
25 changes: 25 additions & 0 deletions examples/resources/cloudavenue_vdc/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "cloudavenue_vdc" "example" {
name = "MyVDC"
vdc_group = "MyVDCGroup"
description = "Example VDC created by Terraform"
cpu_allocated = 6000
memory_allocated = 10
cpu_speed_in_mhz = 1200
billing_model = "PAYG"
disponibility_class = "ONE-ROOM"
service_class = "STD"
storage_billing_model = "PAYG"

storage_profile {
class = "gold"
default = true
limit = 500
}

storage_profile {
class = "silver"
default = false
limit = 500
}

}
12 changes: 6 additions & 6 deletions internal/provider/edge_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func (r *edgeGatewaysResource) Create(ctx context.Context, req resource.CreateRe

edgeID := ""

if jobStatus == "DONE" {
if jobStatus.IsDone() {
// get all edge gateways and find the one that matches the tier0_vrf_id and owner_name
gateways, _, errEdgesGet := r.client.EdgeGatewaysApi.ApiCustomersV20EdgesGet(auth)
if errEdgesGet != nil {
return nil, "error", err
return nil, "err", err
}

for _, gw := range gateways {
Expand All @@ -206,18 +206,18 @@ func (r *edgeGatewaysResource) Create(ctx context.Context, req resource.CreateRe
}
}
} else {
return nil, "pending", nil
return nil, jobStatus.String(), nil
}
return edgeID, "done", nil
return edgeID, jobStatus.String(), nil
}

createStateConf := &sdkResource.StateChangeConf{
Delay: 10 * time.Second,
Refresh: refreshF,
MinTimeout: 5 * time.Second,
Timeout: 5 * time.Minute,
Pending: []string{"pending"},
Target: []string{"done"},
Pending: []string{PENDING.String()},
Target: []string{DONE.String()},
}

edgeID, err := createStateConf.WaitForStateContext(ctxTO)
Expand Down
48 changes: 45 additions & 3 deletions internal/provider/helper_job.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
package provider

import "context"
import (
"context"
"strings"
)

type JobStatus string

const (
DONE JobStatus = "DONE"
FAILED JobStatus = "FAILED"
CREATED JobStatus = "CREATED"
PENDING JobStatus = "PENDING"
INPROGRESS JobStatus = "IN_PROGRESS"
ERROR JobStatus = "ERROR"
)

// getJobStatus is a helper function to get the status of a job.
func getJobStatus(ctx context.Context, client *CloudAvenueClient, jobID string) (string, error) {
func getJobStatus(ctx context.Context, client *CloudAvenueClient, jobID string) (JobStatus, error) {
jobStatus, _, err := client.JobsApi.ApiCustomersV10JobsJobIdGet(ctx, jobID)
if err != nil {
return "", err
}
return jobStatus[0].Status, nil
return parseJobStatus(jobStatus[0].Status), nil
}

// parseJobStatus return the status of a job.
func parseJobStatus(str string) JobStatus {
switch str {
case "DONE":
return DONE
case "FAILED":
return FAILED
case "CREATED":
return CREATED
case "PENDING":
return PENDING
case "IN_PROGRESS":
return INPROGRESS
default:
return ""
}
}

// Stringer interface for JobStatus
func (j JobStatus) String() string {
return strings.ToLower(string(j))
}

// IsDone is a helper function to check if a job is done.
func (j JobStatus) IsDone() bool {
return j == DONE
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource
func (p *cloudavenueProvider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewEdgeGatewayResource,
NewVdcResource,
}
}
Loading

0 comments on commit a857814

Please sign in to comment.