Skip to content

Commit

Permalink
Add empty check for crn
Browse files Browse the repository at this point in the history
  • Loading branch information
ismirlia committed Oct 15, 2024
1 parent f4af4c2 commit ba3e27f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
12 changes: 7 additions & 5 deletions ibm/service/power/resource_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
policy := ap.(string)
body.AffinityPolicy = &policy

if policy == "affinity" {
if policy == Affinity {
if av, ok := d.GetOk(Arg_AffinityVolume); ok {
afvol := av.(string)
body.AffinityVolume = &afvol
Expand Down Expand Up @@ -317,10 +317,12 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
}

if _, ok := d.GetOk(Arg_UserTags); ok {
oldList, newList := d.GetChange(Arg_UserTags)
err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(vol.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of volume (%s) pi_user_tags during creation: %s", volumeid, err)
if vol.Crn != "" {
oldList, newList := d.GetChange(Arg_UserTags)
err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(vol.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of volume (%s) pi_user_tags during creation: %s", volumeid, err)
}
}
}

Expand Down
29 changes: 8 additions & 21 deletions ibm/service/power/resource_ibm_pi_volume_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func ResourceIBMPIVolumeBulk() *schema.Resource {
},
Arg_Count: {
Default: 1,
Description: "Number of volumes to create. Default 1.",
Description: "Number of volumes to create. Default 1. Maximum is 500 for public workspaces, and 250 for private workspaces.",
ForceNew: true,
Optional: true,
Type: schema.TypeInt,
Expand Down Expand Up @@ -244,21 +244,6 @@ func ResourceIBMPIVolumeBulk() *schema.Resource {
}
}

func ResourceIBMPIVolumeBulkValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: "pi_affinity",
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Required: true,
AllowedValues: "affinity, anti-affinity"})
IBMPIVolumeBulkResourceValidator := validate.ResourceValidator{
ResourceName: "ibm_pi_volume",
Schema: validateSchema}
return &IBMPIVolumeBulkResourceValidator
}

func resourceIBMPIVolumeBulkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
Expand Down Expand Up @@ -301,7 +286,7 @@ func resourceIBMPIVolumeBulkCreate(ctx context.Context, d *schema.ResourceData,
policy := ap.(string)
body.AffinityPolicy = &policy

if policy == "affinity" {
if policy == Affinity {
if av, ok := d.GetOk(Arg_AffinityVolume); ok {
afvol := av.(string)
body.AffinityVolume = &afvol
Expand Down Expand Up @@ -346,10 +331,12 @@ func resourceIBMPIVolumeBulkCreate(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}
if _, ok := d.GetOk(Arg_UserTags); ok {
oldList, newList := d.GetChange(Arg_UserTags)
err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(vol.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of volume (%s) pi_user_tags during creation: %s", volumeid, err)
if vol.Crn != "" {
oldList, newList := d.GetChange(Arg_UserTags)
err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(vol.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of volume (%s) pi_user_tags during creation: %s", volumeid, err)
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions ibm/service/power/resource_ibm_pi_volume_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func testAccCheckIBMPIVolumeBulkConfig(name string, userTagsString string) strin
return fmt.Sprintf(`
resource "ibm_pi_volume_bulk" "power_volume" {
pi_cloud_instance_id = "%[2]s"
pi_count = 5
pi_user_tags = %[3]s
pi_volume_name = "%[1]s"
pi_volume_shareable = true
pi_volume_size = 1
pi_volume_type = "tier3"
pi_count = 5
pi_user_tags = %[3]s
pi_volume_name = "%[1]s"
pi_volume_shareable = true
pi_volume_size = 1
pi_volume_type = "tier3"
}`, name, acc.Pi_cloud_instance_id, userTagsString)
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/pi_volume_bulk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Review the argument references that you can specify for your resource.
- `pi_anti_affinity_instances` - (Optional, String) List of pvmInstances to base volume anti-affinity policy against; required if requesting `anti-affinity` and `pi_anti_affinity_volumes` is not provided.
- `pi_anti_affinity_volumes`- (Optional, String) List of volumes to base volume anti-affinity policy against; required if requesting `anti-affinity` and `pi_anti_affinity_instances` is not provided.
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
- `pi_count` - (Optional, Integer) Number of volumes to create. Default 1.
- `pi_count` - (Optional, Integer) Number of volumes to create. Default 1. Maximum is 500 for public workspaces, and 250 for private workspaces.
- `pi_replication_enabled` - (Optional, Boolean) Indicates if the volume should be replication enabled or not.

**Note:** `replication_sites` will be populated automatically with default sites if set to true and sites are not specified.
Expand Down

0 comments on commit ba3e27f

Please sign in to comment.