Skip to content

Commit 416c59a

Browse files
authored
Merge pull request #902 from ovh/dev/aamstutz/add-vcd-backup-datasource
New datasource ovh_vmware_cloud_director_backup
2 parents 1ddbe14 + ee89ff7 commit 416c59a

File tree

7 files changed

+2391
-0
lines changed

7 files changed

+2391
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
subcategory: "VMware Cloud Director (VCD)"
3+
---
4+
5+
# ovh_vmware_cloud_director_backup (Data Source)
6+
7+
Get information about a VMware Cloud Director Backup service
8+
9+
## Example Usage
10+
11+
```terraform
12+
data "ovh_vmware_cloud_director_backup" "backup" {
13+
backup_id = "<VCD backup ID>"
14+
}
15+
```
16+
17+
<!-- schema generated by tfplugindocs -->
18+
## Schema
19+
20+
### Required
21+
22+
- `backup_id` (String) Backup ID
23+
24+
### Read-Only
25+
26+
- `created_at` (String) Datetime when backup was enabled
27+
- `current_state` (Attributes) VMware Cloud Director Backup service current state (see [below for nested schema](#nestedatt--current_state))
28+
- `current_tasks` (Attributes List) Asynchronous operations ongoing on the VMware Cloud Director organization backup service (see [below for nested schema](#nestedatt--current_tasks))
29+
- `iam` (Attributes) IAM resource metadata (see [below for nested schema](#nestedatt--iam))
30+
- `id` (String) Unique identifier of the VMware Cloud Director backup
31+
- `resource_status` (String) Reflects the readiness of the VMware Cloud Director organization backup service
32+
- `target_spec` (Attributes) VMware Cloud Director Backup target spec (see [below for nested schema](#nestedatt--target_spec))
33+
- `updated_at` (String) Datetime when backup is modified
34+
35+
<a id="nestedatt--current_state"></a>
36+
### Nested Schema for `current_state`
37+
38+
Read-Only:
39+
40+
- `az_name` (String) Availability zone of VMware Cloud Director organization backup
41+
- `offers` (Attributes List) List of your VMware Cloud Director organization backup offers (see [below for nested schema](#nestedatt--current_state--offers))
42+
43+
<a id="nestedatt--current_state--offers"></a>
44+
### Nested Schema for `current_state.offers`
45+
46+
Read-Only:
47+
48+
- `name` (String) Backup service offer type (BRONZE|SILVER|GOLD)
49+
- `protection_primary_region` (String) Backup repository primary region
50+
- `protection_replicated_region` (String) Backup repository replicated region
51+
- `quota_in_tb` (Number) Backup repository quota in TB
52+
- `status` (String) Backup offer status
53+
- `used_space_in_gb` (Number) Backup repository used space in GB
54+
55+
<a id="nestedatt--current_tasks"></a>
56+
### Nested Schema for `current_tasks`
57+
58+
Read-Only:
59+
60+
- `id` (String) Identifier of the current task
61+
- `link` (String) Link to the task details
62+
- `status` (String) Current global status of the current task
63+
- `type` (String) Type of the current task
64+
65+
66+
<a id="nestedatt--iam"></a>
67+
### Nested Schema for `iam`
68+
69+
Read-Only:
70+
71+
- `display_name` (String) Resource display name
72+
- `id` (String) Unique identifier of the resource
73+
- `tags` (Map of String) Resource tags. Tags that were internally computed are prefixed with ovh:
74+
- `urn` (String) Unique resource name used in policies
75+
76+
77+
<a id="nestedatt--target_spec"></a>
78+
### Nested Schema for `target_spec`
79+
80+
Read-Only:
81+
82+
- `offers` (Attributes List) List of your VMware Cloud Director backup offers (see [below for nested schema](#nestedatt--target_spec--offers))
83+
84+
<a id="nestedatt--target_spec--offers"></a>
85+
### Nested Schema for `target_spec.offers`
86+
87+
Read-Only:
88+
89+
- `name` (String) Backup service offer type (BRONZE|SILVER|GOLD)
90+
- `quota_in_tb` (Number) Backup repository quota in TB
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "ovh_vmware_cloud_director_backup" "backup" {
2+
backup_id = "<VCD backup ID>"
3+
}
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package ovh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/url"
7+
8+
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
)
10+
11+
var _ datasource.DataSourceWithConfigure = (*vmwareCloudDirectorBackupDataSource)(nil)
12+
13+
func NewVmwareCloudDirectorBackupDataSource() datasource.DataSource {
14+
return &vmwareCloudDirectorBackupDataSource{}
15+
}
16+
17+
type vmwareCloudDirectorBackupDataSource struct {
18+
config *Config
19+
}
20+
21+
func (d *vmwareCloudDirectorBackupDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
22+
resp.TypeName = req.ProviderTypeName + "_vmware_cloud_director_backup"
23+
}
24+
25+
func (d *vmwareCloudDirectorBackupDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
26+
if req.ProviderData == nil {
27+
return
28+
}
29+
30+
config, ok := req.ProviderData.(*Config)
31+
if !ok {
32+
resp.Diagnostics.AddError(
33+
"Unexpected Data Source Configure Type",
34+
fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
35+
)
36+
return
37+
}
38+
39+
d.config = config
40+
}
41+
42+
func (d *vmwareCloudDirectorBackupDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
43+
resp.Schema = VmwareCloudDirectorBackupDataSourceSchema(ctx)
44+
}
45+
46+
func (d *vmwareCloudDirectorBackupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
47+
var data VmwareCloudDirectorBackupModel
48+
49+
// Read Terraform configuration data into the model
50+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
51+
52+
if resp.Diagnostics.HasError() {
53+
return
54+
}
55+
56+
// Read API call logic
57+
endpoint := "/v2/vmwareCloudDirector/backup/" + url.PathEscape(data.BackupId.ValueString())
58+
59+
if err := d.config.OVHClient.Get(endpoint, &data); err != nil {
60+
resp.Diagnostics.AddError(
61+
fmt.Sprintf("Error calling Get %s", endpoint),
62+
err.Error(),
63+
)
64+
return
65+
}
66+
67+
// Save data into Terraform state
68+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
69+
}

0 commit comments

Comments
 (0)