Skip to content

Commit

Permalink
Remove VMware-specific checks in ProvisionMethod==image in host creation
Browse files Browse the repository at this point in the history
Removes an experimental check of the compute_attributes when using "image"-based
host creation. The backend providers need different values.

VMware for example needs the image_id as UUID, see the example file
in examples/host/vmware_imagebased_host.tf

Refs #125
  • Loading branch information
bitkeks committed Jun 28, 2023
1 parent 155a7fe commit 6d60bff
Showing 1 changed file with 4 additions and 36 deletions.
40 changes: 4 additions & 36 deletions foreman/resource_foreman_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,42 +1051,10 @@ func resourceForemanHostCreate(ctx context.Context, d *schema.ResourceData, meta
log.Debugf("ForemanHost: [%+v]", h)
hostRetryCount := d.Get("retry_count").(int)

// This query allows to distinguish between different compute resource providers.
// See below how it is used in VMware and its usage of UUIDs for images.

// Sometimes failes with '{"message":"undefined method `resource_pools' for nil:NilClass"}'
// Source: https://github.com/fog/fog-vsphere/blob/ca07a0d41f1d1d07e4d791887c0875523fb91da8/lib/fog/vsphere/models/compute/cluster.rb#L15
// computeResource, readErr := client.ReadComputeResource(ctx, *h.ComputeResourceId)
// if readErr != nil {
// return diag.FromErr(readErr)
// }
// log.Debugf("computeResource: [%+v]", computeResource)

var diags diag.Diagnostics
if h.ProvisionMethod == "image" { // && strings.ToLower(computeResource.Provider) == "vmware" {
// TODO: is this only vmware specific? Do other providers use the UUID for their images as well?
log.Debugf("ProvisionMethod is image, provider is vmware - checking ComputeAttributes")
if h.ComputeAttributes == nil {
diag := diag.Diagnostic{
Severity: diag.Error,
Summary: "Provision method 'image' needs image_id in compute_attributes",
Detail: "When choosing the provision method 'image' you need to provide the image UUID in the 'compute_attributes' (JSON) field 'image_id'.",
}
diags = append(diags, diag)
return diags

} else if _, ok := h.ComputeAttributes["image_id"]; !ok {
log.Debugf("image_id is not in ComputeAttributes,")
diag := diag.Diagnostic{
Severity: diag.Error,
Summary: "Compute attributes need to contain the 'image_id' field when using image-based provisioning",
Detail: fmt.Sprintf("You defined the JSON for 'compute_attributes' for host %s, but did not provide the field 'image_id' "+
"which must be the image UUID you wish to use.", h.Name),
}
diags = append(diags, diag)
return diags
}
}
// See commit ad2b5890f09645513b520f12291546f26b812c96 for an experimental implementation
// for checks of the "computeAttributes" field, when using ProvisionMethod=image.
// The feature was removed because it was VMware-specific and the test on the backend provider
// could not yet be implemented (via client.ReadComputeResource -> computeResource.Provider)

createdHost, createErr := client.CreateHost(ctx, h, hostRetryCount)
if createErr != nil {
Expand Down

0 comments on commit 6d60bff

Please sign in to comment.