Skip to content

feat(ibmcloud): add IBM COS S3-compatible backend support#811

Merged
adrianriobo merged 1 commit into
redhat-developer:mainfrom
deekay2310:AIPCC-13797
Jun 2, 2026
Merged

feat(ibmcloud): add IBM COS S3-compatible backend support#811
adrianriobo merged 1 commit into
redhat-developer:mainfrom
deekay2310:AIPCC-13797

Conversation

@deekay2310
Copy link
Copy Markdown
Contributor

Introduce IBM_COS_* env vars (access key, secret, endpoint, region) and remap them to AWS SDK env vars in Init() so the Pulumi S3 backend can authenticate to IBM Cloud Object Storage without conflicting with AWS credentials. Add DestroyStack with lock cleanup, CleanupState for post- destroy state removal, and --keep-state flag to ibm-power/ibm-z destroy commands.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds IBM COS (S3-compatible) remote-state support with helpers and env constants, introduces exported DestroyStack/CleanupState lifecycle functions, and wires a new --keep-state flag into IBM Power and IBM Z destroy commands; replaces hardcoded IBM Cloud env lookups with constants.

Changes

IBM COS S3-Compatible Backend with Keep-State Flag

Layer / File(s) Summary
S3 Backend Constants and Helper Functions
pkg/provider/ibmcloud/constants/constants.go, pkg/provider/ibmcloud/ibmcloud.go
Adds exported IBM COS environment variable name constants; adds helpers to detect COS/S3 backends, normalize endpoints to HTTPS, validate required env vars, extract bucket/key, and configure AWS-compatible env vars for COS remote state.
DestroyStack and CleanupState Lifecycle Functions
pkg/provider/ibmcloud/ibmcloud.go
Adds exported DestroyStack(mCtx, stackName) which may remove Pulumi lock objects on force-destroy and delegates to manager.DestroyStack, and CleanupState(mCtx) which deletes Pulumi state from S3 unless keep-state is set.
CLI Keep-State Flag Wiring
cmd/mapt/cmd/ibmcloud/hosts/ibm-power.go, cmd/mapt/cmd/ibmcloud/hosts/ibm-z.go
Adds --keep-state boolean flag (default false) to IBM Power and IBM Z destroy commands and wires the flag into the destroy action args.
Action Layer Destroy Method Updates
pkg/provider/ibmcloud/action/ibm-power/ibm-power.go, pkg/provider/ibmcloud/action/ibm-z/ibm-z.go
Replace single-call ibmcloudp.Destroy teardown with explicit ibmcloudp.DestroyStack(...) followed by ibmcloudp.CleanupState(...), returning early on destroy errors.
Credential Env Constant Usage in Data & Services
pkg/provider/ibmcloud/data/piimages.go, pkg/provider/ibmcloud/data/vpcimages.go, pkg/provider/ibmcloud/services/power/power.go
Replaces hardcoded IBMCLOUD_API_KEY / IBMCLOUD_ACCOUNT string lookups with the new constants and adds the constants package imports where credentials are read.
Docs: COS backend and destroy examples
docs/ibmcloud/ibm-power.md, docs/ibmcloud/ibm-z.md
Adds COS HMAC env vars and endpoint docs, examples for --backed-url in s3:// and HTTPS forms, and updates destroy examples to show --keep-state usage.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% 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 PR title clearly and concisely describes the main feature being added: IBM COS S3-compatible backend support. It directly relates to the substantial changes throughout the codebase.
Description check ✅ Passed The description is well-related to the changeset, outlining the introduction of IBM_COS_* env vars, remapping to AWS SDK vars, adding DestroyStack/CleanupState functions, and the --keep-state flag.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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/ibmcloud/ibmcloud.go`:
- Around line 125-126: The parseS3BackedURL helper can return an empty key and
CleanupState currently calls s3.Delete with that blank key; update
parseS3BackedURL and callers (notably CleanupState and the other block around
the parse use at ~159-167) to validate that the returned key is non-empty before
attempting deletion: either return a descriptive error from parseS3BackedURL
when the URL path yields an empty key, or have CleanupState check the key and
skip/delete only when key != "" (and log/return a clear error if appropriate).
Make sure references to parseS3BackedURL, CleanupState, and s3.Delete are
updated so no Delete is invoked with an empty key.
- Around line 96-113: The code currently calls os.Setenv for AWS_* vars which
mutates process-wide state and can leak/override credentials; instead stop using
os.Setenv in this block and construct the S3 client/config with explicit
credentials and endpoint wiring (e.g. use the AWS SDK config with
credentials.NewStaticCredentialsProvider(accessKey, secretKey, ""), set Region
and a custom EndpointResolver/EndpointResolverWithOptions using
ensureHTTPS(endpoint)) so no environment mutation occurs; update the code that
previously relied on those env vars to accept or receive the aws.Config / s3
client built this way (replace the os.Setenv sequence in
pkg/provider/ibmcloud/ibmcloud.go with creation of an aws.Config/aws-sdk-v2
client using the provided accessKey, secretKey, endpoint, region).
🪄 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: Enterprise

Run ID: 641f765f-0fde-48d9-b4d1-644371b207d5

📥 Commits

Reviewing files that changed from the base of the PR and between 82e1b2d and bcbaf57.

📒 Files selected for processing (6)
  • cmd/mapt/cmd/ibmcloud/hosts/ibm-power.go
  • cmd/mapt/cmd/ibmcloud/hosts/ibm-z.go
  • pkg/provider/ibmcloud/action/ibm-power/ibm-power.go
  • pkg/provider/ibmcloud/action/ibm-z/ibm-z.go
  • pkg/provider/ibmcloud/constants/constants.go
  • pkg/provider/ibmcloud/ibmcloud.go

Comment thread pkg/provider/ibmcloud/ibmcloud.go Outdated
Comment thread pkg/provider/ibmcloud/ibmcloud.go
package constants

const (
EnvIBMCosAccessKeyID = "IBM_COS_ACCESS_KEY_ID"
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.

We already got IBMCLOUD_ACCOUNT and IBMCLOUD_API_KEY and IC_REGION which are used by the natively by the provider, should we keep those I mean use them instead ? Also what is the value for the endpoint?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since these are HMAC keys (access key + secret key) and exist specifically for S3-compatible API access, they are separate from IAM API keys and I think we should keep them separate. For region, it should be okay to use IC_REGION.

Re: endpoint - value needs to be set manually right now. Should I look into auto-constructing it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made some changes here.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/provider/ibmcloud/ibmcloud.go (1)

171-175: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't report destroy success when state deletion fails.

CleanupState logs s3.Delete errors and still returns nil. Since the action layer returns CleanupState(mCtx) directly, a failed delete still exits success even when --keep-state is false, leaving stale backend state behind.

🤖 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/ibmcloud/ibmcloud.go` around lines 171 - 175, The CleanupState
function currently swallows s3.Delete errors (calling logging.Warnf) and still
returns nil, causing callers (e.g., action layer that calls CleanupState(mCtx))
to treat a failed delete as success; update CleanupState so that if
s3.Delete(...) returns an error you propagate that error (or wrap it with
context) instead of returning nil—refer to the s3.Delete call, the
mCtx.Context() usage, and the existing logging.Warnf/Info calls in CleanupState
to locate the change, and ensure the success log (logging.Info) only runs when
no error is returned.
🤖 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.

Outside diff comments:
In `@pkg/provider/ibmcloud/ibmcloud.go`:
- Around line 171-175: The CleanupState function currently swallows s3.Delete
errors (calling logging.Warnf) and still returns nil, causing callers (e.g.,
action layer that calls CleanupState(mCtx)) to treat a failed delete as success;
update CleanupState so that if s3.Delete(...) returns an error you propagate
that error (or wrap it with context) instead of returning nil—refer to the
s3.Delete call, the mCtx.Context() usage, and the existing logging.Warnf/Info
calls in CleanupState to locate the change, and ensure the success log
(logging.Info) only runs when no error is returned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 5f9f2a0c-59d2-4601-9ceb-91297d542cbc

📥 Commits

Reviewing files that changed from the base of the PR and between 4e06f0c and d2fd5ca.

📒 Files selected for processing (5)
  • pkg/provider/ibmcloud/constants/constants.go
  • pkg/provider/ibmcloud/data/piimages.go
  • pkg/provider/ibmcloud/data/vpcimages.go
  • pkg/provider/ibmcloud/ibmcloud.go
  • pkg/provider/ibmcloud/services/power/power.go

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@adrianriobo
Copy link
Copy Markdown
Collaborator

@deekay2310 can you add sample of usage within the docs for IBM also the squash commits and I think we are good to go

@adrianriobo
Copy link
Copy Markdown
Collaborator

NVM doc is all good, once you tested with last artifacts squash all commits then I will LGTM

@deekay2310
Copy link
Copy Markdown
Contributor Author

The COS Backend connection worked and Pulumi connected to COS successfully. Just going to need to harden how we delete the resources.

Add provider-specific env vars (IBMCLOUD_COS_ACCESS_KEY_ID,
IBMCLOUD_COS_SECRET_ACCESS_KEY, IBMCLOUD_COS_ENDPOINT) and map them
to AWS SDK env vars so the Pulumi S3 backend can authenticate to IBM
Cloud Object Storage. Construct the full Pulumi backend URL with
endpoint query params via Provider.Init() return value, ensuring
Pulumi connects to COS instead of amazonaws.com.

Also adds DestroyStack with lock cleanup, CleanupState for post-destroy
state removal, --keep-state flag, empty key guard in parseS3BackedURL,
and consolidates IBMCLOUD_* string constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@adrianriobo adrianriobo left a comment

Choose a reason for hiding this comment

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

LGTM

@adrianriobo adrianriobo merged commit 47ddfb2 into redhat-developer:main Jun 2, 2026
9 checks passed
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.

2 participants