Skip to content

feat: add !aws.organization_id YAML function#2117

Merged
aknysh merged 10 commits intomainfrom
aknysh/aws.organization_id
Feb 27, 2026
Merged

feat: add !aws.organization_id YAML function#2117
aknysh merged 10 commits intomainfrom
aknysh/aws.organization_id

Conversation

@aknysh
Copy link
Member

@aknysh aknysh commented Feb 26, 2026

what

  • Add a new !aws.organization_id YAML function that retrieves the AWS Organization ID by calling the AWS Organizations DescribeOrganization API
  • New pkg/aws/organization/ package with Getter interface, per-auth-context caching with double-checked locking, and mock support
  • Full integration with Atmos Authentication — uses credentials from the active identity when available, falls back to standard AWS SDK credential resolution
  • Handles AWSOrganizationsNotInUseException with a clear error message when the account is not in an organization
  • Added ErrAwsDescribeOrganization sentinel error
  • Updated Go toolchain references to 1.26

why

  • Users need to reference the AWS Organization ID in stack configurations for governance, tagging, cross-account trust policies, and SCP scoping
  • Currently the organization ID must be hardcoded or retrieved through workarounds
  • This is the Atmos equivalent of Terragrunt's get_aws_org_id() function
  • Closes Add !aws.organization_id YAML function #2073

references

Summary by CodeRabbit

Release Notes

  • New Features

    • Added !aws.organization_id YAML function to retrieve AWS Organization ID from stack configurations with automatic per-invocation caching.
  • Chores

    • Updated Go toolchain from 1.25 to 1.26.
    • Updated Atmos installer version from 1.206.0 to 1.208.0.
    • Updated AWS SDK and other key dependencies to latest stable versions.
  • Documentation

    • Added comprehensive documentation and blog post for the new AWS Organization ID function, including usage examples and prerequisites.

aknysh and others added 2 commits February 26, 2026 18:32
Add a new `!aws.organization_id` YAML function that retrieves the AWS
Organization ID by calling the AWS Organizations DescribeOrganization API.
This complements the existing AWS context functions and is equivalent to
Terragrunt's `get_aws_org_id()`.

- Create `pkg/aws/organization/` package with Getter interface, caching,
  and mock support (parallel to `pkg/aws/identity/`)
- Register tag constants in both modern (`pkg/function/tags.go`) and
  legacy (`pkg/utils/yaml_utils.go`) layers
- Implement modern layer function in `pkg/function/aws.go`
- Implement legacy layer handler in `internal/exec/yaml_func_aws.go`
- Add routing in `internal/exec/yaml_func_utils.go`
- Add comprehensive unit tests across all three layers
- Add documentation, blog post, PRD, and roadmap update
- Update Go version references from 1.24/1.25 to 1.26

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document how the function integrates with Atmos Authentication,
including auth context flow, credential resolution, stack-level
configuration, and per-auth-context caching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aknysh aknysh added the minor New features that do not break anything label Feb 26, 2026
@aknysh aknysh requested review from a team as code owners February 26, 2026 23:58
@github-actions github-actions bot added the size/xl Extra large size PR label Feb 26, 2026
@github-actions
Copy link

github-actions bot commented Feb 26, 2026

🚀 Go Version Change Detected

This PR changes the Go version:

  • Base branch (main): 1.25.5
  • This PR: 1.26
  • Change: ⬆️ Upgrade

Tip

Upgrade Checklist

  • Verify all CI workflows pass with new Go version
  • Check for new language features that could be leveraged
  • Review release notes: https://go.dev/doc/go1
  • Update .tool-versions if using asdf
  • Update Dockerfile Go version if applicable

This is an automated comment from the Go Version Check action.

@aknysh aknysh self-assigned this Feb 26, 2026
@mergify
Copy link

mergify bot commented Feb 26, 2026

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@mergify
Copy link

mergify bot commented Feb 26, 2026

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label Feb 26, 2026
@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 12 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
github.com/aws/aws-sdk-go-v21.41.2NullUnknown License
github.com/aws/aws-sdk-go-v2/config1.32.10NullUnknown License
github.com/aws/aws-sdk-go-v2/credentials1.19.10NullUnknown License
github.com/aws/aws-sdk-go-v2/service/organizations1.50.3NullUnknown License
github.com/aws/aws-sdk-go-v2/service/s31.96.2NullUnknown License
github.com/aws/aws-sdk-go-v2/service/sso1.30.11NullUnknown License
github.com/aws/aws-sdk-go-v2/service/ssooidc1.35.15NullUnknown License
github.com/docker/cli29.2.1+incompatibleNullUnknown License
github.com/getsentry/sentry-go0.43.0NullUnknown License
github.com/go-git/go-git/v55.17.0NullUnknown License
github.com/mattn/go-runewidth0.0.20NullUnknown License
github.com/zclconf/go-cty1.18.0NullUnknown License
Allowed Licenses: MIT, MIT-0, Apache-2.0, BSD-2-Clause, BSD-2-Clause-Views, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-3.0, Python-2.0, OFL-1.1, LicenseRef-scancode-generic-cla, LicenseRef-scancode-unknown-license-reference, LicenseRef-scancode-unicode, LicenseRef-scancode-google-patent-license-golang

Scanned Files

  • go.mod

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

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

Introduces a new !aws.organization_id YAML function to retrieve AWS Organization ID via the AWS Organizations API. Includes a new caching-enabled organization package, function handler registration, updated Go toolchain from 1.25 to 1.26, expanded test coverage, and documentation across blog and function references.

Changes

Cohort / File(s) Summary
Go Toolchain & Build Configuration
.devcontainer/Dockerfile, .github/actions/go-version-check/README.md, CLAUDE.md, docs/development.md, demo/screengrabs/Makefile, tools/gomodcheck/go.mod
Updated Go version requirement and toolchain from 1.25 to 1.26 across dev containers, documentation, and build configurations.
Dependency Updates
go.mod, NOTICE
Bumped Go toolchain to 1.26 and updated AWS SDK v2 components, Docker CLI, go-git, OPA, and other transitive dependencies to newer patch/minor versions.
AWS Organizations Core Package
pkg/aws/organization/organization.go, pkg/aws/organization/organization_test.go, pkg/aws/organization/mock_organization.go
New package implementing Organization and Getter interfaces with per-auth-context caching, DescribeOrganization API integration, and test mocks.
YAML Function Handler Integration
internal/exec/yaml_func_aws.go, internal/exec/yaml_func_aws_test.go, internal/exec/yaml_func_utils.go, internal/exec/aws_getter.go
Added processTagAwsOrganizationID handler, type aliases and cache helpers for organization integration, and wired function into YAML processing pipeline with extensive unit tests.
Function Layer Registration
pkg/function/aws.go, pkg/function/aws_test.go, pkg/function/defaults.go, pkg/function/tags.go, pkg/function/tags_test.go
Introduced AwsOrganizationIDFunction, registered function defaults, added TagAwsOrganizationID constant, and updated tag mappings with corresponding tests.
YAML Utilities
pkg/utils/yaml_utils.go, pkg/utils/yaml_utils_test.go
Added AtmosYamlFuncAwsOrganizationID constant and registered it in tag lookup map and slice.
Error Handling
errors/errors.go
Added ErrAwsDescribeOrganization sentinel error for organization API failures.
Documentation & Examples
docs/prd/aws-organization-id-yaml-function.md, website/docs/functions/yaml/aws.organization-id.mdx, website/blog/2026-02-26-aws-organization-id-yaml-function.mdx, website/docs/functions/yaml/aws*.mdx, website/src/data/roadmap.js
New comprehensive PRD, dedicated function docs, blog announcement, cross-references in related AWS functions, and roadmap milestone entry.
Test Configuration
pkg/devcontainer/lifecycle_rebuild_test.go, examples/quick-start-advanced/Dockerfile
Updated expected Atmos version from 1.206.0 to 1.208.0 in test assertions and Dockerfile.
Linting Configuration
.golangci.yml, .pre-commit-config.yaml
Added AWS organization package exclusion to depguard rule and updated Go compatibility comment.

Sequence Diagram(s)

sequenceDiagram
    participant Client as YAML Parser
    participant Handler as yaml_func_aws
    participant Cache as Organization Cache
    participant AWSSDk as AWS SDK
    
    Client->>Handler: processTagAwsOrganizationID(input)
    Handler->>Handler: Validate input tag
    Handler->>Handler: Extract auth context from stackInfo
    Handler->>Cache: GetOrganizationCached(ctx, config, authContext)
    alt Cache Hit
        Cache-->>Handler: Return cached OrganizationInfo
    else Cache Miss
        Cache->>AWSSDk: DescribeOrganization()
        AWSSDk-->>Cache: Organization details
        Cache->>Cache: Store in cache with auth context key
        Cache-->>Handler: Return OrganizationInfo
    end
    Handler->>Handler: Extract organization ID
    Handler-->>Client: Return organization ID string
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • osterman
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.55% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding a new !aws.organization_id YAML function. It directly matches the primary objective from the linked issue.
Linked Issues check ✅ Passed The pull request fully implements the requirements from issue #2073: adds the !aws.organization_id YAML function that retrieves the AWS Organization ID via the DescribeOrganization API [#2073].
Out of Scope Changes check ✅ Passed Changes are scoped to the AWS organization ID feature implementation. Go toolchain updates (1.24/1.25 to 1.26) and dependency bumps are necessary infrastructure changes to support the feature, not extraneous.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aknysh/aws.organization_id

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.

…d tags

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

@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: 6

🧹 Nitpick comments (2)
internal/exec/yaml_func_aws.go (1)

184-192: Add a defensive guard before dereferencing organization info.

A nil/empty response from the getter path will currently panic or return a silent empty value.

Suggested hardening
 	orgInfo, err := getAWSOrganizationCached(ctx, atmosConfig, authContext)
 	if err != nil {
 		log.Error("Failed to get AWS organization info", "error", err)
 		errUtils.CheckErrorPrintAndExit(err, "", "")
 		return nil
 	}
+
+	if orgInfo == nil || orgInfo.ID == "" {
+		log.Error("Failed to get AWS organization info", "error", errUtils.ErrAwsDescribeOrganization)
+		errUtils.CheckErrorPrintAndExit(errUtils.ErrAwsDescribeOrganization, "", "")
+		return nil
+	}
 
 	log.Debug("Resolved !aws.organization_id", "organization_id", orgInfo.ID)
 	return orgInfo.ID
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/exec/yaml_func_aws.go` around lines 184 - 192, The code calls
getAWSOrganizationCached and immediately dereferences orgInfo.ID; add a
defensive guard to check orgInfo for nil and orgInfo.ID for empty before using
it. Specifically, after the call to getAWSOrganizationCached (in
yaml_func_aws.go) check if orgInfo == nil || orgInfo.ID == "" and if so log an
error via log.Error (include context like "empty or nil orgInfo") and call
errUtils.CheckErrorPrintAndExit (or return an appropriate error) instead of
proceeding to log.Debug and return orgInfo.ID, so you never dereference a nil
orgInfo or return an empty ID.
internal/exec/yaml_func_aws_test.go (1)

766-804: Add an explicit failure-path case for processTagAwsOrganizationID.

The table includes mockErr, but all rows are success cases. Add one non-nil error case so the new function’s error behavior is asserted, not inferred.

As per coding guidelines "Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/exec/yaml_func_aws_test.go` around lines 766 - 804, Add a
failing-case row to TestProcessTagAwsOrganizationID that sets mockErr to a
non-nil error (e.g. errors.New("fetch error")) and asserts the function's
error-path output (typically an empty string) by adding a test case named like
"error fetching org info" to the tests slice; use the same helpers
(runAWSOrgYamlFuncTest, processTagAwsOrganizationID, AWSOrganizationInfo) so the
test verifies the function returns the expectedResult when mockErr is returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.devcontainer/Dockerfile:
- Line 1: The final image currently runs as root; update the Dockerfile's final
build stage by adding a non-root runtime user assignment (e.g., set USER vscode)
so containers start with non-root privileges; locate the final stage in the
Dockerfile (the stage labeled or ending with the runtime artifacts, after AS
confetty) and append the USER vscode directive (and ensure the vscode user
exists or is created earlier in the Dockerfile) to enforce the non-root runtime
user.

In `@NOTICE`:
- Around line 160-163: The NOTICE file is out of sync and must be regenerated
rather than edited manually; run the provided script
./scripts/generate-notice.sh to regenerate NOTICE (ensuring it captures the
github.com/aws/aws-sdk-go-v2/service/organizations entry and any other changes),
review the updated NOTICE for correctness, and commit the regenerated NOTICE
output to the branch before merging.

In `@pkg/aws/organization/organization_test.go`:
- Around line 16-42: Replace the manual mocks mockOrgGetter and
countingOrgGetter with the generated MockGetter from mock_organization.go:
remove types mockOrgGetter and countingOrgGetter, import/use MockGetter, and set
expectations in tests with MockGetter.EXPECT().GetOrganization(ctx, atmosConfig,
authContext).Return(<desired>, <err>).Times(n) to both supply return values and
verify call counts; update any test setup referencing mockOrgGetter or
countingOrgGetter to construct a *MockGetter and configure
EXPECT().GetOrganization(...) accordingly.

In `@pkg/aws/organization/organization.go`:
- Around line 55-58: The call to awsIdentity.LoadConfigWithAuth in
organization.go returns a raw error instead of being wrapped with the project
standard; replace the direct return of err with a wrapped error using
ErrAwsDescribeOrganization and ErrWrapFormat (the same pattern used later on
lines returning ErrAwsDescribeOrganization) so all organization lookup failures
are classified uniformly—wrap the error from awsIdentity.LoadConfigWithAuth with
fmt.Sprintf(ErrWrapFormat, ErrAwsDescribeOrganization, err) (or the project's
equivalent) before returning.

In `@pkg/function/aws_test.go`:
- Around line 315-326: Add a go:generate directive to the organization.Getter
interface declaration so mockgen can produce a mock for it (e.g., add
"//go:generate mockgen -destination=mock_organization.go -package=organization
<module>/pkg/aws/organization Organization" next to the interface in
organization.go), run mockgen to generate the mock, then remove the hand-written
mock type mockAWSOrgGetter and update the test to use the generated mock
(construct the generated mock struct, set its EXPECT() for GetOrganization(ctx,
atmosConfig, authContext) to return the desired (*awsOrg.OrganizationInfo,
error) values). Ensure references to the hand-rolled mockAWSOrgGetter and its
GetOrganization method are replaced with the generated mock's methods and
import.

In `@website/src/data/roadmap.js`:
- Line 378: The roadmap entry object with label '`!aws.organization_id` YAML
function' in website/src/data/roadmap.js is missing the required PR metadata;
add a pr: 2117 property to that object (the same object that has status:
'shipped', changelog: 'aws-organization-id-yaml-function') so shipped milestones
tied to minor/major PRs include the PR number, and after adding it, update the
related initiative's progress percentage to reflect this shipped milestone.

---

Nitpick comments:
In `@internal/exec/yaml_func_aws_test.go`:
- Around line 766-804: Add a failing-case row to TestProcessTagAwsOrganizationID
that sets mockErr to a non-nil error (e.g. errors.New("fetch error")) and
asserts the function's error-path output (typically an empty string) by adding a
test case named like "error fetching org info" to the tests slice; use the same
helpers (runAWSOrgYamlFuncTest, processTagAwsOrganizationID,
AWSOrganizationInfo) so the test verifies the function returns the
expectedResult when mockErr is returned.

In `@internal/exec/yaml_func_aws.go`:
- Around line 184-192: The code calls getAWSOrganizationCached and immediately
dereferences orgInfo.ID; add a defensive guard to check orgInfo for nil and
orgInfo.ID for empty before using it. Specifically, after the call to
getAWSOrganizationCached (in yaml_func_aws.go) check if orgInfo == nil ||
orgInfo.ID == "" and if so log an error via log.Error (include context like
"empty or nil orgInfo") and call errUtils.CheckErrorPrintAndExit (or return an
appropriate error) instead of proceeding to log.Debug and return orgInfo.ID, so
you never dereference a nil orgInfo or return an empty ID.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d18a81a and 18c809b.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (34)
  • .devcontainer/Dockerfile
  • .github/actions/go-version-check/README.md
  • .golangci.yml
  • .pre-commit-config.yaml
  • CLAUDE.md
  • NOTICE
  • demo/screengrabs/Makefile
  • docs/development.md
  • docs/prd/aws-organization-id-yaml-function.md
  • errors/errors.go
  • examples/quick-start-advanced/Dockerfile
  • go.mod
  • internal/exec/aws_getter.go
  • internal/exec/yaml_func_aws.go
  • internal/exec/yaml_func_aws_test.go
  • internal/exec/yaml_func_utils.go
  • pkg/aws/organization/organization.go
  • pkg/aws/organization/organization_test.go
  • pkg/devcontainer/lifecycle_rebuild_test.go
  • pkg/function/aws.go
  • pkg/function/aws_test.go
  • pkg/function/defaults.go
  • pkg/function/tags.go
  • pkg/function/tags_test.go
  • pkg/utils/yaml_utils.go
  • pkg/utils/yaml_utils_test.go
  • tools/gomodcheck/go.mod
  • website/blog/2026-02-26-aws-organization-id-yaml-function.mdx
  • website/docs/functions/yaml/aws.account-id.mdx
  • website/docs/functions/yaml/aws.caller-identity-arn.mdx
  • website/docs/functions/yaml/aws.caller-identity-user-id.mdx
  • website/docs/functions/yaml/aws.organization-id.mdx
  • website/docs/functions/yaml/aws.region.mdx
  • website/src/data/roadmap.js

…number

- Replace manual mocks with generated MockGetter (go.uber.org/mock) in
  organization_test.go and aws_test.go per repo conventions
- Add defensive nil/empty guard before dereferencing orgInfo in
  processTagAwsOrganizationID (legacy layer)
- Add subprocess-based error path tests for processTagAwsOrganizationID
  (getter error, nil info, empty ID all cause os.Exit)
- Wrap config-loading error with ErrAwsDescribeOrganization using
  standard ErrWrapFormat pattern
- Add pr: 2117 to roadmap milestone

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

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/exec/yaml_func_aws_test.go`:
- Around line 841-842: The -test.run argument passed to exec.Command uses an
unanchored regex which can match unintended tests; update the argument for the
subprocess invocation (the exec.Command call that uses os.Args[0] and
"-test.run=TestProcessTagAwsOrganizationID_ErrorHelper") to use an anchored
regex by changing the value to
"-test.run=^TestProcessTagAwsOrganizationID_ErrorHelper$" so only that exact
helper test is executed.
- Around line 731-743: Replace the handwritten mock type
mockAWSOrganizationGetter and its GetOrganization method with the generated
gomock MockGetter from pkg/aws/organization: remove the
mockAWSOrganizationGetter struct and its method, import the generated mock
package, create a mock via organization.NewMockGetter(ctrl) (using
gomock.NewController in the test setup), and replace uses of
mockAWSOrganizationGetter with the MockGetter and its
EXPECT().GetOrganization(...).Return(...) setup so tests follow the existing
gomock pattern.

In `@pkg/aws/organization/organization.go`:
- Around line 108-116: SetGetter currently allows setting a nil Getter which
will cause a panic later when getter.GetOrganization is called; update SetGetter
to guard against nil by checking if g == nil and either (a) reject it
immediately with a clear panic or error (e.g., panic("organization.SetGetter:
nil Getter provided")) or (b) substitute a safe no-op/default implementation so
future calls to getter.GetOrganization won't panic; implement the chosen
approach inside SetGetter and ensure the returned restore func still restores
the original getter. Refer to SetGetter, Getter, getter and GetOrganization when
making the change.
- Around line 76-78: The current nil-check for org returns (info, nil) which
hides an anomalous AWS response; instead when org == nil return a wrapped
ErrAwsDescribeOrganization error (including context such as the AWS account or
request ID if available) rather than nil error. Update the nil branch in the
function that inspects org (the org variable in
pkg/aws/organization/organization.go) to return the zero info and
fmt.Errorf("...: %w", ErrAwsDescribeOrganization) or errors.Wrap-style error so
callers get a clear, typed error instead of an empty ID.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 18c809b and 48e7fad.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • NOTICE
  • go.mod
  • internal/exec/yaml_func_aws.go
  • internal/exec/yaml_func_aws_test.go
  • pkg/aws/organization/mock_organization.go
  • pkg/aws/organization/organization.go
  • pkg/aws/organization/organization_test.go
  • pkg/function/aws_test.go
  • tests/snapshots/TestCLICommands_atmos_auth_validate_--verbose.stderr.golden
  • tests/snapshots/TestCLICommands_atmos_describe_config_imports.stderr.golden
  • tests/snapshots/TestCLICommands_atmos_describe_configuration.stderr.golden
  • tests/snapshots/TestCLICommands_echo_info_runs_with_verbose_flag.stderr.golden
  • website/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • NOTICE
  • pkg/function/aws_test.go
  • internal/exec/yaml_func_aws.go

- Replace manual mockAWSOrganizationGetter and countingAWSOrgGetter with
  generated awsOrg.NewMockGetter(ctrl) in internal/exec tests
- Anchor -test.run regex with ^...$ in subprocess error tests
- Return wrapped error instead of empty info when Organization payload is nil
- Guard SetGetter against nil injection (falls back to defaultGetter)
- Revert golden snapshots to main (remove env-specific gh auth debug line)

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

@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 the current code and only fix it if needed.

Inline comments:
In `@internal/exec/yaml_func_aws_test.go`:
- Around line 747-752: The test uses gomock.AnyTimes() on the
awsOrg.NewMockGetter().GetOrganization expectation which can hide missed or
extra calls; replace AnyTimes() with a strict Times(n) (e.g., Times(1) if the
getter should be called once) so the test asserts the exact invocation count for
GetOrganization. Do the same change for the other occurrence of the same
expectation (the block around lines shown for the second test), keeping the same
mock (awsOrg.NewMockGetter / mock) and expectation setup but swapping AnyTimes()
for the appropriate Times(...) value.
- Around line 839-842: The test currently only checks for a non-nil error from
cmd.Run() when tt.wantErr is true; change this to assert that the error is an
*exec.ExitError and that its ExitCode() == 1. After calling cmd.Run() in the
test (the same spot where tt.wantErr is checked), use errors.As (or a type
assertion) to extract an *exec.ExitError from err and assert the extraction
succeeded, then assert exitErr.ExitCode() == 1; keep behavior unchanged when
tt.wantErr is false.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 48e7fad and 80c023a.

📒 Files selected for processing (2)
  • internal/exec/yaml_func_aws_test.go
  • pkg/aws/organization/organization.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/aws/organization/organization.go

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 93.43066% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.52%. Comparing base (50b760f) to head (49672dc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/aws/organization/organization.go 93.33% 4 Missing and 1 partial ⚠️
internal/exec/yaml_func_aws.go 81.81% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2117      +/-   ##
==========================================
+ Coverage   76.49%   76.52%   +0.03%     
==========================================
  Files         831      832       +1     
  Lines       79254    79391     +137     
==========================================
+ Hits        60624    60753     +129     
- Misses      14837    14842       +5     
- Partials     3793     3796       +3     
Flag Coverage Δ
unittests 76.52% <93.43%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
internal/exec/aws_getter.go 100.00% <100.00%> (ø)
internal/exec/yaml_func_utils.go 92.30% <100.00%> (+0.15%) ⬆️
pkg/function/aws.go 100.00% <100.00%> (ø)
pkg/function/defaults.go 89.28% <100.00%> (+0.39%) ⬆️
pkg/function/tags.go 100.00% <100.00%> (ø)
pkg/utils/yaml_utils.go 84.88% <ø> (ø)
internal/exec/yaml_func_aws.go 82.85% <81.81%> (-0.48%) ⬇️
pkg/aws/organization/organization.go 93.33% <93.33%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Replace manual mocks with gomock-generated mocks across all test files
- Tighten mock expectations from AnyTimes() to Times(1)
- Add specific exit code assertion in subprocess error tests
- Add organizationsAPI interface + injectable factory variables for
  testable defaultGetter.GetOrganization (was 0%, now 100%)
- Add TestSetGetter_NilFallback for nil guard branch coverage
- Add 7 defaultGetter unit tests: success, nil fields, config error,
  describe error, not-in-org error, nil payload, auth context passthrough
- Regenerate mock_organization.go with both Getter and organizationsAPI
- Overall organization package coverage: 47.88% → 95.3%

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

@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 the current code and only fix it if needed.

Inline comments:
In `@pkg/aws/organization/organization.go`:
- Around line 162-169: getCacheKey currently builds a colon-joined key which can
collide when fields contain ":"; update getCacheKey to produce a collision-safe
key by canonicalizing the three fields (authContext.Profile,
authContext.CredentialsFile, authContext.ConfigFile) and hashing them (e.g.,
SHA-256) or JSON-marshaling the struct and using the result as the cache key;
keep the nil check and return a deterministic string (e.g., hex hash or
marshaled string) instead of fmt.Sprintf("%s:%s:%s", ...).
- Around line 83-99: The code currently dereferences output.Organization without
ensuring output is non-nil after calling orgClient.DescribeOrganization; update
the DescribeOrganization handling (the call to orgClient.DescribeOrganization
and subsequent uses of output) to first check if output == nil and return a
wrapped errUtils.ErrAwsDescribeOrganization with a clear message if so, then
proceed to check output.Organization for nil as before (referencing output,
output.Organization and the org variable) to avoid a potential panic on
anomalous SDK responses.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 80c023a and 9887dac.

📒 Files selected for processing (8)
  • internal/exec/yaml_func_aws_test.go
  • pkg/aws/organization/mock_organization.go
  • pkg/aws/organization/organization.go
  • pkg/aws/organization/organization_test.go
  • tests/snapshots/TestCLICommands_atmos_auth_validate_--verbose.stderr.golden
  • tests/snapshots/TestCLICommands_atmos_describe_config_imports.stderr.golden
  • tests/snapshots/TestCLICommands_atmos_describe_configuration.stderr.golden
  • tests/snapshots/TestCLICommands_echo_info_runs_with_verbose_flag.stderr.golden

- Guard nil DescribeOrganization output before dereferencing Organization
- Add TestDefaultGetter_GetOrganization_NilOutput for the new guard
- Make cache keys collision-safe using %q with | delimiter
- Revert golden snapshots to remove env-specific gh auth debug line

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

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

🧹 Nitpick comments (1)
pkg/aws/organization/organization_test.go (1)

185-192: Minor defensive improvement for goroutines.

If assertions fail inside goroutines, assert won't stop execution - subsequent info.ID access could panic on nil. While the mock guarantees success here, a guard would be more resilient to future refactoring.

💡 Optional defensive pattern
 go func() {
     defer wg.Done()
     info, err := GetOrganizationCached(ctx, atmosConfig, nil)
-    assert.NoError(t, err)
-    assert.Equal(t, "o-concurrent", info.ID)
+    if assert.NoError(t, err) && info != nil {
+        assert.Equal(t, "o-concurrent", info.ID)
+    }
 }()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/aws/organization/organization_test.go` around lines 185 - 192, In the
goroutine calling GetOrganizationCached, avoid potential nil dereference on
info.ID by guarding after the assert: check the returned err and/or info before
accessing info.ID (e.g., after assert.NoError(t, err) add if err != nil || info
== nil { return } ), or use an early return when err != nil; target the
anonymous goroutine containing GetOrganizationCached, the assert.NoError call,
and the subsequent info.ID access to add this defensive guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/aws/organization/organization_test.go`:
- Around line 185-192: In the goroutine calling GetOrganizationCached, avoid
potential nil dereference on info.ID by guarding after the assert: check the
returned err and/or info before accessing info.ID (e.g., after assert.NoError(t,
err) add if err != nil || info == nil { return } ), or use an early return when
err != nil; target the anonymous goroutine containing GetOrganizationCached, the
assert.NoError call, and the subsequent info.ID access to add this defensive
guard.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9887dac and f60cfd6.

📒 Files selected for processing (2)
  • pkg/aws/organization/organization.go
  • pkg/aws/organization/organization_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/aws/organization/organization.go

@aknysh aknysh requested a review from osterman February 27, 2026 05:52
@aknysh aknysh merged commit ff71e77 into main Feb 27, 2026
61 of 62 checks passed
@aknysh aknysh deleted the aknysh/aws.organization_id branch February 27, 2026 17:37
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Feb 27, 2026
@github-actions
Copy link

Warning

Release Documentation Required

This PR is labeled minor or major and requires documentation updates:

  • Changelog entry - Add a blog post in website/blog/YYYY-MM-DD-feature-name.mdx
  • Roadmap update - Update website/src/data/roadmap.js with the new milestone

Alternatively: If this change doesn't require release documentation, remove the minor or major label.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

These changes were released in v1.208.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add !aws.organization_id YAML function

2 participants