diff --git a/outscale/data_source_outscale_volumes.go b/outscale/data_source_outscale_volumes.go index b94e1dfb2..16e57eafb 100644 --- a/outscale/data_source_outscale_volumes.go +++ b/outscale/data_source_outscale_volumes.go @@ -190,5 +190,5 @@ func getIops(volumeType string, iops int32) int32 { if volumeType != "standard" { return iops } - return defaultIops + return utils.DefaultIops } diff --git a/outscale/resource_outscale_nic_link.go b/outscale/resource_outscale_nic_link.go index 44546a086..9e97d2821 100644 --- a/outscale/resource_outscale_nic_link.go +++ b/outscale/resource_outscale_nic_link.go @@ -117,7 +117,7 @@ func resourceOutscaleOAPINetworkInterfaceAttachmentRead(d *schema.ResourceData, resp, err := stateConf.WaitForState() if err != nil { return fmt.Errorf( - "Error waiting for Volume to attach to Instance: %s, error: %s", nicID, err) + "Error waiting for NIC to attach to Instance: %s, error: %s", nicID, err) } r := resp.(oscgo.ReadNicsResponse) @@ -206,7 +206,7 @@ func resourceOutscaleNetworkInterfaceAttachmentImportState(d *schema.ResourceDat resp, err := stateConf.WaitForState() if err != nil { return nil, fmt.Errorf( - "Error waiting for Volume to attach to Instance: %s, error: %s", d.Id(), err) + "Error waiting for NIC to attach to Instance: %s, error: %s", d.Id(), err) } r := resp.(oscgo.ReadNicsResponse) linkNic := r.GetNics()[0].GetLinkNic() diff --git a/outscale/resource_outscale_volume.go b/outscale/resource_outscale_volume.go index 20da335cf..39e779382 100644 --- a/outscale/resource_outscale_volume.go +++ b/outscale/resource_outscale_volume.go @@ -15,8 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -const defaultIops = 150 - func resourceOutscaleOAPIVolume() *schema.Resource { return &schema.Resource{ Create: resourceOAPIVolumeCreate, @@ -69,6 +67,10 @@ func resourceOutscaleOAPIVolume() *schema.Resource { ForceNew: true, Computed: true, }, + "termination_snapshot_name": { + Type: schema.TypeString, + Optional: true, + }, "volume_type": { Type: schema.TypeString, Optional: true, @@ -236,7 +238,7 @@ func resourceOAPIVolumeUpdate(d *schema.ResourceData, meta interface{}) error { Target: []string{"available", "in-use"}, Refresh: volumeOAPIStateRefreshFunc(conn, d.Id()), Timeout: 5 * time.Minute, - Delay: 5 * time.Second, + Delay: 2 * time.Second, MinTimeout: 3 * time.Second, } @@ -251,6 +253,47 @@ func resourceOAPIVolumeUpdate(d *schema.ResourceData, meta interface{}) error { func resourceOAPIVolumeDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*OutscaleClient).OSCAPI + if snpName, ok := d.GetOk("termination_snapshot_name"); ok { + volId := d.Get("volume_id").(string) + description := "Created before volume deletion" + resp := oscgo.CreateSnapshotResponse{} + request := oscgo.CreateSnapshotRequest{ + Description: &description, + VolumeId: &volId, + } + err := resource.Retry(5*time.Minute, func() *resource.RetryError { + var err error + r, httpResp, err := conn.SnapshotApi.CreateSnapshot(context.Background()).CreateSnapshotRequest(request).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + resp = r + return nil + }) + if err != nil { + return err + } + snapTagsReq := oscgo.CreateTagsRequest{ + ResourceIds: []string{resp.Snapshot.GetSnapshotId()}, + Tags: []oscgo.ResourceTag{ + { + Key: "Name", + Value: snpName.(string), + }, + }, + } + err = resource.Retry(60*time.Second, func() *resource.RetryError { + _, httpResp, err := conn.TagApi.CreateTags(context.Background()).CreateTagsRequest(snapTagsReq).Execute() + if err != nil { + return utils.CheckThrottling(httpResp, err) + } + return nil + }) + if err != nil { + return err + } + } + return resource.Retry(5*time.Minute, func() *resource.RetryError { request := oscgo.DeleteVolumeRequest{ VolumeId: d.Id(), @@ -319,6 +362,11 @@ func readOAPIVolume(d *schema.ResourceData, volume oscgo.Volume) error { if err := d.Set("creation_date", volume.GetCreationDate()); err != nil { return err } + if snapName, ok := d.GetOk("termination_snapshot_name"); ok { + if err := d.Set("termination_snapshot_name", snapName.(string)); err != nil { + return err + } + } if err := d.Set("iops", getIops(volume.GetVolumeType(), volume.GetIops())); err != nil { return err } diff --git a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref index bec078ec8..66786c985 100644 --- a/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/access_keys/TF-57_access_keys_datasource_attributes_ok/step2.access_keys_datasource_attributes_ok.ref @@ -49,10 +49,10 @@ { "schema_version": 0, "attributes": { - "access_key_id": "##id-1##", + "access_key_id": "##id-0##", "creation_date": "########", "expiration_date": "", - "id": "##id-1##", + "id": "##id-0##", "last_modification_date": "########", "request_id": "########", "secret_key": "########", @@ -72,10 +72,10 @@ { "schema_version": 0, "attributes": { - "access_key_id": "##id-0##", + "access_key_id": "##id-1##", "creation_date": "########", "expiration_date": "", - "id": "##id-0##", + "id": "##id-1##", "last_modification_date": "########", "request_id": "########", "secret_key": "########", diff --git a/tests/qa_provider_oapi/data/snapshot/TF-130_snapshot_datasource_attributes_ok/step1.snapshot_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/snapshot/TF-130_snapshot_datasource_attributes_ok/step1.snapshot_datasource_attributes_ok.ref index 1055cd3e0..e7037d770 100644 --- a/tests/qa_provider_oapi/data/snapshot/TF-130_snapshot_datasource_attributes_ok/step1.snapshot_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/snapshot/TF-130_snapshot_datasource_attributes_ok/step1.snapshot_datasource_attributes_ok.ref @@ -110,6 +110,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/snapshot/TF-131_snapshot_resource_attributes_ok/step1.snapshot_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/snapshot/TF-131_snapshot_resource_attributes_ok/step1.snapshot_resource_attributes_ok.ref index dde73ed88..7cb555050 100644 --- a/tests/qa_provider_oapi/data/snapshot/TF-131_snapshot_resource_attributes_ok/step1.snapshot_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/snapshot/TF-131_snapshot_resource_attributes_ok/step1.snapshot_resource_attributes_ok.ref @@ -105,6 +105,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/snapshot_attributes/TF-132_snapshot_attributes_resource_attributes_ok/step1.snapshot_attributes_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/snapshot_attributes/TF-132_snapshot_attributes_resource_attributes_ok/step1.snapshot_attributes_resource_attributes_ok.ref index bd6377197..de870c971 100644 --- a/tests/qa_provider_oapi/data/snapshot_attributes/TF-132_snapshot_attributes_resource_attributes_ok/step1.snapshot_attributes_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/snapshot_attributes/TF-132_snapshot_attributes_resource_attributes_ok/step1.snapshot_attributes_resource_attributes_ok.ref @@ -126,6 +126,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/snapshot_copy/TF-133_snapashot_c_resource_attributes_ok/step1.snapshot_copy_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/snapshot_copy/TF-133_snapashot_c_resource_attributes_ok/step1.snapshot_copy_resource_attributes_ok.ref index ddd7820e9..56b5897c8 100644 --- a/tests/qa_provider_oapi/data/snapshot_copy/TF-133_snapashot_c_resource_attributes_ok/step1.snapshot_copy_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/snapshot_copy/TF-133_snapashot_c_resource_attributes_ok/step1.snapshot_copy_resource_attributes_ok.ref @@ -100,6 +100,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/snapshots/TF-134_snapshots_datasource_attributes_ok/step1.snapshots_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/snapshots/TF-134_snapshots_datasource_attributes_ok/step1.snapshots_datasource_attributes_ok.ref index 975a33185..8793bf27f 100644 --- a/tests/qa_provider_oapi/data/snapshots/TF-134_snapshots_datasource_attributes_ok/step1.snapshots_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/snapshots/TF-134_snapshots_datasource_attributes_ok/step1.snapshots_datasource_attributes_ok.ref @@ -180,6 +180,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-3##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step1.vm_resource_public_with_multiple_BDM_ok.ref b/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step1.vm_resource_public_with_multiple_BDM_ok.ref index 3d85c9d35..e0dd63c0a 100644 --- a/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step1.vm_resource_public_with_multiple_BDM_ok.ref +++ b/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step1.vm_resource_public_with_multiple_BDM_ok.ref @@ -223,6 +223,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-3##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step2.vm_resource_public_with_multiple_BDM_ok.ref b/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step2.vm_resource_public_with_multiple_BDM_ok.ref index 1b6d64beb..042651f69 100644 --- a/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step2.vm_resource_public_with_multiple_BDM_ok.ref +++ b/tests/qa_provider_oapi/data/vm/TF-146_vm_resource_public_with_BDM_attributes_ok/step2.vm_resource_public_with_multiple_BDM_ok.ref @@ -222,6 +222,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-3##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/volume/TF-152_volume_datasource_attributes_ok/step1.volume_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/volume/TF-152_volume_datasource_attributes_ok/step1.volume_datasource_attributes_ok.ref index 30d8220d4..b44885ba1 100644 --- a/tests/qa_provider_oapi/data/volume/TF-152_volume_datasource_attributes_ok/step1.volume_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/volume/TF-152_volume_datasource_attributes_ok/step1.volume_datasource_attributes_ok.ref @@ -69,6 +69,7 @@ "value": "test-Volume" } ], + "termination_snapshot_name": null, "volume_id": "##id-0##", "volume_type": "io1" }, diff --git a/tests/qa_provider_oapi/data/volume/TF-153_volume_resource_attributes_ok/step1.volume_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/volume/TF-153_volume_resource_attributes_ok/step1.volume_resource_attributes_ok.ref index e072bc5a8..7aece0ee6 100644 --- a/tests/qa_provider_oapi/data/volume/TF-153_volume_resource_attributes_ok/step1.volume_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/volume/TF-153_volume_resource_attributes_ok/step1.volume_resource_attributes_ok.ref @@ -29,6 +29,7 @@ "value": "volume-standard" } ], + "termination_snapshot_name": null, "volume_id": "##id-0##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/volume/TF-155_volume_resource_attributes_ok3/step1.volume_resource_attributes_ok3.ref b/tests/qa_provider_oapi/data/volume/TF-155_volume_resource_attributes_ok3/step1.volume_resource_attributes_ok3.ref index b317b2981..6c13d4618 100644 --- a/tests/qa_provider_oapi/data/volume/TF-155_volume_resource_attributes_ok3/step1.volume_resource_attributes_ok3.ref +++ b/tests/qa_provider_oapi/data/volume/TF-155_volume_resource_attributes_ok3/step1.volume_resource_attributes_ok3.ref @@ -69,6 +69,7 @@ "value": "test1" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, @@ -96,6 +97,7 @@ "state": "available", "subregion_name": "eu-west-2a", "tags": [], + "termination_snapshot_name": null, "volume_id": "##id-3##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/volumes/TF-156_volumes_datasource_attributes_ok/step1.volumes_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/volumes/TF-156_volumes_datasource_attributes_ok/step1.volumes_datasource_attributes_ok.ref index 8e1d88cda..07f6a4489 100644 --- a/tests/qa_provider_oapi/data/volumes/TF-156_volumes_datasource_attributes_ok/step1.volumes_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/volumes/TF-156_volumes_datasource_attributes_ok/step1.volumes_datasource_attributes_ok.ref @@ -91,6 +91,7 @@ "value": "volume-io1-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-1##", "volume_type": "io1" }, @@ -123,6 +124,7 @@ "value": "volume-io1-2" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "io1" }, diff --git a/tests/qa_provider_oapi/data/volumes/TF-157_volumes_datasource_attributes_ok2/step1.volumes_datasource_attributes_ok2.ref b/tests/qa_provider_oapi/data/volumes/TF-157_volumes_datasource_attributes_ok2/step1.volumes_datasource_attributes_ok2.ref index 43f842602..bcee99ee9 100644 --- a/tests/qa_provider_oapi/data/volumes/TF-157_volumes_datasource_attributes_ok2/step1.volumes_datasource_attributes_ok2.ref +++ b/tests/qa_provider_oapi/data/volumes/TF-157_volumes_datasource_attributes_ok2/step1.volumes_datasource_attributes_ok2.ref @@ -83,6 +83,7 @@ "value": "volume-standard-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, @@ -115,6 +116,7 @@ "value": "volume-io1-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-1##", "volume_type": "io1" }, diff --git a/tests/qa_provider_oapi/data/volumes/TF-158_volumes_datasource_attributes_ok3/step1.volumes_datasource_attributes_ok3.ref b/tests/qa_provider_oapi/data/volumes/TF-158_volumes_datasource_attributes_ok3/step1.volumes_datasource_attributes_ok3.ref index b87ed4888..338050b7f 100644 --- a/tests/qa_provider_oapi/data/volumes/TF-158_volumes_datasource_attributes_ok3/step1.volumes_datasource_attributes_ok3.ref +++ b/tests/qa_provider_oapi/data/volumes/TF-158_volumes_datasource_attributes_ok3/step1.volumes_datasource_attributes_ok3.ref @@ -83,6 +83,7 @@ "value": "volume-standard-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-1##", "volume_type": "standard" }, @@ -115,6 +116,7 @@ "value": "volume-standard-2" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, diff --git a/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step1.volumes_datasource_attributes_ok4.ref b/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step1.volumes_datasource_attributes_ok4.ref index d3a954ff6..6c5a4e774 100644 --- a/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step1.volumes_datasource_attributes_ok4.ref +++ b/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step1.volumes_datasource_attributes_ok4.ref @@ -209,6 +209,7 @@ "value": "volume-standard-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-1##", "volume_type": "standard" }, @@ -241,6 +242,7 @@ "value": "volume-standard-2" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, @@ -273,6 +275,7 @@ "value": "io1" } ], + "termination_snapshot_name": null, "volume_id": "##id-4##", "volume_type": "io1" }, diff --git a/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step2.volumes_datasource_attributes_ok4.ref b/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step2.volumes_datasource_attributes_ok4.ref index d40e1cfc0..ce763adf0 100644 --- a/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step2.volumes_datasource_attributes_ok4.ref +++ b/tests/qa_provider_oapi/data/volumes/TF-159_volumes_datasource_attributes_ok4/step2.volumes_datasource_attributes_ok4.ref @@ -218,6 +218,7 @@ "value": "volume-standard-1" } ], + "termination_snapshot_name": null, "volume_id": "##id-1##", "volume_type": "standard" }, @@ -250,6 +251,7 @@ "value": "volume-standard-2" } ], + "termination_snapshot_name": null, "volume_id": "##id-2##", "volume_type": "standard" }, @@ -290,6 +292,7 @@ "value": "io1" } ], + "termination_snapshot_name": null, "volume_id": "##id-4##", "volume_type": "io1" }, diff --git a/tests/qa_provider_oapi/data/volumes_link/TF-160_volumes_link_resource_attributes_ok/step1.volumes_link_resource_attributes_ok.ref b/tests/qa_provider_oapi/data/volumes_link/TF-160_volumes_link_resource_attributes_ok/step1.volumes_link_resource_attributes_ok.ref index b61468e98..1f3d52c51 100644 --- a/tests/qa_provider_oapi/data/volumes_link/TF-160_volumes_link_resource_attributes_ok/step1.volumes_link_resource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/volumes_link/TF-160_volumes_link_resource_attributes_ok/step1.volumes_link_resource_attributes_ok.ref @@ -130,6 +130,7 @@ "value": "standard" } ], + "termination_snapshot_name": null, "volume_id": "##id-6##", "volume_type": "standard" }, diff --git a/utils/utils.go b/utils/utils.go index e0ec3c613..5172415fc 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ const ( MaxPort int = 65535 MinIops int = 100 MaxIops int = 13000 - DefaultIops int = 150 + DefaultIops int32 = 150 MaxSize int = 14901 InvalidState string = "InvalidState" VolumeIOPSError string = `