Skip to content

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

Open
deekay2310 wants to merge 5 commits into
redhat-developer:mainfrom
deekay2310:AIPCC-13797
Open

feat(ibmcloud): add IBM COS S3-compatible backend support#811
deekay2310 wants to merge 5 commits into
redhat-developer:mainfrom
deekay2310:AIPCC-13797

Conversation

@deekay2310
Copy link
Copy Markdown

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.

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.

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

coderabbitai Bot commented May 21, 2026

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: Enterprise

Run ID: 1186e165-5643-41d8-a3dd-d6eb49ebdcf5

📥 Commits

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

📒 Files selected for processing (2)
  • pkg/provider/ibmcloud/constants/constants.go
  • pkg/provider/ibmcloud/ibmcloud.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/provider/ibmcloud/constants/constants.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/provider/ibmcloud/ibmcloud.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a --keep-state flag to IBM Power and IBM Z destroy commands to preserve stack state during teardown.
  • Improvements

    • Destroy flow now separates stack destruction from state cleanup and respects the keep-state preference.
    • Improved remote-state handling for S3/COS-backed state and validation of S3-backed URLs.
    • Standardized environment variable names for IBM Cloud credential lookups.

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 isS3Path, ensureHTTPS, requireEnv, manageCOSRemoteState, and parseS3BackedURL helpers; validates S3-backed URLs and enforces an object key.
Init S3 Backend Detection
pkg/provider/ibmcloud/ibmcloud.go (Init changes)
IBMCloud.Init detects s3:// backend URLs and routes initialization through manageCOSRemoteState to set AWS-compatible env vars for COS access.
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.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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 accurately describes the main feature being introduced: IBM COS S3-compatible backend support, which aligns with the primary changes throughout the changeset.
Description check ✅ Passed The description clearly relates to the changeset, covering the introduction of IBM COS environment variables, AWS SDK remapping, DestroyStack/CleanupState functions, and --keep-state flag additions.
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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Command failed


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
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
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.

deekay2310 and others added 3 commits May 26, 2026 14:14
parseS3BackedURL could return an empty key for URLs like s3://bucket or
s3://bucket/, which would then be passed to s3.Delete. Add validation to
return a descriptive error when the object key is empty, protecting all
callers (CleanupState and DestroyStack) in both ibmcloud and aws providers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- IBM_COS_REGION now falls back to IC_REGION when not set, since IC_REGION
  is already required for compute provisioning.
- IBM_COS_ENDPOINT is no longer required; when unset it is auto-constructed
  as s3.<region>.cloud-object-storage.appdomain.cloud. Can still be
  overridden for private or cross-region endpoints.
- Required env vars reduced from 4 to 2 (IBM_COS_ACCESS_KEY_ID and
  IBM_COS_SECRET_ACCESS_KEY).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… access

Replace IBM_COS_ACCESS_KEY_ID and IBM_COS_SECRET_ACCESS_KEY with existing
IBMCLOUD_ACCOUNT and IBMCLOUD_API_KEY env vars per reviewer feedback.
Consolidate raw string references across power.go, piimages.go, and
vpcimages.go to use constants from the ibmcloud/constants package.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

…kend

Revert to HMAC credentials for COS access (IAM keys confirmed incompatible
with S3 SigV4 auth) and standardize all env vars under the IBMCLOUD_* prefix:
IBMCLOUD_COS_ACCESS_KEY_ID, IBMCLOUD_COS_SECRET_ACCESS_KEY, IBMCLOUD_COS_ENDPOINT.

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

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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