Skip to content

Commit

Permalink
fix: set user_data and backup_unit_id in cube server resource (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberea authored Oct 9, 2024
1 parent fc7640d commit 1bd720c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes
- Fix documentation rendering of `autoscaling_group` resource and data source, `dbaas_mongo_template` data source and `server_boot_device_selection` resource in Terraform registry
- Fix `application_loadbalancer_forwardingrule` docs typo
- Fix for [#687](https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/687) by setting `user_data` and `backupunit_id` in `ionoscloud_cube_server`

## 6.5.6
### Fixes
Expand Down
22 changes: 22 additions & 0 deletions ionoscloud/resource_cube_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,28 @@ func resourceCubeServerCreate(ctx context.Context, d *schema.ResourceData, meta
volume.ImageAlias = nil
}

if backupUnitID, ok := d.GetOk("volume.0.backup_unit_id"); ok {
if utils.IsValidUUID(backupUnitID.(string)) {
if image == "" && imageAlias == "" {
diags := diag.FromErr(fmt.Errorf("it is mandatory to provide either public image or imageAlias in conjunction with backup unit id property"))
return diags
}

backupUnitID := backupUnitID.(string)
volume.BackupunitId = &backupUnitID
}
}

if userData, ok := d.GetOk("volume.0.user_data"); ok {
if image == "" && imageAlias == "" {
diags := diag.FromErr(fmt.Errorf("it is mandatory to provide either public image or imageAlias that has cloud-init compatibility in conjunction with backup unit id property "))
return diags
}

userData := userData.(string)
volume.UserData = &userData
}

server.Entities = &ionoscloud.ServerEntities{
Volumes: &ionoscloud.AttachedVolumes{
Items: &[]ionoscloud.Volume{
Expand Down

0 comments on commit 1bd720c

Please sign in to comment.