Skip to content

Commit

Permalink
fix(HMS-2640): machine type is required
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Oct 23, 2023
1 parent 40701c3 commit 8f2c413
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions internal/services/gcp_reservation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func CreateGCPReservation(w http.ResponseWriter, r *http.Request) {
return
}

// Check machine type for "This organization policy prevents creating instances with exotic machine types. Contact the IT Public Cloud team at help.redhat.com for an exception"
if payload.MachineType == "" {
renderError(w, r, payloads.NewInvalidRequestError(r.Context(), "Machine type must be present even when a template is in use", ErrBothTypeAndTemplateMissing))
return
}

namePattern := "inst-####"
// Verify name pattern is lower cased and add #####
if payload.NamePattern != "" {
Expand Down
1 change: 1 addition & 0 deletions internal/services/reservations_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
ErrUnknownInstanceTypeName = errors.New("unknown instance type")
ErrArchitectureMismatch = errors.New("instance type and image architecture mismatch")
ErrBothTypeAndTemplateMissing = errors.New("instance type or launch template not set")
ErrMachineTypeMissing = errors.New("machine type missing")
ErrUnsupportedRegion = errors.New("unknown region/location/zone")
ErrInvalidNamePattern = errors.New("name pattern is not RFC-1035 compatible")
ErrPubkeyNotFound = errors.New("no pubkey found")
Expand Down
4 changes: 3 additions & 1 deletion scripts/rest_examples/http-client.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"source_id_gcp": "3",
"pubkey_id": "1",
"region": "us-east-1",
"launch_template_id": "",
"zone_gcp": "us-central1-a",
"launch_template_id_aws": "",
"launch_template_id_gcp": "",
"reservation-get-id": "1",
"azure-resource-group": "redhat-deployed"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/rest_examples/reservation-create-aws.http
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ X-Rh-Identity: {{identity}}
"source_id": "{{source_id_aws}}",
"image_id": "ami-05fa00d4c63e32376",
"amount": 1,
"launch_template_id": "{{launch_template_id}}",
"launch_template_id_aws": "{{launch_template_id}}",
"instance_type": "t2.nano",
"pubkey_id": {{pubkey_id}},
"poweroff": true
Expand Down
4 changes: 2 additions & 2 deletions scripts/rest_examples/reservation-create-gcp.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ X-Rh-Identity: {{identity}}

{
"name_pattern": "gcp-linux-eu-west8-c",
"zone": "europe-west8-c",
"zone": "{{zone_gcp}}",
"source_id": "{{source_id_gcp}}",
"image_id": "https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-9-v20230411",
"amount": 1,
"machine_type": "e2-micro",
"launch_template_id": "{{launch_template_id}}",
"launch_template_id_gcp": "{{launch_template_id}}",
"pubkey_id": {{pubkey_id}},
"poweroff": true
}

0 comments on commit 8f2c413

Please sign in to comment.