Skip to content

Commit

Permalink
fix: nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
Florin Mihalache committed Jun 1, 2021
1 parent b782cc7 commit 9203e96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ionoscloud/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,9 @@ func resourceServerRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cpu_family", *server.Properties.CpuFamily)
}

if server.Entities.Volumes != nil && len(*server.Entities.Volumes.Items) > 0 {
if server.Entities.Volumes != nil &&
len(*server.Entities.Volumes.Items) > 0 &&
(*server.Entities.Volumes.Items)[0].Properties.Image != nil {
d.Set("boot_image", *(*server.Entities.Volumes.Items)[0].Properties.Image)
}

Expand Down
10 changes: 5 additions & 5 deletions ionoscloud/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
}

if image_name == "" && licenceType == "" && isSnapshot == false {
return fmt.Errorf("Either 'image_name', or 'licenceType' must be set.")
return fmt.Errorf("either 'image_name', or 'licenceType' must be set")
}

if isSnapshot == true && (imagePassword != "" || len(publicKeys) > 0) {
return fmt.Errorf("You can't pass 'image_password' and/or 'ssh keys' when creating a volume from a snapshot")
return fmt.Errorf("you can't pass 'image_password' and/or 'ssh keys' when creating a volume from a snapshot")
}

volumeName := d.Get("name").(string)
Expand Down Expand Up @@ -295,7 +295,7 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
backupUnitId := d.Get("backup_unit_id").(string)
if IsValidUUID(backupUnitId) {
if image == "" && image_alias == "" {
return fmt.Errorf("It is mandatory to provied either public image or imageAlias in conjunction with backup unit id property")
return fmt.Errorf("it is mandatory to provied either public image or imageAlias in conjunction with backup unit id property")
} else {
volume.Properties.BackupunitId = &backupUnitId
}
Expand All @@ -306,7 +306,7 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
userData := d.Get("user_data").(string)
if userData != "" {
if image == "" && image_alias == "" {
return fmt.Errorf("It is mandatory to provied either public image or imageAlias that has cloud-init compatibility in conjunction with backup unit id property ")
return fmt.Errorf("it is mandatory to provied either public image or imageAlias that has cloud-init compatibility in conjunction with backup unit id property ")
} else {
volume.Properties.UserData = &userData
}
Expand All @@ -321,7 +321,7 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
volume, apiResponse, err := client.VolumeApi.DatacentersVolumesPost(ctx, dcId).Volume(volume).Execute()

if err != nil {
return fmt.Errorf("An error occured while creating a volume: %s, apiError : %s", err, string(apiResponse.Payload))
return fmt.Errorf("an error occured while creating a volume: %s, apiError : %s", err, string(apiResponse.Payload))
}

d.SetId(*volume.Id)
Expand Down

0 comments on commit 9203e96

Please sign in to comment.