From ffd20f0e223dd13fd9d80ffe477af2050bfc6cd4 Mon Sep 17 00:00:00 2001 From: pavel <36902936+pavel-github@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:36:19 +0200 Subject: [PATCH] feat(resource/cloudsigma_remote_snapshot): remove unused resource BREAKING CHANGE: resource 'cloudsigma_remote_snapshot' does not implement create functionality correctly --- cloudsigma/provider.go | 7 +- .../resource_cloudsigma_remote_snapshot.go | 141 ------------------ docs/resources/remote_snapshot.md | 41 ----- 3 files changed, 3 insertions(+), 186 deletions(-) delete mode 100644 cloudsigma/resource_cloudsigma_remote_snapshot.go delete mode 100644 docs/resources/remote_snapshot.md diff --git a/cloudsigma/provider.go b/cloudsigma/provider.go index 1bb4832..a612cf3 100644 --- a/cloudsigma/provider.go +++ b/cloudsigma/provider.go @@ -53,10 +53,9 @@ func Provider() *schema.Provider { DataSourcesMap: map[string]*schema.Resource{}, ResourcesMap: map[string]*schema.Resource{ - "cloudsigma_drive": resourceCloudSigmaDrive(), - "cloudsigma_remote_snapshot": resourceCloudSigmaRemoteSnapshot(), - "cloudsigma_server": resourceCloudSigmaServer(), - "cloudsigma_snapshot": resourceCloudSigmaSnapshot(), + "cloudsigma_drive": resourceCloudSigmaDrive(), + "cloudsigma_server": resourceCloudSigmaServer(), + "cloudsigma_snapshot": resourceCloudSigmaSnapshot(), }, } diff --git a/cloudsigma/resource_cloudsigma_remote_snapshot.go b/cloudsigma/resource_cloudsigma_remote_snapshot.go deleted file mode 100644 index 573842e..0000000 --- a/cloudsigma/resource_cloudsigma_remote_snapshot.go +++ /dev/null @@ -1,141 +0,0 @@ -package cloudsigma - -import ( - "context" - "log" - - "github.com/cloudsigma/cloudsigma-sdk-go/cloudsigma" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func resourceCloudSigmaRemoteSnapshot() *schema.Resource { - return &schema.Resource{ - Description: ` -The remote snapshot resource allows you to manage CloudSigma remote snapshots. - -Remote snapshots are point-in-time versions of a drive. They can be cloned to -a full drive, which makes it possible to restore an older version of a VM image. -`, - - CreateContext: resourceCloudSigmaRemoteSnapshotCreate, - ReadContext: resourceCloudSigmaRemoteSnapshotRead, - UpdateContext: resourceCloudSigmaRemoteSnapshotUpdate, - DeleteContext: resourceCloudSigmaRemoteSnapshotDelete, - - SchemaVersion: 0, - - Schema: map[string]*schema.Schema{ - "drive": { - Description: "The UUID of the drive.", - Type: schema.TypeString, - Required: true, - }, - - "location": { - Description: "The location of the remote snapshot.", - Required: true, - Type: schema.TypeString, - }, - - "name": { - Description: "The remote snapshot name.", - Required: true, - Type: schema.TypeString, - }, - - "resource_uri": { - Description: "The unique resource identifier of the remote snapshot.", - Computed: true, - Type: schema.TypeString, - }, - - "status": { - Description: "The remote snapshot status.", - Computed: true, - Type: schema.TypeString, - }, - }, - } -} - -func resourceCloudSigmaRemoteSnapshotCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*cloudsigma.Client) - - createRequest := &cloudsigma.RemoteSnapshotCreateRequest{ - // Drive: &cloudsigma.Drive{ - // UUID: d.Get("drive").(string), - // }, - // Location: d.Get("location").(string), - // Name: d.Get("name").(string), - } - log.Printf("[DEBUG] Remote snapshot create configuration: %#v", *createRequest) - remoteSnapshots, _, err := client.RemoteSnapshots.Create(ctx, createRequest) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(remoteSnapshots[0].UUID) - log.Printf("[INFO] Remote snapshot ID: %s", d.Id()) - - return resourceCloudSigmaRemoteSnapshotRead(ctx, d, meta) -} - -func resourceCloudSigmaRemoteSnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*cloudsigma.Client) - - remoteSnapshot, resp, err := client.RemoteSnapshots.Get(ctx, d.Id()) - if err != nil { - if resp != nil && resp.StatusCode == 404 { - d.SetId("") - return nil - } - return diag.FromErr(err) - } - - _ = d.Set("drive", remoteSnapshot.Drive.UUID) - _ = d.Set("name", remoteSnapshot.Name) - _ = d.Set("resource_uri", remoteSnapshot.ResourceURI) - _ = d.Set("status", remoteSnapshot.Status) - - return nil -} - -func resourceCloudSigmaRemoteSnapshotUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*cloudsigma.Client) - - remoteSnapshot := &cloudsigma.RemoteSnapshot{ - Snapshot: cloudsigma.Snapshot{ - UUID: d.Id(), - }, - } - - if d.HasChange("name") { - _, newName := d.GetChange("name") - remoteSnapshot.Snapshot.Name = newName.(string) - } - - updateRequest := &cloudsigma.RemoteSnapshotUpdateRequest{ - RemoteSnapshot: remoteSnapshot, - } - log.Printf("[DEBUG] Remote snapshot update configuration: %#v", *updateRequest) - _, _, err := client.RemoteSnapshots.Update(ctx, remoteSnapshot.UUID, updateRequest) - if err != nil { - return diag.FromErr(err) - } - - return resourceCloudSigmaRemoteSnapshotRead(ctx, d, meta) -} - -func resourceCloudSigmaRemoteSnapshotDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*cloudsigma.Client) - - _, err := client.RemoteSnapshots.Delete(ctx, d.Id()) - if err != nil { - return diag.FromErr(err) - } - - d.SetId("") - - return nil -} diff --git a/docs/resources/remote_snapshot.md b/docs/resources/remote_snapshot.md deleted file mode 100644 index d7fe03d..0000000 --- a/docs/resources/remote_snapshot.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "cloudsigma_remote_snapshot Resource - terraform-provider-cloudsigma" -subcategory: "" -description: |- - The remote snapshot resource allows you to manage CloudSigma remote snapshots. - Remote snapshots are point-in-time versions of a drive. They can be cloned to - a full drive, which makes it possible to restore an older version of a VM image. ---- - -# cloudsigma_remote_snapshot (Resource) - -The remote snapshot resource allows you to manage CloudSigma remote snapshots. - -Remote snapshots are point-in-time versions of a drive. They can be cloned to -a full drive, which makes it possible to restore an older version of a VM image. - -## Example Usage - -```terraform -resource "cloudsigma_remote_snapshot" "snapshot" { - drive = "2ae05b0a-c538-47ac-ba41-e8519f782ab4" - location = "ZRH" - name = "my remote snapshot" -} -``` - - -## Schema - -### Required - -- `drive` (String) The UUID of the drive. -- `location` (String) The location of the remote snapshot. -- `name` (String) The remote snapshot name. - -### Read-Only - -- `id` (String) The ID of this resource. -- `resource_uri` (String) The unique resource identifier of the remote snapshot. -- `status` (String) The remote snapshot status.