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

Granular CRN for snapshot data sources and resources #158

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM-Cloud/power-go-client v1.8.1
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.7.0 h1:/GuGwPMTKoCZACfnwt7b6wKr4v32q1VO1AMFGNETRN4=
github.com/IBM-Cloud/power-go-client v1.7.0/go.mod h1:9izycYAmNQ+NAdVPXDC3fHYxqWLjlR2YiwqKYveMv5Y=
github.com/IBM-Cloud/power-go-client v1.8.1 h1:tx1aPJmIQrNru1MD1VHGNasGx3eRIs0zzPZ0KvdFQrg=
github.com/IBM-Cloud/power-go-client v1.8.1/go.mod h1:N4RxrsMUvBQjSQ/qPk0iMZ8zK+fZPRTnHi/gTaASw0g=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instance_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func DataSourceIBMPIInstanceSnapshot() *schema.Resource {
Description: "Date of snapshot creation.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_Description: {
Computed: true,
Description: "The description of the snapshot.",
Expand Down Expand Up @@ -92,6 +97,9 @@ func dataSourceIBMPIInstanceSnapshotRead(ctx context.Context, d *schema.Resource
d.SetId(*snapshotData.SnapshotID)
d.Set(Attr_Action, snapshotData.Action)
d.Set(Attr_CreationDate, snapshotData.CreationDate.String())
if snapshotData.Crn != "" {
d.Set(Attr_CRN, snapshotData.Crn)
}
d.Set(Attr_Description, snapshotData.Description)
d.Set(Attr_LastUpdatedDate, snapshotData.LastUpdateDate.String())
d.Set(Attr_Name, snapshotData.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

func TestAccIBMPIInstanceSnapshotDataSource_basic(t *testing.T) {
snapshotResData := "data.ibm_pi_instance_snapshot.testacc_ds_snapshot"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceSnapshotDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_instance_snapshot.testacc_ds_snapshot", "id"),
resource.TestCheckResourceAttrSet(snapshotResData, "id"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instance_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func DataSourceIBMPIInstanceSnapshots() *schema.Resource {
Description: "Date of snapshot creation.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_Description: {
Computed: true,
Description: "The description of the snapshot.",
Expand Down Expand Up @@ -122,6 +127,9 @@ func flattenSnapshotsInstances(list []*models.Snapshot) []map[string]interface{}
Attr_Status: i.Status,
Attr_VolumeSnapshots: i.VolumeSnapshots,
}
if i.Crn != "" {
l[Attr_CRN] = i.Crn
}
result = append(result, l)
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

func TestAccIBMPIInstanceSnapshotsDataSource_basic(t *testing.T) {
snapshotResData := "data.ibm_pi_instance_snapshots.testacc_ds_snapshots"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceSnapshotsDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_instance_snapshots.testacc_ds_snapshots", "id"),
resource.TestCheckResourceAttrSet(snapshotResData, "id"),
),
},
},
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/data_source_ibm_pi_pvm_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func DataSourceIBMPIPVMSnapshot() *schema.Resource {
Description: "Date of snapshot creation.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_Description: {
Computed: true,
Description: "The description of the snapshot.",
Expand Down Expand Up @@ -129,6 +134,9 @@ func flattenPVMSnapshotInstances(list []*models.Snapshot) []map[string]interface
Attr_Status: i.Status,
Attr_VolumeSnapshots: i.VolumeSnapshots,
}
if i.Crn != "" {
l[Attr_CRN] = i.Crn
}
result = append(result, l)
}
return result
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/data_source_ibm_pi_pvm_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

func TestAccIBMPISnapshotDataSource_basic(t *testing.T) {
snapshotRes := "data.ibm_pi_pvm_snapshots.testacc_pi_snapshots"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPISnapshotDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_pvm_snapshots.testacc_pi_snapshots", "id"),
resource.TestCheckResourceAttrSet(snapshotRes, "id"),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
Arg_SysType = "pi_sys_type"
Arg_TargetStorageTier = "pi_target_storage_tier"
Arg_UserData = "pi_user_data"
Arg_UserTags = "pi_user_tags"
Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned"
Arg_VirtualOpticalDevice = "pi_virtual_optical_device"
Arg_VolumeCloneName = "pi_volume_clone_name"
Expand Down
22 changes: 22 additions & 0 deletions ibm/service/power/resource_ibm_pi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func ResourceIBMPISnapshot() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_UserTags: {
Description: "The user tags attached to this resource.",
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
Optional: true,
Type: schema.TypeList,
},
Arg_VolumeIDs: {
Description: "A list of volume IDs of the instance that will be part of the snapshot. If none are provided, then all the volumes of the instance will be part of the snapshot.",
DiffSuppressFunc: flex.ApplyOnce,
Expand All @@ -73,6 +80,11 @@ func ResourceIBMPISnapshot() *schema.Resource {
Description: "Creation date of the snapshot.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_LastUpdateDate: {
Computed: true,
Description: "The last updated date of the snapshot.",
Expand Down Expand Up @@ -123,6 +135,13 @@ func resourceIBMPISnapshotCreate(ctx context.Context, d *schema.ResourceData, me
log.Printf("no volumeids provided. Will snapshot the entire instance")
}

if v, ok := d.GetOk(Arg_UserTags); ok {
if len(v.([]interface{})) > 0 {
snapshotBody.UserTags = flex.ExpandStringList(v.([]interface{}))
}

}

snapshotResponse, err := client.CreatePvmSnapShot(instanceid, snapshotBody)
if err != nil {
log.Printf("[DEBUG] err %s", err)
Expand Down Expand Up @@ -160,6 +179,9 @@ func resourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, meta

d.Set(Arg_SnapShotName, snapshotdata.Name)
d.Set(Attr_CreationDate, snapshotdata.CreationDate.String())
if snapshotdata.Crn != "" {
d.Set(Attr_CRN, snapshotdata.Crn)
}
d.Set(Attr_LastUpdateDate, snapshotdata.LastUpdateDate.String())
d.Set(Attr_SnapshotID, *snapshotdata.SnapshotID)
d.Set(Attr_Status, snapshotdata.Status)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/pi_instance_snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ In addition to all argument reference list, you can access the following attribu

- `action` - (String) Action performed on the instance snapshot.
- `creation_date` - (String) Date of snapshot creation.
- `crn` - (String) The CRN of this resource.
- `description` - (String) The description of the snapshot.
- `last_updated_date` - (String) Date of last update.
- `name` - (String) The name of the Power Systems Virtual Machine instance snapshot.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/pi_instance_snapshots.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ In addition to all argument reference list, you can access the following attribu
Nested scheme for `instance_snapshots`:
- `action` - (String) Action performed on the instance snapshot.
- `creation_date` - (String) Date of snapshot creation.
- `crn` - (String) The CRN of this resource.
- `description` - (String) The description of the snapshot.
- `id` - (String) The unique identifier of the Power Systems Virtual Machine instance snapshot.
- `last_updated_date` - (String) Date of last update.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/pi_pvm_snapshots.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ In addition to all argument reference list, you can access the following attribu
Nested scheme for `pvm_snapshots`:
- `action` - (String) Action performed on the instance snapshot.
- `creation_date` - (String) Date of snapshot creation.
- `crn` - (String) The CRN of this resource.
- `description` - (String) The description of the snapshot.
- `id` - (String) The unique identifier of the Power Virtual Machine instance snapshot.
- `last_updated_date` - (String) Date of last update.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/pi_snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ Review the argument references that you can specify for your resource.
- `pi_description` - (Optional, String) Description of the PVM instance snapshot.
- `pi_instance_name` - (Required, String) The name of the instance you want to take a snapshot of.
- `pi_snap_shot_name` - (Required, String) The unique name of the snapshot.
- `pi_user_tags` - (Optional, List) The user tags attached to this resource.
- `pi_volume_ids` - (Optional, String) A list of volume IDs of the instance that will be part of the snapshot. If none are provided, then all the volumes of the instance will be part of the snapshot.

## Attribute reference

In addition to all argument reference list, you can access the following attribute reference after your resource is created.

- `creation_date` - (String) Creation date of the snapshot.
- `crn` - (String) The CRN of this resource.
- `id` - (String) The unique identifier of the snapshot. The ID is composed of <pi_cloud_instance_id>/<snapshot_id>.
- `last_update_date` - (String) The last updated date of the snapshot.
- `snapshot_id` - (String) ID of the PVM instance snapshot.
Expand Down
Loading