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

fix: cube server creation was missing name and other attributes #316

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
### Enhancement:
- Increase go version to 1.18
- Update dependencies to latest versions
- Update Ionos Cloud GO SDK v6.1.2. Release notes here [v6.1.3](https://github.com/ionos-cloud/sdk-go/releases/tag/v6.1.3)
- Update SDK GO DBaaS Postgres to v6.1.2. Release notes here [v1.0.4](https://github.com/ionos-cloud/sdk-go-dbaas-postgres/releases/tag/v1.0.4)
- `ssh_key_path` will now allow the keys to be passed directly also. In the future, will be renamed to `ssh_keys`.

### Fixes
- Reproduces rarely: sometimes the `nic` resource is not found after creation. As a fix we added a retry for 5 minutes to be able to get the NIC. The retry will keep trying if the response
is `not found`(404)

- Fix cube server creation. Some attributes were not populated - name, boot_cdrom, availability_zone
## 6.3.1

### Feature
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_k8s_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func resourcek8sNodePoolCreate(ctx context.Context, d *schema.ResourceData, meta
nodepoolReady, rsErr := k8sNodepoolReady(ctx, client, d)

if rsErr != nil {
diags := diag.FromErr(fmt.Errorf("error while checking readiness status of k8s node pool %s: %s", d.Id(), rsErr))
diags := diag.FromErr(fmt.Errorf("error while checking readiness status of k8s node pool %s: %w", d.Id(), rsErr))
return diags
}

Expand Down
36 changes: 8 additions & 28 deletions ionoscloud/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,7 @@ func resourceServerCreate(ctx context.Context, d *schema.ResourceData, meta inte
diags := diag.FromErr(err)
return diags
}
if v, ok := d.GetOk("availability_zone"); ok {
vStr := v.(string)
serverReq.Properties.AvailabilityZone = &vStr
}

if v, ok := d.GetOk("cpu_family"); ok {
if v.(string) != "" {
vStr := v.(string)
serverReq.Properties.CpuFamily = &vStr
}
}
// create volume object with data to be used for image
volume, err := getVolumeData(d, "volume.0.")

Expand Down Expand Up @@ -1109,15 +1099,18 @@ func SetCdromProperties(image ionoscloud.Image) map[string]interface{} {

// Initializes server with the required attributes depending on the server type (CUBE or ENTERPRISE)
func initializeCreateRequests(d *schema.ResourceData) (ionoscloud.Server, error) {
// create server object
server := ionoscloud.NewServer(*ionoscloud.NewServerPropertiesWithDefaults())

serverType := d.Get("type").(string)

// create server object and populate with common attributes
server, err := getServerData(d)
if err != nil {
return *server, err
}

if serverType != "" {
server.Properties.Type = &serverType
}

switch strings.ToLower(serverType) {
case "cube":
if v, ok := d.GetOk("template_uuid"); ok {
Expand All @@ -1139,11 +1132,6 @@ func initializeCreateRequests(d *schema.ResourceData) (ionoscloud.Server, error)
return *server, fmt.Errorf("volume.0.size argument can not be set for %s type of servers\n", serverType)
}
default: //enterprise
var err error
server, err = getServerData(d)
if err != nil {
return *server, err
}
if _, ok := d.GetOk("template_uuid"); ok {
return *server, fmt.Errorf("template_uuid argument can not be set only for %s type of servers\n", serverType)
}
Expand All @@ -1170,9 +1158,7 @@ func initializeCreateRequests(d *schema.ResourceData) (ionoscloud.Server, error)
}

func getServerData(d *schema.ResourceData) (*ionoscloud.Server, error) {
server := ionoscloud.Server{
Properties: &ionoscloud.ServerProperties{},
}
server := ionoscloud.NewServer(*ionoscloud.NewServerPropertiesWithDefaults())

if v, ok := d.GetOk("availability_zone"); ok {
vStr := v.(string)
Expand All @@ -1182,12 +1168,6 @@ func getServerData(d *schema.ResourceData) (*ionoscloud.Server, error) {
serverName := d.Get("name").(string)
server.Properties.Name = &serverName

serverCores := int32(d.Get("cores").(int))
server.Properties.Cores = &serverCores

serverRam := int32(d.Get("ram").(int))
server.Properties.Ram = &serverRam

if v, ok := d.GetOk("cpu_family"); ok {
if v.(string) != "" {
vStr := v.(string)
Expand All @@ -1207,7 +1187,7 @@ func getServerData(d *schema.ResourceData) (*ionoscloud.Server, error) {
}
}

return &server, nil
return server, nil
}

func setResourceServerData(ctx context.Context, client *ionoscloud.APIClient, d *schema.ResourceData, server *ionoscloud.Server) error {
Expand Down