Skip to content

feat(aws): Support instance creation from AMI id - #871

Open
albfan wants to merge 1 commit into
redhat-developer:mainfrom
albfan:ami-id
Open

feat(aws): Support instance creation from AMI id#871
albfan wants to merge 1 commit into
redhat-developer:mainfrom
albfan:ami-id

Conversation

@albfan

@albfan albfan commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

fixes #626

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fdbc8fb5-72d9-4b58-b098-de030241e89c

📥 Commits

Reviewing files that changed from the base of the PR and between b2899d3 and c6b9eaa.

📒 Files selected for processing (10)
  • cmd/mapt/cmd/aws/hosts/fedora.go
  • cmd/mapt/cmd/aws/hosts/rhel.go
  • cmd/mapt/cmd/aws/hosts/rhelai.go
  • cmd/mapt/cmd/aws/hosts/windows.go
  • pkg/provider/aws/action/fedora/fedora.go
  • pkg/provider/aws/action/rhel-ai/rhelai.go
  • pkg/provider/aws/action/rhel/rhel.go
  • pkg/provider/aws/action/windows/windows.go
  • pkg/provider/aws/services/ec2/ami/ami.go
  • pkg/target/host/rhelai/api.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added support for specifying a custom AWS AMI ID when creating Fedora, RHEL, RHEL AI, and Windows hosts.
    • Host creation now uses the provided AMI ID directly when specified.
    • Existing automatic AMI selection remains available when no custom ID is supplied.

Walkthrough

AWS Fedora, RHEL, RHEL AI, and Windows host creation commands now accept optional AMI IDs. Providers resolve explicit IDs through EC2 lookup and retain existing name-based resolution when no ID is supplied.

Changes

Custom AMI deployment

Layer / File(s) Summary
AMI input contract and CLI wiring
pkg/provider/aws/action/{fedora,rhel,windows}/*.go, pkg/target/host/rhelai/api.go, cmd/mapt/cmd/aws/hosts/*
Host argument structures and Fedora, RHEL, RHEL AI, and Windows create commands expose and pass an optional AMI ID.
AMI propagation and resolution
pkg/provider/aws/action/{fedora,rhel,rhel-ai}/*.go, pkg/provider/aws/services/ec2/ami/ami.go
Requests carry the AMI ID, use GetAMIByID when provided, and otherwise retain existing name-based lookup and RHEL AI validation behavior.
Windows AMI handling
pkg/provider/aws/action/windows/windows.go
Explicit AMI IDs bypass regional AMI offering and copy logic; name-based lookup remains the fallback.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: deekay2310

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant HostCreate
  participant AMIService
  participant AWS_EC2
  CLI->>HostCreate: provide optional AMI ID
  HostCreate->>AMIService: resolve AMI
  AMIService->>AWS_EC2: lookup by image ID or name
  AWS_EC2-->>AMIService: AMI result
  AMIService-->>HostCreate: selected AMI
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: supporting instance creation from an AMI ID.
Description check ✅ Passed The description references the linked issue and stays on-topic for the AMI ID feature.
Linked Issues check ✅ Passed The PR adds AMI-ID support to AWS host create paths and lookup logic, matching #626's goal.
Out of Scope Changes check ✅ Passed The changes stay focused on AMI-ID plumbing and lookup behavior with no unrelated edits.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/provider/aws/action/snc/snc.go`:
- Around line 183-194: Declare an error variable in deploy before the r.ami
conditional so it is in scope for the AMI fallback. Keep the existing ami, err =
amiSVC.GetAMIByName assignment in the else branch, avoiding := so the outer ami
and err variables are reused rather than shadowed.

In `@pkg/provider/aws/data/ami.go`:
- Around line 168-170: Update IsAMIIDValid’s DescribeImages error handling to
return false, nil only for an error that confirms the AMI is unavailable;
propagate all other AWS lookup errors to the caller. Preserve the existing
valid-image and unavailable-AMI behavior while retaining the original error for
access, throttling, network, and configuration failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c20beb59-248f-421f-b4b2-5ea693dbbe4d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3cacf and b2899d3.

📒 Files selected for processing (4)
  • cmd/mapt/cmd/aws/services/snc.go
  • pkg/provider/aws/action/snc/snc.go
  • pkg/provider/aws/data/ami.go
  • pkg/target/service/snc/api.go

Comment thread pkg/provider/aws/action/snc/snc.go Outdated
Comment thread pkg/provider/aws/data/ami.go Outdated
Comment on lines +168 to +170
if err != nil {
return false, nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
rg -n -C4 'DescribeImages|return false, nil|IsAMIIDValid' pkg/provider/aws/data/ami.go pkg/provider/aws/action/snc/snc.go

Repository: redhat-developer/mapt

Length of output: 4688


🏁 Script executed:

#!/usr/bin/env bash
python3 - <<'PY'
from pathlib import Path
import re

ami = Path("pkg/provider/aws/data/ami.go").read_text()
m = re.search(r'func IsAMIIDValid\(.*?\n(?:^(?:\s*.+\n)*)', ami, re.S | re.M)
if not m:
    print("IsAMIIDValid body not found")
    raise SystemExit(0)
body = m.group(0)
print("IsAMIIDValid body:")
print(body)
print("contains DescribeImages call:", "DescribeImages(ctx, &ec2.DescribeImagesInput{" in body)
print("error block:", bool(re.search(r'if err != nil \{\s*return false, nil\s*\}', body)))
print("returns valid check:", bool(re.search(r'return result != nil && len\(result\.Images\) > 0, nil', body)))
PY

Repository: redhat-developer/mapt

Length of output: 2264


Propagate unexpected DescribeImages errors.

IsAMIIDValid converts all AWS image lookup failures to false, nil, so the caller reports access, throttling, network, and config issues as “AMI ... could not be found in region.” Only return false, nil when the error indicates the AMI is genuinely unavailable; otherwise return the error.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provider/aws/data/ami.go` around lines 168 - 170, Update IsAMIIDValid’s
DescribeImages error handling to return false, nil only for an error that
confirms the AMI is unavailable; propagate all other AWS lookup errors to the
caller. Preserve the existing valid-image and unavailable-AMI behavior while
retaining the original error for access, throttling, network, and configuration
failures.

@albfan albfan self-assigned this Jul 29, 2026

@adrianriobo adrianriobo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this in service targets (i.e. kind and openshift-snc)?

@adrianriobo

Copy link
Copy Markdown
Collaborator

Also did you try it? using the ghcr image from this PR?

@albfan

albfan commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Will remove for kind and openshift-snc and test with some existing AMI (which even request some decription key)

@adrianriobo

Copy link
Copy Markdown
Collaborator

let me know once you do it

Signed-off-by: Alberto Fanjul <afanjula@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allow deploying from a given AMI image

2 participants