From 8fd80ad8017a2f04914e25fcb88a8e80dd466b6c Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sat, 31 Oct 2026 11:41:34 -0500 Subject: [PATCH 01/75] feat(terragrunt): add typed flags, executable mode, exact values, logs, and Atmos Pro support Declare provider options in the plugin manifest so the Terragrunt flags and help appear on atmos terraform commands. Add executable mode, which runs one pinned terragrunt per unit under Atmos scheduling, authentication, and toolchain. Pass unit inputs as exact values with sensitive inputs masked and kept out of varfiles, resolve plugin AWS calls from the invocation identity, and forward Terragrunt log events through the Atmos logger. Make units ordinary Atmos Pro instances and support applying a saved plan on another runner by shipping the plan record with the planfile and re-provisioning the working directory. Set the OCI image source annotation on published plugins and install the example from the registry. Co-Authored-By: Claude Sonnet 5.5 --- .golangci.yml | 5 + cmd/help_template.go | 23 +- cmd/help_template_test.go | 52 + cmd/help_topics_render.go | 5 +- cmd/plugin/author.go | 8 +- cmd/plugin/publish_safety_test.go | 31 + cmd/plugin/release.go | 45 +- cmd/root.go | 7 +- cmd/terraform/planfile/download.go | 3 +- cmd/terraform/planfile/resolve.go | 21 + cmd/terraform/planfile/resolve_test.go | 29 + cmd/terraform/planfile/upload.go | 9 +- cmd/terraform/terraform.go | 30 + cmd/terraform/utils.go | 24 + cmd/terraform/utils_test.go | 22 + errors/plugin.go | 10 + examples/terragrunt-native/README.md | 60 +- examples/terragrunt-native/atmos.yaml | 14 +- .../terragrunt-native/profiles/dev/atmos.yaml | 4 +- pkg/ci/plugins/terraform/handlers.go | 6 + pkg/ci/plugins/terraform/handlers_test.go | 76 ++ .../plugins/terraform/planfile/interface.go | 9 + pkg/ci/plugins/terraform/planfile/write.go | 24 +- .../plugins/terraform/planfile/write_test.go | 46 + pkg/component/helm/aggregate_ci_test.go | 4 +- pkg/component/provideroptions/flags.go | 350 ++++++ pkg/component/provideroptions/options.go | 294 ++++++ .../provideroptions/provideroptions_test.go | 246 +++++ pkg/component/terraform/configuration.go | 128 ++- pkg/component/terraform/configuration_plan.go | 173 ++- .../configuration_plan_pipeline_test.go | 236 ++++- .../terraform/configuration_plan_test.go | 47 + .../terraform/configuration_restore.go | 233 ++++ .../terraform/configuration_toolchain_test.go | 111 ++ pkg/component/terraform/execute.go | 6 + pkg/component/terraform/execute_pipeline.go | 22 +- pkg/component/terraform/execute_terragrunt.go | 105 ++ .../terraform/plan_diff_preparation.go | 12 +- pkg/component/terraform/shell.go | 6 + pkg/component/terraform/verify_plan.go | 7 +- .../terragruntexec/mock_host_test.go | 70 ++ .../terragruntexec/terragruntexec.go | 299 ++++++ .../terragruntexec/terragruntexec_test.go | 279 +++++ pkg/config/config.go | 1 + pkg/flags/standard_parser.go | 21 + pkg/flags/standard_parser_tristate_test.go | 39 + pkg/plugin/adapter/component/diagnostics.go | 6 + .../adapter/component/diagnostics_test.go | 120 +++ pkg/plugin/adapter/component/logs.go | 119 +++ pkg/plugin/adapter/component/objects.go | 72 ++ pkg/plugin/adapter/component/objects_test.go | 63 ++ pkg/plugin/adapter/configuration/discovery.go | 4 +- pkg/plugin/adapter/configuration/imports.go | 1 + .../adapter/configuration/imports_test.go | 2 +- .../adapter/configuration/preparation.go | 20 +- .../adapter/configuration/preparation_test.go | 223 ++++ pkg/plugin/adapter/configuration/session.go | 8 +- .../adapter/configuration/session_test.go | 2 +- pkg/plugin/adapter/configuration/settings.go | 51 +- pkg/plugin/adapter/configuration/state.go | 1 + pkg/plugin/bootstrap/components.go | 157 +++ pkg/plugin/bootstrap/components_test.go | 90 ++ pkg/plugin/extension/component.go | 37 +- pkg/plugin/extension/component_test.go | 40 + pkg/plugin/oci/inspect.go | 11 +- pkg/plugin/oci/metadata_test.go | 135 +++ pkg/plugin/oci/pack.go | 116 +- pkg/plugin/proto/atmos/plugin/v1/plugin.pb.go | 995 +++++++++++------- pkg/schema/component_configuration.go | 8 + pkg/schema/schema.go | 15 +- plugins/README.md | 6 +- plugins/terragrunt/README.md | 13 +- plugins/terragrunt/bridge/aws.go | 345 ++++++ plugins/terragrunt/bridge/aws_test.go | 320 ++++++ plugins/terragrunt/bridge/go.mod | 10 +- plugins/terragrunt/fixtures/toolprobe/main.go | 78 +- plugins/terragrunt/go.mod | 4 +- plugins/terragrunt/internal/engine/logs.go | 167 +++ .../terragrunt/internal/engine/logs_test.go | 142 +++ plugins/terragrunt/internal/engine/resolve.go | 17 +- .../internal/engine/resolve_test.go | 131 +++ .../terragrunt/internal/engine/sensitivity.go | 207 ++++ plugins/terragrunt/internal/model/model.go | 31 +- .../terragrunt/internal/provider/discovery.go | 31 +- plugins/terragrunt/internal/provider/logs.go | 66 ++ .../internal/provider/preparation.go | 30 +- .../terragrunt/internal/provider/provider.go | 96 +- .../internal/provider/provider_test.go | 249 +++++ plugins/terragrunt/plugin.tests.yaml | 96 ++ plugins/terragrunt/plugin.yaml | 37 + plugins/terragrunt/schemas/config.json | 6 +- plugins/terragrunt/scripts/modes.star | 438 ++++++++ plugins/terragrunt/scripts/pro.star | 152 +++ plugins/terragrunt/scripts/release.star | 25 + .../terragrunt/scripts/values_logging.star | 224 ++++ proto/atmos/plugin/v1/plugin.proto | 81 +- sdk/component/failure.go | 9 + sdk/component/failure_test.go | 18 + sdk/proto/atmos/plugin/v1/plugin.pb.go | 995 +++++++++++------- tests/terragrunt_pro_test.go | 429 ++++++++ ...-10-29-native-terragrunt-compatibility.mdx | 16 +- website/docs/cli/commands/plugin/pack.mdx | 7 + website/docs/cli/commands/plugin/publish.mdx | 3 +- website/docs/cli/commands/plugin/release.mdx | 2 + website/docs/migration/terragrunt.mdx | 24 +- 105 files changed, 9086 insertions(+), 967 deletions(-) create mode 100644 pkg/component/provideroptions/flags.go create mode 100644 pkg/component/provideroptions/options.go create mode 100644 pkg/component/provideroptions/provideroptions_test.go create mode 100644 pkg/component/terraform/configuration_restore.go create mode 100644 pkg/component/terraform/execute_terragrunt.go create mode 100644 pkg/component/terragruntexec/mock_host_test.go create mode 100644 pkg/component/terragruntexec/terragruntexec.go create mode 100644 pkg/component/terragruntexec/terragruntexec_test.go create mode 100644 pkg/plugin/adapter/component/logs.go create mode 100644 plugins/terragrunt/bridge/aws.go create mode 100644 plugins/terragrunt/bridge/aws_test.go create mode 100644 plugins/terragrunt/internal/engine/logs.go create mode 100644 plugins/terragrunt/internal/engine/logs_test.go create mode 100644 plugins/terragrunt/internal/engine/sensitivity.go create mode 100644 plugins/terragrunt/internal/provider/logs.go create mode 100644 plugins/terragrunt/scripts/modes.star create mode 100644 plugins/terragrunt/scripts/pro.star create mode 100644 plugins/terragrunt/scripts/values_logging.star create mode 100644 tests/terragrunt_pro_test.go diff --git a/.golangci.yml b/.golangci.yml index a820f830cd8..9dd846e806a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -108,6 +108,11 @@ linters: # Only this cloud-specific leaf imports the SDK; the parent downloader stays generic. - "!**/pkg/downloader/s3/**" - "!**/pkg/github/**" + # The Terragrunt plugin bridge resolves the AWS identity of an invocation for Terragrunt's own + # AWS calls (get_aws_account_id, S3 dependency state). It is an AWS-specific leaf of a separate + # module that cannot import the Atmos auth packages. + - "!**/plugins/terragrunt/bridge/aws.go" + - "!**/plugins/terragrunt/bridge/aws_test.go" # The S3 deployment Mage target is an AWS-specific build tool and # intentionally uses the AWS SDK instead of shelling out to a CLI. - "!**/magefiles/s3/**" diff --git a/cmd/help_template.go b/cmd/help_template.go index 8e220fafc8c..8e88241f0ca 100644 --- a/cmd/help_template.go +++ b/cmd/help_template.go @@ -10,10 +10,12 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/muesli/reflow/wordwrap" "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/cloudposse/atmos/cmd/internal" tuiUtils "github.com/cloudposse/atmos/internal/tui/utils" atmosansi "github.com/cloudposse/atmos/pkg/ansi" + "github.com/cloudposse/atmos/pkg/component/provideroptions" cfg "github.com/cloudposse/atmos/pkg/config" "github.com/cloudposse/atmos/pkg/flags/compat" log "github.com/cloudposse/atmos/pkg/logger" @@ -495,10 +497,7 @@ func printFlags(w io.Writer, cmd *cobra.Command, atmosConfig *schema.AtmosConfig termWidth := getTerminalWidth() if cmd.HasAvailableLocalFlags() { - fmt.Fprintln(w, styles.heading.Render("FLAGS")) - fmt.Fprintln(w) - renderFlags(w, cmd.LocalFlags(), styles.commandName, styles.flagName, styles.flagDesc, termWidth, atmosConfig) - fmt.Fprintln(w) + renderLocalFlagSections(w, cmd.LocalFlags(), styles, termWidth, atmosConfig) } if cmd.HasAvailableInheritedFlags() { @@ -686,3 +685,19 @@ func printFooter(w io.Writer, cmd *cobra.Command, styles *helpStyles) { usageMsg = renderMarkdownDescription(usageMsg) fmt.Fprintf(w, "\n%s\n", styles.muted.Render(usageMsg)) } + +// renderLocalFlagSections prints the FLAGS section, followed by one section for each configuration +// provider whose declared options the command accepts. +func renderLocalFlagSections(w io.Writer, local *pflag.FlagSet, styles *helpStyles, termWidth int, atmosConfig *schema.AtmosConfiguration) { + rest, providerSections := provideroptions.SplitFlags(local) + fmt.Fprintln(w, styles.heading.Render("FLAGS")) + fmt.Fprintln(w) + renderFlags(w, rest, styles.commandName, styles.flagName, styles.flagDesc, termWidth, atmosConfig) + fmt.Fprintln(w) + for _, section := range providerSections { + fmt.Fprintln(w, styles.heading.Render(section.Title)) + fmt.Fprintln(w) + renderFlags(w, section.Flags, styles.commandName, styles.flagName, styles.flagDesc, termWidth, atmosConfig) + fmt.Fprintln(w) + } +} diff --git a/cmd/help_template_test.go b/cmd/help_template_test.go index 928ca54e058..51322cd661e 100644 --- a/cmd/help_template_test.go +++ b/cmd/help_template_test.go @@ -9,7 +9,9 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/spf13/cobra" + terraformcmd "github.com/cloudposse/atmos/cmd/terraform" "github.com/cloudposse/atmos/pkg/ansi" + "github.com/cloudposse/atmos/pkg/component/provideroptions" "github.com/cloudposse/atmos/pkg/flags/compat" "github.com/cloudposse/atmos/pkg/schema" "github.com/cloudposse/atmos/pkg/ui/markdown" @@ -1422,3 +1424,53 @@ func TestGetExperimentalBadge(t *testing.T) { }) } } + +func TestPrintFlagsGroupsProviderFlagsUnderTheirProvider(t *testing.T) { + root := &cobra.Command{Use: "terraform"} + plan := &cobra.Command{Use: "plan", Run: func(*cobra.Command, []string) {}} + plan.Flags().Bool("affected", false, "Plan the affected components") + root.AddCommand(plan) + options, err := provideroptions.Parse("tool", []any{ + map[string]any{"name": "level", "type": "string", "description": "Provider log level.", "commands": []any{"plan"}}, + }) + if err != nil { + t.Fatal(err) + } + if err := provideroptions.Register(root, []provideroptions.Provider{{Section: "tool", Name: "tool", Mode: provideroptions.ModeNative, Options: options}}); err != nil { + t.Fatal(err) + } + + var buf bytes.Buffer + styles := createHelpStyles(lipgloss.NewRenderer(&buf)) + printFlags(&buf, plan, &schema.AtmosConfiguration{}, &styles) + output := buf.String() + + flags, providerFlags, found := strings.Cut(output, "TOOL FLAGS") + if !found { + t.Fatalf("provider section missing: %q", output) + } + if !strings.Contains(flags, "--affected") || strings.Contains(flags, "--tool-level") { + t.Errorf("Atmos flags and provider flags are not separated: %q", flags) + } + if !strings.Contains(providerFlags, "--tool-level") || !strings.Contains(providerFlags, "Provider log level.") { + t.Errorf("provider section lacks its flag: %q", providerFlags) + } +} + +func TestRegisterProviderFlagsWithoutEnabledProvidersChangesNothing(t *testing.T) { + before := plan().Flags().NFlag() + for _, args := range [][]string{{"terraform", "plan"}, {"version"}, nil} { + if err := terraformcmd.RegisterProviderFlags(&schema.AtmosConfiguration{}, args); err != nil { + t.Errorf("args %v: %v", args, err) + } + } + if plan().Flags().NFlag() != before { + t.Error("registration without a provider changed the flags") + } +} + +// plan finds the terraform plan command in the real command tree. +func plan() *cobra.Command { + command, _, _ := RootCmd.Find([]string{"terraform", "plan"}) + return command +} diff --git a/cmd/help_topics_render.go b/cmd/help_topics_render.go index 562fc08ef46..3884108c53b 100644 --- a/cmd/help_topics_render.go +++ b/cmd/help_topics_render.go @@ -21,10 +21,7 @@ func printLocalFlagsOnly(w io.Writer, cmd *cobra.Command, atmosConfig *schema.At return } - fmt.Fprintln(w, styles.heading.Render("FLAGS")) - fmt.Fprintln(w) - renderFlags(w, localFlags, styles.commandName, styles.flagName, styles.flagDesc, getTerminalWidth(), atmosConfig) - fmt.Fprintln(w) + renderLocalFlagSections(w, localFlags, styles, getTerminalWidth(), atmosConfig) } func commandSpecificFlagSet(cmd *cobra.Command) *pflag.FlagSet { diff --git a/cmd/plugin/author.go b/cmd/plugin/author.go index 87e5d2c315b..f53b24bf439 100644 --- a/cmd/plugin/author.go +++ b/cmd/plugin/author.go @@ -46,7 +46,7 @@ func validateCommand() *cobra.Command { } func packCommand() *cobra.Command { - parser := newOutputParser(flags.WithStringFlag(packOutputFlag, "o", "", "Destination OCI layout directory")) + parser := newOutputParser(append(sourceFlags(), flags.WithStringFlag(packOutputFlag, "o", "", "Destination OCI layout directory"))...) command := &cobra.Command{Use: "pack [directory] --output ", Short: "Pack precompiled plugins into a multi-platform OCI layout", Args: cobra.MaximumNArgs(1)} registerOutputFlags(command, parser) _ = command.MarkFlagRequired(packOutputFlag) @@ -68,7 +68,11 @@ func packCommand() *cobra.Command { return err } output := values.GetString(packOutputFlag) - if err := pluginoci.Pack(directory, output, registry, pluginoci.WithExecutableFormatCheck()); err != nil { + opts, err := packOptions(values) + if err != nil { + return err + } + if err := pluginoci.Pack(directory, output, registry, opts...); err != nil { return err } files, err := pluginoci.LayoutFiles(output) diff --git a/cmd/plugin/publish_safety_test.go b/cmd/plugin/publish_safety_test.go index f3476dab906..96b321552eb 100644 --- a/cmd/plugin/publish_safety_test.go +++ b/cmd/plugin/publish_safety_test.go @@ -121,3 +121,34 @@ func TestDeleteReleaseConfirmation(t *testing.T) { require.ErrorIs(t, deleteRelease(t.Context(), client, reference, true, deletePrompts{interactive: neverInteractive, confirm: noConfirm}), denied) }) } + +func TestPackOptionsSourceIsOptInAndNeverImplicit(t *testing.T) { + t.Setenv("GITHUB_REPOSITORY", "") + t.Setenv("GITHUB_SERVER_URL", "") + values := func(source string) *viper.Viper { + result := viper.New() + result.Set(sourceFlag, source) + return result + } + + opts, err := packOptions(values("")) + require.NoError(t, err) + require.Len(t, opts, 1, "without --source only the executable format check applies") + + opts, err = packOptions(values("https://github.com/example/repo")) + require.NoError(t, err) + require.Len(t, opts, 2) + + _, err = packOptions(values(sourceGitHubActions)) + require.ErrorIs(t, err, errUtils.ErrPluginInvalidConfig, "github-actions must fail loudly outside GitHub Actions") + + t.Setenv("GITHUB_REPOSITORY", "example/repo") + opts, err = packOptions(values(sourceGitHubActions)) + require.NoError(t, err) + require.Len(t, opts, 2) + + t.Setenv("GITHUB_REPOSITORY", "example/repo") + opts, err = packOptions(values("")) + require.NoError(t, err) + require.Len(t, opts, 1, "the CI environment alone never links a package") +} diff --git a/cmd/plugin/release.go b/cmd/plugin/release.go index 9502322014d..e74e56e050d 100644 --- a/cmd/plugin/release.go +++ b/cmd/plugin/release.go @@ -3,6 +3,8 @@ package plugin import ( "context" "fmt" + "os" + "slices" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -23,7 +25,7 @@ import ( ) func releaseCommand() *cobra.Command { - parser := newOutputParser(append(publicationFlags(), inventoryReleaseFlags()...)...) + parser := newOutputParser(slices.Concat(publicationFlags(), inventoryReleaseFlags(), sourceFlags())...) command := &cobra.Command{ Use: "release [directory] [--to | --inventory ]", Short: "Build all targets, test the host target, and publish a plugin release", @@ -122,7 +124,46 @@ func (backend *releaseBackend) Test(ctx context.Context, directory string) error } func (backend *releaseBackend) Pack(_ context.Context, directory, layout string) error { - return pluginoci.Pack(directory, layout, backend.manager.Installer.Descriptors, pluginoci.WithExecutableFormatCheck()) + opts, err := packOptions(backend.values) + if err != nil { + return err + } + return pluginoci.Pack(directory, layout, backend.manager.Installer.Descriptors, opts...) +} + +const ( + // The source flag selects the repository recorded as the package source. + sourceFlag = "source" + // The github-actions value asks packing to derive the repository link from the GitHub Actions environment. + sourceGitHubActions = "github-actions" +) + +// sourceFlags declares the opt-in repository link recorded as org.opencontainers.image.source. +func sourceFlags() []flags.Option { + return []flags.Option{ + flags.WithStringFlag(sourceFlag, "", "", "Repository URL recorded as the package source so registries such as GHCR link the package to it (https URL, or "+sourceGitHubActions+" to derive it from GITHUB_REPOSITORY); defaults to metadata.repository in plugin.yaml"), + flags.WithEnvVars(sourceFlag, "ATMOS_PLUGIN_SOURCE"), + } +} + +// packOptions translates the shared pack flags into packing options. Nothing is +// derived from the environment unless --source asks for it. +func packOptions(values *viper.Viper) ([]pluginoci.Option, error) { + opts := []pluginoci.Option{pluginoci.WithExecutableFormatCheck()} + switch source := values.GetString(sourceFlag); source { + case "": + case sourceGitHubActions: + derived := pluginoci.GitHubActionsSource(os.Getenv) //nolint:forbidigo // GITHUB_* is the runner's own context, not Atmos configuration, and is read only when --source asks for it. + if derived == "" { + return nil, errUtils.Build(fmt.Errorf("%w: --%s=%s requires GITHUB_REPOSITORY (and optionally an https GITHUB_SERVER_URL)", errUtils.ErrPluginInvalidConfig, sourceFlag, sourceGitHubActions)). + WithHintf("Run inside GitHub Actions, or pass the repository explicitly with `--%s https://github.com//`.", sourceFlag). + Err() + } + opts = append(opts, pluginoci.WithSource(derived)) + default: + opts = append(opts, pluginoci.WithSource(source)) + } + return opts, nil } func (backend *releaseBackend) Publish(ctx context.Context, layout string) (*pluginoci.Release, error) { diff --git a/cmd/root.go b/cmd/root.go index 100f197e9b3..953d612230b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -59,7 +59,7 @@ import ( _ "github.com/cloudposse/atmos/cmd/secret" stackcmd "github.com/cloudposse/atmos/cmd/stack" _ "github.com/cloudposse/atmos/cmd/store" - _ "github.com/cloudposse/atmos/cmd/terraform" + terraformcmd "github.com/cloudposse/atmos/cmd/terraform" "github.com/cloudposse/atmos/cmd/terraform/backend" terraformcache "github.com/cloudposse/atmos/cmd/terraform/cache" "github.com/cloudposse/atmos/cmd/terraform/workdir" @@ -1903,6 +1903,11 @@ func Execute() error { if err != nil { return err } + + // Provider options come from static package metadata and must exist before Cobra parses flags. + if err = terraformcmd.RegisterProviderFlags(&atmosConfig, os.Args[1:]); err != nil { + return err + } } // Custom commands and configured aliases can now use inherited discovery metadata. diff --git a/cmd/terraform/planfile/download.go b/cmd/terraform/planfile/download.go index 5209afe7c1e..a6e466bcaeb 100644 --- a/cmd/terraform/planfile/download.go +++ b/cmd/terraform/planfile/download.go @@ -179,8 +179,7 @@ func resolveDownloadPlanfilePath(cmd *cobra.Command, opts *DownloadOptions, atmo return "", fmt.Errorf("%w: failed to resolve component path: %w", errUtils.ErrPlanfileDownloadFailed, err) } - planfilePath := exec.ConstructTerraformComponentPlanfilePath(atmosConfig, &info) - return planfilePath, nil + return canonicalPlanfilePath(atmosConfig, &info) } // printDownloadSuccess prints the success message for a download. diff --git a/cmd/terraform/planfile/resolve.go b/cmd/terraform/planfile/resolve.go index b6ecd634f9e..bc1e5223f48 100644 --- a/cmd/terraform/planfile/resolve.go +++ b/cmd/terraform/planfile/resolve.go @@ -5,12 +5,33 @@ import ( "os" errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/internal/exec" "github.com/cloudposse/atmos/pkg/ci/plugins/terraform/planfile" + "github.com/cloudposse/atmos/pkg/component" + cfg "github.com/cloudposse/atmos/pkg/config" "github.com/cloudposse/atmos/pkg/git" log "github.com/cloudposse/atmos/pkg/logger" "github.com/cloudposse/atmos/pkg/perf" + provWorkdir "github.com/cloudposse/atmos/pkg/provisioner/workdir" + "github.com/cloudposse/atmos/pkg/schema" ) +// canonicalPlanfilePath returns where `atmos terraform plan` keeps a component's plan file. A +// workdir-enabled component (every Terragrunt unit) keeps it in its workdir, which is derived from +// the configuration here because nothing has been provisioned in a new process or on a fresh runner. +func canonicalPlanfilePath(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (string, error) { + defer perf.Track(atmosConfig, "planfile.canonicalPlanfilePath")() + + if provWorkdir.IsWorkdirEnabled(info.ComponentSection) { + workdir, _, err := component.BuildAndResolveWorkdirPath(atmosConfig, info, cfg.TerraformComponentType) + if err != nil { + return "", err + } + info.ComponentSection[provWorkdir.WorkdirPathKey] = workdir + } + return exec.ConstructTerraformComponentPlanfilePath(atmosConfig, info), nil +} + // resolvedContext holds SHA and branch resolved from environment or git. type resolvedContext struct { SHA string diff --git a/cmd/terraform/planfile/resolve_test.go b/cmd/terraform/planfile/resolve_test.go index 505546e0e1f..4c82a84ffb9 100644 --- a/cmd/terraform/planfile/resolve_test.go +++ b/cmd/terraform/planfile/resolve_test.go @@ -2,12 +2,15 @@ package planfile import ( "errors" + "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/schema" ) func TestResolveContext(t *testing.T) { @@ -149,3 +152,29 @@ func TestGetFirstEnvValue(t *testing.T) { assert.Empty(t, result) }) } + +func TestCanonicalPlanfilePathFollowsTheComponentWorkdir(t *testing.T) { + base := t.TempDir() + config := &schema.AtmosConfiguration{BasePath: base, TerraformDirAbsolutePath: filepath.Join(base, "components", "terraform")} + config.Components.Terraform.BasePath = filepath.Join("components", "terraform") + + t.Run("workdir component keeps its plan in the workdir, which need not exist yet", func(t *testing.T) { + info := &schema.ConfigAndStacksInfo{ + Stack: "live/dev", ComponentFromArg: "app", FinalComponent: "app", + ComponentSettingsSection: map[string]any{"configuration": true}, + ComponentSection: map[string]any{"provision": map[string]any{"workdir": map[string]any{"enabled": true}}}, + } + path, err := canonicalPlanfilePath(config, info) + require.NoError(t, err) + assert.Contains(t, filepath.ToSlash(path), ".workdir/terraform/live/dev-app-") + assert.True(t, strings.HasSuffix(path, ".planfile"), path) + assert.NoDirExists(t, filepath.Dir(path), "resolving the path must not provision anything") + }) + + t.Run("ordinary component keeps its plan beside its sources", func(t *testing.T) { + info := &schema.ConfigAndStacksInfo{Stack: "dev", ComponentFromArg: "vpc", FinalComponent: "vpc", ComponentSection: map[string]any{}} + path, err := canonicalPlanfilePath(config, info) + require.NoError(t, err) + assert.Equal(t, filepath.Join(base, "components", "terraform", "vpc"), filepath.Dir(path)) + }) +} diff --git a/cmd/terraform/planfile/upload.go b/cmd/terraform/planfile/upload.go index 4b1a4d36ccd..a169a96b6fa 100644 --- a/cmd/terraform/planfile/upload.go +++ b/cmd/terraform/planfile/upload.go @@ -156,6 +156,12 @@ func runUpload(cmd *cobra.Command, args []string) error { } } + // Include the plan record when the component keeps one, so another runner can verify and apply the plan. + if entry, closer, found := planfile.OpenBinding(planfilePath); found { + defer closer.Close() + files = append(files, entry) + } + // Resolve SHA: explicit flag > context resolution. sha := opts.SHA if sha == "" { @@ -264,8 +270,7 @@ func resolveUploadPlanfilePath(opts *UploadOptions, atmosConfig *schema.AtmosCon return "", fmt.Errorf("%w: failed to resolve component path: %w", errUtils.ErrPlanfileUploadFailed, err) } - planfilePath := exec.ConstructTerraformComponentPlanfilePath(atmosConfig, &info) - return planfilePath, nil + return canonicalPlanfilePath(atmosConfig, &info) } // resolveLockfilePath returns the lock file path from the explicit flag or auto-detected diff --git a/cmd/terraform/terraform.go b/cmd/terraform/terraform.go index 3092a51474e..0e957a4d165 100644 --- a/cmd/terraform/terraform.go +++ b/cmd/terraform/terraform.go @@ -1,6 +1,7 @@ package terraform import ( + "context" "strings" "github.com/spf13/cobra" @@ -19,6 +20,9 @@ import ( cfg "github.com/cloudposse/atmos/pkg/config" "github.com/cloudposse/atmos/pkg/flags" "github.com/cloudposse/atmos/pkg/flags/compat" + log "github.com/cloudposse/atmos/pkg/logger" + "github.com/cloudposse/atmos/pkg/perf" + pluginbootstrap "github.com/cloudposse/atmos/pkg/plugin/bootstrap" "github.com/cloudposse/atmos/pkg/schema" ) @@ -106,6 +110,32 @@ func init() { ) } +// RegisterProviderFlags adds the options that enabled configuration providers declare in their +// package metadata to the terraform subcommands they apply to. It reads static metadata only, so no +// plugin starts, and it runs before Cobra parses the command line. +func RegisterProviderFlags(config *schema.AtmosConfiguration, args []string) error { + defer perf.Track(config, "terraform.RegisterProviderFlags")() + + err := pluginbootstrap.RegisterComponentFlags(context.Background(), config, terraformCmd) + if err != nil && !targetsTerraform(args) { + // A package that declares a bad option must not break commands that never run a unit. + log.Debug("Provider flag registration failed", "error", err) + return nil + } + return err +} + +// targetsTerraform reports whether the command line selects `atmos terraform` or one of its subcommands. +func targetsTerraform(args []string) bool { + target, _, _ := terraformCmd.Root().Find(args) + for command := target; command != nil; command = command.Parent() { + if command == terraformCmd { + return true + } + } + return false +} + // TerraformCommandProvider implements the CommandProvider interface. type TerraformCommandProvider struct{} diff --git a/cmd/terraform/utils.go b/cmd/terraform/utils.go index 8a3b315f366..c073a3b15b6 100644 --- a/cmd/terraform/utils.go +++ b/cmd/terraform/utils.go @@ -31,6 +31,7 @@ import ( citerraform "github.com/cloudposse/atmos/pkg/ci/plugins/terraform" "github.com/cloudposse/atmos/pkg/ci/plugins/terraform/planfile" "github.com/cloudposse/atmos/pkg/component" + "github.com/cloudposse/atmos/pkg/component/provideroptions" cfg "github.com/cloudposse/atmos/pkg/config" "github.com/cloudposse/atmos/pkg/flags" "github.com/cloudposse/atmos/pkg/flags/compat" @@ -42,6 +43,7 @@ import ( "github.com/cloudposse/atmos/pkg/policy/admission" "github.com/cloudposse/atmos/pkg/proexec" "github.com/cloudposse/atmos/pkg/provisioner" + provWorkdir "github.com/cloudposse/atmos/pkg/provisioner/workdir" "github.com/cloudposse/atmos/pkg/schema" "github.com/cloudposse/atmos/pkg/store/authbridge" u "github.com/cloudposse/atmos/pkg/utils" @@ -1833,6 +1835,10 @@ func terraformRunWithOptions(parentCmd, actualCmd *cobra.Command, args []string, // Apply parsed options to info BEFORE prompting, so hasMultiComponentFlags() works correctly. // This fixes issue #1945: --all flag must be set before resolveAndPromptForArgs checks it. applyOptionsToInfo(&info, opts) + // Provider options are validated here, before any discovery or preparation can start a plugin. + if info.ComponentProviderOptions, err = provideroptions.Resolve(actualCmd, viper.GetViper()); err != nil { + return err + } applyFromPlanSelection(&info, actualCmd) // Honor a component already chosen interactively in PreRunE (runBeforeHooks) so the @@ -2009,6 +2015,9 @@ func verifyStoredPlanForDeploy(subCommand string, info *schema.ConfigAndStacksIn } canonicalPlanPath := e.ConstructTerraformComponentPlanfilePath(&verifyAtmosConfig, info) + if workdirPath, ok := retainedWorkdirPlanfilePath(&verifyAtmosConfig, info); ok { + canonicalPlanPath = workdirPath + } storedPlanPath := filepath.Join(filepath.Dir(canonicalPlanPath), planfile.StoredPlanPrefix+planfile.PlanFilename) if _, statErr := os.Stat(storedPlanPath); statErr != nil { // No stored planfile was downloaded. Whether that blocks the deploy is @@ -2027,6 +2036,21 @@ func verifyStoredPlanForDeploy(subCommand string, info *schema.ConfigAndStacksIn return verifyPlanfile(info, storedPlanPath, mode) } +// retainedWorkdirPlanfilePath returns the plan file path inside the workdir of a workdir-enabled +// component (every Terragrunt unit), where `plan` keeps its plan and the CI hooks store the +// downloaded one. It derives the directory from configuration, so it works before anything is +// provisioned on a fresh runner. It reports false for components without a workdir. +func retainedWorkdirPlanfilePath(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (string, bool) { + if !provWorkdir.IsWorkdirEnabled(info.ComponentSection) { + return "", false + } + workdir, _, err := component.BuildAndResolveWorkdirPath(atmosConfig, info, cfg.TerraformComponentType) + if err != nil { + return "", false + } + return filepath.Join(workdir, filepath.Base(e.ConstructTerraformComponentPlanfilePath(atmosConfig, info))), true +} + // handleUnconfiguredPlanfileStorage resolves a verification request that cannot be // honored because no planfile storage is configured. An explicit --verify-plan / // ATMOS_TERRAFORM_VERIFY_PLAN=true errors: verification depends on storage settings diff --git a/cmd/terraform/utils_test.go b/cmd/terraform/utils_test.go index 6300d9b85d9..a229098482a 100644 --- a/cmd/terraform/utils_test.go +++ b/cmd/terraform/utils_test.go @@ -3,6 +3,7 @@ package terraform import ( "bytes" "errors" + "path/filepath" "strings" "testing" @@ -1325,3 +1326,24 @@ func normalizeUIOutput(s string) string { } return strings.Join(strings.Fields(b.String()), " ") } + +func TestRetainedWorkdirPlanfilePathLocatesTheWorkdirOfAFreshRunner(t *testing.T) { + base := t.TempDir() + config := &schema.AtmosConfiguration{BasePath: base, TerraformDirAbsolutePath: filepath.Join(base, "components", "terraform")} + config.Components.Terraform.BasePath = filepath.Join("components", "terraform") + + unit := &schema.ConfigAndStacksInfo{ + Stack: "live/dev", ComponentFromArg: "app", FinalComponent: "app", + ComponentSettingsSection: map[string]any{"configuration": true}, + ComponentSection: map[string]any{"provision": map[string]any{"workdir": map[string]any{"enabled": true}}}, + } + path, ok := retainedWorkdirPlanfilePath(config, unit) + require.True(t, ok) + require.Contains(t, filepath.ToSlash(path), ".workdir/terraform/live/dev-app-") + require.NotContains(t, path, filepath.Join("components", "terraform")) + require.NoDirExists(t, filepath.Dir(path), "locating the workdir must not provision it") + + ordinary := &schema.ConfigAndStacksInfo{Stack: "dev", ComponentFromArg: "vpc", FinalComponent: "vpc", ComponentSection: map[string]any{}} + _, ok = retainedWorkdirPlanfilePath(config, ordinary) + require.False(t, ok, "components without a workdir keep the canonical path") +} diff --git a/errors/plugin.go b/errors/plugin.go index 2c3f03cc121..faeb24278dc 100644 --- a/errors/plugin.go +++ b/errors/plugin.go @@ -97,6 +97,16 @@ var ( ErrComponentRunIgnored = errors.New("component run ended by an ignored error") // ErrComponentExcluded ends a component run successfully because the provider excluded the operation. ErrComponentExcluded = errors.New("component excluded from this operation") + // ErrProviderOption identifies a configuration provider option that is declared or supplied incorrectly. + ErrProviderOption = errors.New("invalid configuration provider option") + // ErrProviderOptionCollision identifies a provider option whose flag name an Atmos or another provider flag already uses. + ErrProviderOptionCollision = errors.New("configuration provider option collides with an existing flag") + // ErrExecutableModeUnsupported identifies a command or stack override that executable mode cannot honor. + ErrExecutableModeUnsupported = errors.New("not supported in executable mode") + // ErrExecutableNotFound identifies a missing or unusable terragrunt executable in executable mode. + ErrExecutableNotFound = errors.New("terragrunt executable not found") + // ErrExecutableVersion identifies a terragrunt executable that is older than the supported minimum. + ErrExecutableVersion = errors.New("terragrunt version is not supported") ErrInvalidCredentialCodec = errors.New("invalid credential codec") ErrDuplicateCredentialCodec = errors.New("duplicate credential codec") diff --git a/examples/terragrunt-native/README.md b/examples/terragrunt-native/README.md index 754f4d92e62..8b63a9953c7 100644 --- a/examples/terragrunt-native/README.md +++ b/examples/terragrunt-native/README.md @@ -18,36 +18,42 @@ run the Terragrunt executable. The module uses the built-in `terraform_data` resource and local state. No cloud credentials or provider downloads are needed. -## Build the development package +## Install the plugin -This example requires the experimental Atmos branch and its local Terragrunt -plugin. See [plugin usage](https://atmos.tools/cli/commands/plugin/usage) for package configuration. The plugin is not yet published. Install Go and OpenTofu, then run these -commands from the root of the Atmos checkout containing this example: +The Terragrunt configuration provider is a plugin package that Atmos installs from the registry. +`atmos.yaml` declares it with a source and a version constraint: -```shell -go build -o build/atmos . -export PATH="$PWD/build:$PATH" -atmos plugin build plugins/terragrunt -export ATMOS_TERRAGRUNT_PLUGIN_PATH="$PWD/plugins/terragrunt" +```yaml +plugins: + packages: + terragrunt: + source: oci://ghcr.io/cloudposse/atmos/plugins/terragrunt + version: "^0.1.0" ``` -Copy the example into a new directory and select its `dev` profile, which points the -plugin package at your build: +Install Atmos and OpenTofu, copy the example into a new directory, and install the plugin: ```shell atmos init ./examples/terragrunt-native ./terragrunt-native \ --copy --no-git cd terragrunt-native -export ATMOS_PROFILE=dev +atmos plugin install ``` -The example already enables native discovery, and `profiles/dev/atmos.yaml` reads the -plugin path from `ATMOS_TERRAGRUNT_PLUGIN_PATH`. To enable the same behavior in an -existing project, run these commands from that project's root: +`atmos plugin install` downloads the release, verifies its digest, and writes it to +`.atmos.plugins.lock.yaml`. Commit that file: the lock pins the exact release, so every machine +and CI run restores the same bytes, and CI refuses to create a new lock entry on its own. +Without this step the first command that needs the plugin installs it and creates the lock entry; +`atmos plugin install --frozen` restores exactly what the lock records and never changes it. +If the package cannot be fetched (for example because the registry is unreachable or the release is +not yet published), Atmos reports which source and version constraint it could not prepare and +changes nothing. + +To enable the same behavior in an existing project, run these commands from that project's root: ```shell -atmos config set plugins.packages.terragrunt.path \ - "$ATMOS_TERRAGRUNT_PLUGIN_PATH" +atmos plugin install oci://ghcr.io/cloudposse/atmos/plugins/terragrunt \ + --as=terragrunt atmos config set components.terraform.base_path \ components/terraform atmos config set components.terraform.command tofu @@ -60,14 +66,30 @@ atmos config set \ components.terraform.terragrunt.discovery.enabled true ``` -In an existing project the plugin path is stored in `atmos.yaml`, so Atmos does not -need the environment variable on subsequent runs. Adjust `included_paths` to match your Terragrunt directory layout; +Adjust `included_paths` to match your Terragrunt directory layout; see [discovery paths](https://atmos.tools/migration/terragrunt#discovery-paths) for the pattern rules. `components.terraform.base_path` is required by Atmos even though Terragrunt units do not live there; the directory does not need to exist. If you use Terraform instead, set `components.terraform.command` to `terraform` and install Terraform 1.4 or newer. +## Develop against a local build + +Only plugin developers need this. The `dev` profile replaces the registry package with a local +build, which is never fetched, locked, or signature-checked. From the root of the Atmos checkout +containing this example: + +```shell +go build -o build/atmos . +export PATH="$PWD/build:$PATH" +atmos plugin build plugins/terragrunt +export ATMOS_TERRAGRUNT_PLUGIN_PATH="$PWD/plugins/terragrunt" +export ATMOS_PROFILE=dev +``` + +Run the commands below from the copied example directory with `ATMOS_PROFILE=dev` set. +`profiles/dev/atmos.yaml` reads the plugin path from `ATMOS_TERRAGRUNT_PLUGIN_PATH`. + ## Discover and plan ```shell diff --git a/examples/terragrunt-native/atmos.yaml b/examples/terragrunt-native/atmos.yaml index cc43645367c..c3248752bdf 100644 --- a/examples/terragrunt-native/atmos.yaml +++ b/examples/terragrunt-native/atmos.yaml @@ -6,10 +6,22 @@ components: base_path: components/terraform command: tofu # Settings for the Terragrunt configuration provider. The provider itself comes from - # plugins.packages.terragrunt; the `dev` profile supplies a local build (see profiles/dev). + # plugins.packages.terragrunt below. terragrunt: enabled: true mode: native discovery: enabled: true included_paths: [live/**] + +# The Terragrunt configuration provider is installed from the registry. The first command that needs it +# creates the lock entry (`.atmos.plugins.lock.yaml`); `atmos plugin install` does the same up front, +# and `atmos plugin install --frozen` restores exactly what the lock records, as CI does. +# +# To run a local build while developing the plugin itself, activate the `dev` profile instead +# (ATMOS_PROFILE=dev, see profiles/dev/atmos.yaml): its `path` takes the place of this registry package. +plugins: + packages: + terragrunt: + source: oci://ghcr.io/cloudposse/atmos/plugins/terragrunt + version: "^0.1.0" diff --git a/examples/terragrunt-native/profiles/dev/atmos.yaml b/examples/terragrunt-native/profiles/dev/atmos.yaml index cb44173e002..53b119121ff 100644 --- a/examples/terragrunt-native/profiles/dev/atmos.yaml +++ b/examples/terragrunt-native/profiles/dev/atmos.yaml @@ -4,8 +4,8 @@ # export ATMOS_PROFILE=dev # # A package with `path` is not fetched, locked, or signature-checked, and Atmos warns once per run. -# Once the plugin is published, declare `source` and `version` under plugins.packages.terragrunt in -# atmos.yaml and drop this profile. +# This profile is for developing the plugin itself. Everyone else uses the registry package declared +# by `source` and `version` in atmos.yaml; a `path` takes precedence over them while this profile is active. plugins: packages: terragrunt: diff --git a/pkg/ci/plugins/terraform/handlers.go b/pkg/ci/plugins/terraform/handlers.go index 65848980cca..4a5a780d883 100644 --- a/pkg/ci/plugins/terraform/handlers.go +++ b/pkg/ci/plugins/terraform/handlers.go @@ -569,6 +569,12 @@ func (p *Plugin) uploadPlanfile(ctx *plugin.HookContext) error { files = append(files, planfile.FileEntry{Name: planfile.LockFilename, Data: lf, Size: -1}) } + // Include the plan record when the component keeps one, so another runner can verify and apply the plan. + if entry, closer, found := planfile.OpenBinding(planfilePath); found { + defer closer.Close() + files = append(files, entry) + } + metadata := p.buildPlanfileMetadata(ctx) if err := metadata.Validate(); err != nil { return errUtils.Build(errUtils.ErrPlanfileUploadFailed).WithCause(err). diff --git a/pkg/ci/plugins/terraform/handlers_test.go b/pkg/ci/plugins/terraform/handlers_test.go index ec733b27f48..88ede8b5db9 100644 --- a/pkg/ci/plugins/terraform/handlers_test.go +++ b/pkg/ci/plugins/terraform/handlers_test.go @@ -12,8 +12,12 @@ import ( "github.com/stretchr/testify/require" errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/ci/artifact" + _ "github.com/cloudposse/atmos/pkg/ci/artifact/local" // Register the local artifact store. "github.com/cloudposse/atmos/pkg/ci/internal/plugin" "github.com/cloudposse/atmos/pkg/ci/internal/provider" + "github.com/cloudposse/atmos/pkg/ci/plugins/terraform/planfile" + "github.com/cloudposse/atmos/pkg/ci/plugins/terraform/planfile/adapter" "github.com/cloudposse/atmos/pkg/ci/templates" cfg "github.com/cloudposse/atmos/pkg/config" provWorkdir "github.com/cloudposse/atmos/pkg/provisioner/workdir" @@ -2584,3 +2588,75 @@ func TestDestroyBinding_WarningsStayInsideCallouts(t *testing.T) { } assert.NotContains(t, summary, "> > Warning:") } + +// TestUploadPlanfile_CarriesThePlanRecordToAnotherRunner uploads a plan with its record through a real +// local planfile store and restores it the way `planfile download` does, so a different runner gets +// both files and can verify and apply the plan. +func TestUploadPlanfile_CarriesThePlanRecordToAnotherRunner(t *testing.T) { + storeDir := filepath.Join(t.TempDir(), "store") + backend, err := artifact.NewStore(artifact.StoreOptions{Type: "local/dir", Options: map[string]any{"path": storeDir}}) + require.NoError(t, err) + store := adapter.NewStore(backend) + + runnerA := t.TempDir() + planPath := filepath.Join(runnerA, "atmos-key.planfile") + require.NoError(t, os.WriteFile(planPath, []byte("plan bytes"), 0o600)) + require.NoError(t, os.WriteFile(planfile.BindingPath(planPath), []byte(`{"Version":3}`), 0o600)) + + ctx := &plugin.HookContext{ + Config: &schema.AtmosConfiguration{CI: schema.CIConfig{Enabled: true}}, + Command: "plan", + CICtx: &provider.Context{SHA: "abc123"}, + Info: &schema.ConfigAndStacksInfo{Stack: "dev", ComponentFromArg: "app", PlanFile: planPath}, + CreatePlanfileStore: func() (any, error) { + return store, nil + }, + } + require.NoError(t, (&Plugin{}).uploadPlanfile(ctx)) + + key, err := (&Plugin{}).getArtifactKey(ctx.Info, ctx.CICtx) + require.NoError(t, err) + results, _, err := store.Download(t.Context(), key) + require.NoError(t, err) + defer func() { + for _, r := range results { + r.Data.Close() + } + }() + runnerB := filepath.Join(t.TempDir(), "atmos-key.planfile") + require.NoError(t, planfile.WritePlanfileResults(results, runnerB)) + + restoredPlan, err := os.ReadFile(runnerB) + require.NoError(t, err) + assert.Equal(t, "plan bytes", string(restoredPlan)) + restoredRecord, err := os.ReadFile(planfile.BindingPath(runnerB)) + require.NoError(t, err) + assert.Equal(t, `{"Version":3}`, string(restoredRecord)) +} + +// A plan without a record (every ordinary component) uploads exactly what it did before. +func TestUploadPlanfile_OrdinaryPlanUploadsNoRecord(t *testing.T) { + backend, err := artifact.NewStore(artifact.StoreOptions{Type: "local/dir", Options: map[string]any{"path": filepath.Join(t.TempDir(), "store")}}) + require.NoError(t, err) + store := adapter.NewStore(backend) + planPath := filepath.Join(t.TempDir(), "plan.tfplan") + require.NoError(t, os.WriteFile(planPath, []byte("plan bytes"), 0o600)) + ctx := &plugin.HookContext{ + Config: &schema.AtmosConfiguration{CI: schema.CIConfig{Enabled: true}}, + Command: "plan", + CICtx: &provider.Context{SHA: "abc123"}, + Info: &schema.ConfigAndStacksInfo{Stack: "dev", ComponentFromArg: "vpc", PlanFile: planPath}, + CreatePlanfileStore: func() (any, error) { return store, nil }, + } + require.NoError(t, (&Plugin{}).uploadPlanfile(ctx)) + key, err := (&Plugin{}).getArtifactKey(ctx.Info, ctx.CICtx) + require.NoError(t, err) + results, _, err := store.Download(t.Context(), key) + require.NoError(t, err) + names := []string{} + for _, r := range results { + names = append(names, r.Name) + r.Data.Close() + } + assert.Equal(t, []string{planfile.PlanFilename}, names) +} diff --git a/pkg/ci/plugins/terraform/planfile/interface.go b/pkg/ci/plugins/terraform/planfile/interface.go index be7db7b442a..65c74ca3ebe 100644 --- a/pkg/ci/plugins/terraform/planfile/interface.go +++ b/pkg/ci/plugins/terraform/planfile/interface.go @@ -27,6 +27,15 @@ const ( // LockFilename is the well-known name for the lock file within a bundle. LockFilename = ".terraform.lock.hcl" + // BindingFilename is the well-known name for the plan record within a bundle. Components + // whose configuration provider owns their saved plans (for example Terragrunt units) keep a + // record beside the plan file that proves what was reviewed; without it another runner cannot + // apply the plan. Components that have no record upload nothing under this name. + BindingFilename = PlanFilename + ".atmos.json" + + // BindingSuffix is the suffix of the record stored beside a plan file on disk. + bindingSuffix = ".atmos.json" + // StoredPlanPrefix is the prefix used for stored planfiles during plan verification. // When --verify-plan is set in CI mode, the downloaded planfile gets this prefix // so terraform can generate a fresh plan at the canonical path for comparison. diff --git a/pkg/ci/plugins/terraform/planfile/write.go b/pkg/ci/plugins/terraform/planfile/write.go index 77e65195a97..bd6add8250c 100644 --- a/pkg/ci/plugins/terraform/planfile/write.go +++ b/pkg/ci/plugins/terraform/planfile/write.go @@ -10,8 +10,28 @@ import ( "github.com/cloudposse/atmos/pkg/perf" ) +// BindingPath returns where the plan record of a plan file is kept on disk. +func BindingPath(planfilePath string) string { + defer perf.Track(nil, "planfile.BindingPath")() + + return planfilePath + bindingSuffix +} + +// OpenBinding opens the plan record beside a plan file for upload. It reports false when there is +// none, which is the normal case for components that do not keep one. The caller closes the returned file. +func OpenBinding(planfilePath string) (FileEntry, io.Closer, bool) { + defer perf.Track(nil, "planfile.OpenBinding")() + + file, err := os.Open(BindingPath(planfilePath)) + if err != nil { + return FileEntry{}, nil, false + } + return FileEntry{Name: BindingFilename, Data: file, Size: -1}, file, true +} + // WritePlanfileResults writes downloaded planfile results to disk. -// It maps PlanFilename to planfilePath and LockFilename to the same directory. +// It maps PlanFilename to planfilePath, BindingFilename to the plan record beside it, and +// LockFilename to the same directory. // Parent directories are created as needed. Unknown filenames are skipped. func WritePlanfileResults(results []FileResult, planfilePath string) error { defer perf.Track(nil, "planfile.WritePlanfileResults")() @@ -23,6 +43,8 @@ func WritePlanfileResults(results []FileResult, planfilePath string) error { switch r.Name { case PlanFilename: destPath = planfilePath + case BindingFilename: + destPath = BindingPath(planfilePath) case LockFilename: destPath = filepath.Join(componentDir, LockFilename) default: diff --git a/pkg/ci/plugins/terraform/planfile/write_test.go b/pkg/ci/plugins/terraform/planfile/write_test.go index a21657de7a4..66cf321350c 100644 --- a/pkg/ci/plugins/terraform/planfile/write_test.go +++ b/pkg/ci/plugins/terraform/planfile/write_test.go @@ -202,3 +202,49 @@ func TestVerificationStopsOnUnreadableLockfile(t *testing.T) { require.NoError(t, err) assert.Equal(t, LockFilename, target, "a stat error must not overwrite the current lockfile") } + +func TestWritePlanfileResultsRestoresThePlanRecordBesideThePlan(t *testing.T) { + tmpDir := t.TempDir() + planPath := filepath.Join(tmpDir, "atmos-key.planfile") + results := []FileResult{ + {Name: PlanFilename, Data: io.NopCloser(strings.NewReader("plan data"))}, + {Name: BindingFilename, Data: io.NopCloser(strings.NewReader(`{"Version":3}`))}, + } + require.NoError(t, WritePlanfileResults(results, planPath)) + + record, err := os.ReadFile(BindingPath(planPath)) + require.NoError(t, err) + assert.JSONEq(t, `{"Version":3}`, string(record)) + assert.Equal(t, planPath+".atmos.json", BindingPath(planPath)) +} + +func TestWritePlanfileResultsForVerificationDoesNotRestoreARecord(t *testing.T) { + tmpDir := t.TempDir() + stored := filepath.Join(tmpDir, StoredPlanPrefix+PlanFilename) + canonical := filepath.Join(tmpDir, "atmos-key.planfile") + results := []FileResult{ + {Name: PlanFilename, Data: io.NopCloser(strings.NewReader("plan data"))}, + {Name: BindingFilename, Data: io.NopCloser(strings.NewReader("{}"))}, + } + require.NoError(t, WritePlanfileResultsForVerification(results, stored, canonical)) + + assert.FileExists(t, stored) + assert.NoFileExists(t, BindingPath(stored), "a stored plan is only compared against; the fresh plan gets its own record") + assert.NoFileExists(t, BindingPath(canonical)) +} + +func TestOpenBindingFindsOnlyAnExistingRecord(t *testing.T) { + planPath := filepath.Join(t.TempDir(), "atmos-key.planfile") + _, closer, found := OpenBinding(planPath) + assert.False(t, found, "components without a record upload nothing under the record name") + assert.Nil(t, closer) + + require.NoError(t, os.WriteFile(BindingPath(planPath), []byte("record"), 0o600)) + entry, closer, found := OpenBinding(planPath) + require.True(t, found) + defer closer.Close() + assert.Equal(t, BindingFilename, entry.Name) + data, err := io.ReadAll(entry.Data) + require.NoError(t, err) + assert.Equal(t, "record", string(data)) +} diff --git a/pkg/component/helm/aggregate_ci_test.go b/pkg/component/helm/aggregate_ci_test.go index 366b58bcfce..0212de11b1c 100644 --- a/pkg/component/helm/aggregate_ci_test.go +++ b/pkg/component/helm/aggregate_ci_test.go @@ -81,8 +81,10 @@ func (p *helmBulkGraphTestProvider) Execute(ctx *component.ExecutionContext) err } return nil } + func (p *helmBulkGraphTestProvider) GenerateArtifacts(*component.ExecutionContext) error { return nil } -func (p *helmBulkGraphTestProvider) GetAvailableCommands() []string { return nil } + +func (p *helmBulkGraphTestProvider) GetAvailableCommands() []string { return nil } func TestHelmBulkCICollectorRecordsDependencyBlockedComponents(t *testing.T) { collector := newHelmBulkCICollector("apply") diff --git a/pkg/component/provideroptions/flags.go b/pkg/component/provideroptions/flags.go new file mode 100644 index 00000000000..2f08ae033c4 --- /dev/null +++ b/pkg/component/provideroptions/flags.go @@ -0,0 +1,350 @@ +package provideroptions + +import ( + "fmt" + "maps" + "slices" + "strconv" + "strings" + "sync" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/flags" + atmosio "github.com/cloudposse/atmos/pkg/io" + "github.com/cloudposse/atmos/pkg/perf" + "github.com/cloudposse/atmos/pkg/schema" +) + +// sectionAnnotation marks a flag as belonging to a provider, so help can group it. +const sectionAnnotation = "atmos_provider_section" + +// registration records the flags one provider added to one command. +type registration struct { + provider Provider + options []Option + parser *flags.StandardParser +} + +var registered = struct { + sync.Mutex + byCommand map[*cobra.Command][]*registration +}{byCommand: make(map[*cobra.Command][]*registration)} + +// Register adds the flags of every option to the subcommands that accept it. Registration needs no +// running plugin: it uses only the static declarations. A flag name that an Atmos flag or another +// provider already uses is rejected, so a provider can never shadow selection, scheduling, or UI flags. +func Register(root *cobra.Command, providers []Provider) error { + defer perf.Track(nil, "provideroptions.Register")() + + for index := range providers { + provider := &providers[index] + commands := make(map[string][]Option) + for i := range provider.Options { + option := &provider.Options[i] + if !option.AppliesTo(provider.Mode) { + continue + } + for _, name := range option.Commands { + commands[name] = append(commands[name], *option) + } + } + for _, name := range slices.Sorted(maps.Keys(commands)) { + sub := findSubcommand(root, name) + if sub == nil { + continue + } + if err := registerCommand(sub, provider, commands[name]); err != nil { + return err + } + } + } + return nil +} + +func findSubcommand(root *cobra.Command, name string) *cobra.Command { + for _, sub := range root.Commands() { + if sub.Name() == name { + return sub + } + } + return nil +} + +func registerCommand(sub *cobra.Command, provider *Provider, options []Option) error { + if alreadyRegistered(sub, provider) { + return nil + } + var parserOptions []flags.Option + for index := range options { + option := &options[index] + primary := option.FlagName(provider.Name) + for _, name := range append([]string{primary}, option.Aliases...) { + if err := checkCollision(sub, provider, option, name); err != nil { + return err + } + } + parserOptions = append(parserOptions, flagOptions(provider.Name, option, primary)...) + } + parser := flags.NewStandardParser(parserOptions...) + parser.RegisterFlags(sub) + if err := parser.BindToViper(viper.GetViper()); err != nil { + return fmt.Errorf("%w: %w", errUtils.ErrProviderOption, err) + } + for index := range options { + decorate(sub, provider.Name, &options[index]) + } + registered.Lock() + registered.byCommand[sub] = append(registered.byCommand[sub], ®istration{provider: *provider, options: options, parser: parser}) + registered.Unlock() + return nil +} + +func alreadyRegistered(sub *cobra.Command, provider *Provider) bool { + registered.Lock() + defer registered.Unlock() + for _, existing := range registered.byCommand[sub] { + if existing.provider.Name == provider.Name && existing.provider.Section == provider.Section { + return true + } + } + return false +} + +func checkCollision(sub *cobra.Command, provider *Provider, option *Option, name string) error { + if sub.Flags().Lookup(name) == nil && sub.InheritedFlags().Lookup(name) == nil && sub.PersistentFlags().Lookup(name) == nil { + return nil + } + return errUtils.Build(errUtils.ErrProviderOptionCollision). + WithExplanationf("The `%s` configuration provider declares option `%s` with flag `--%s`, but `atmos terraform %s` already has a flag with that name.", provider.Name, option.Name, name, sub.Name()). + WithContext("provider", provider.Name). + WithContext("option", option.Name). + WithContext("command", sub.Name()). + WithHint("Atmos owns stack selection, `--affected`, `--all`, `--ui`, and scheduling flags; a provider option cannot reuse them."). + WithHint("Ask the package author to set a different `flag` for the option in `plugin.yaml`, or remove the conflicting package."). + Err() +} + +func flagOptions(provider string, option *Option, name string) []flags.Option { + description := option.Description + if option.Default != nil { + description += fmt.Sprintf(" (default: %v)", option.Default) + } + var result []flags.Option + switch option.Type { + case TypeBool: + value, _ := option.Default.(bool) + result = append(result, flags.WithBoolFlag(name, "", value, description)) + case TypeInt: + value, _ := option.Default.(int) + result = append(result, flags.WithIntFlag(name, "", value, description)) + case TypeList: + value, _ := option.Default.([]string) + result = append(result, flags.WithStringArrayFlag(name, "", value, description)) + case TypeMap: + result = append(result, flags.WithStringMapFlag(name, "", nil, description)) + default: + value, _ := option.Default.(string) + result = append(result, flags.WithStringFlag(name, "", value, description)) + } + return append(result, flags.WithEnvVars(name, option.EnvNames(provider)...)) +} + +// decorate groups the flags under their provider in help and adds aliases and deprecation. +func decorate(sub *cobra.Command, provider string, option *Option) { + primary := sub.Flags().Lookup(option.FlagName(provider)) + if primary == nil { + return + } + mark(primary, provider) + for _, alias := range option.Aliases { + shared := &pflag.Flag{Name: alias, Usage: "Alias of --" + primary.Name, Value: primary.Value, DefValue: primary.DefValue, NoOptDefVal: primary.NoOptDefVal, Hidden: true} + mark(shared, provider) + sub.Flags().AddFlag(shared) + } + if option.Deprecated != "" { + _ = sub.Flags().MarkDeprecated(primary.Name, option.Deprecated) + } +} + +func mark(flag *pflag.Flag, provider string) { + if flag.Annotations == nil { + flag.Annotations = make(map[string][]string) + } + flag.Annotations[sectionAnnotation] = []string{provider} +} + +// Resolve reads the options the user set for the command, from the command line or the +// environment, and validates them against their declared types. Options the user did not set are +// absent from the result. Values of sensitive options are registered with the output masker and +// never appear in an error. +func Resolve(cmd *cobra.Command, v *viper.Viper) (map[string]map[string]schema.ComponentProviderOption, error) { + defer perf.Track(nil, "provideroptions.Resolve")() + + registered.Lock() + entries := slices.Clone(registered.byCommand[cmd]) + registered.Unlock() + result := make(map[string]map[string]schema.ComponentProviderOption) + for _, entry := range entries { + if err := entry.parser.BindFlagsToViper(cmd, v); err != nil { + return nil, fmt.Errorf("%w: %w", errUtils.ErrProviderOption, err) + } + for index := range entry.options { + option := &entry.options[index] + value, set, err := entry.read(cmd, v, option) + if err != nil { + return nil, err + } + if !set { + continue + } + if result[entry.provider.Section] == nil { + result[entry.provider.Section] = make(map[string]schema.ComponentProviderOption) + } + result[entry.provider.Section][option.Name] = schema.ComponentProviderOption{Value: value, Sensitive: option.Sensitive} + if option.Sensitive { + atmosio.RegisterSecretValue(value) + } + } + } + return result, nil +} + +func (r *registration) read(cmd *cobra.Command, v *viper.Viper, option *Option) (any, bool, error) { + primary := option.FlagName(r.provider.Name) + if !r.explicit(cmd, option, primary) { + return nil, false, nil + } + value, err := convert(option, primary, r.raw(cmd, v, option, primary)) + if err != nil { + return nil, false, err + } + return value, true, nil +} + +func (r *registration) explicit(cmd *cobra.Command, option *Option, primary string) bool { + for _, name := range append([]string{primary}, option.Aliases...) { + if flag := cmd.Flags().Lookup(name); flag != nil && flag.Changed { + return true + } + } + return r.parser.IsFlagExplicitlySet(cmd, primary) +} + +// convert turns a flag or environment value into the declared type. +func convert(option *Option, flag string, raw any) (any, error) { + switch option.Type { + case TypeBool: + parsed, err := strconv.ParseBool(strings.TrimSpace(fmt.Sprint(raw))) + if err != nil { + return nil, invalidValue(option, flag, "expected true or false") + } + return parsed, nil + case TypeInt: + parsed, err := strconv.Atoi(strings.TrimSpace(fmt.Sprint(raw))) + if err != nil { + return nil, invalidValue(option, flag, "expected a whole number") + } + return parsed, nil + case TypeList: + return listValues(raw), nil + case TypeMap: + return mapValues(option, flag, raw) + } + return fmt.Sprint(raw), nil +} + +// listValues reads a repeatable flag or a comma-separated environment value. An explicit empty +// value is an empty list, not an absent one. +func listValues(raw any) []string { + switch typed := raw.(type) { + case []string: + return append([]string{}, typed...) + case []any: + items := make([]string, 0, len(typed)) + for _, item := range typed { + items = append(items, fmt.Sprint(item)) + } + return items + case string: + items := []string{} + for _, item := range strings.Split(typed, ",") { + if item = strings.TrimSpace(item); item != "" { + items = append(items, item) + } + } + return items + } + return []string{} +} + +// mapValues parses name=value entries and rejects malformed ones instead of dropping them. +func mapValues(option *Option, flag string, raw any) (map[string]any, error) { + result := make(map[string]any) + for _, entry := range listValues(raw) { + key, value, found := strings.Cut(entry, "=") + if !found || strings.TrimSpace(key) == "" { + return nil, invalidValue(option, flag, "each entry must look like name=value") + } + result[strings.TrimSpace(key)] = value + } + return result, nil +} + +// invalidValue never echoes the value, which may be a secret. +func invalidValue(option *Option, flag, problem string) error { + return errUtils.Build(errUtils.ErrProviderOption). + WithExplanationf("The value for `--%s` (option `%s`) is invalid: %s.", flag, option.Name, problem). + WithContext("option", option.Name). + WithHintf("Check `--%s` or the environment variable that supplies it. Run the command with `--help` to see the accepted values.", flag). + Err() +} + +// Section is a titled group of provider flags, for help output. +type Section struct { + Title string + Flags *pflag.FlagSet +} + +// SplitFlags separates provider flags from the rest, so help can show them under a provider heading. +func SplitFlags(set *pflag.FlagSet) (*pflag.FlagSet, []Section) { + defer perf.Track(nil, "provideroptions.SplitFlags")() + + rest := pflag.NewFlagSet("flags", pflag.ContinueOnError) + groups := make(map[string]*pflag.FlagSet) + set.VisitAll(func(flag *pflag.Flag) { + provider := flag.Annotations[sectionAnnotation] + if len(provider) == 0 { + rest.AddFlag(flag) + return + } + if groups[provider[0]] == nil { + groups[provider[0]] = pflag.NewFlagSet(provider[0], pflag.ContinueOnError) + } + groups[provider[0]].AddFlag(flag) + }) + sections := make([]Section, 0, len(groups)) + for _, name := range slices.Sorted(maps.Keys(groups)) { + sections = append(sections, Section{Title: strings.ToUpper(name) + " FLAGS", Flags: groups[name]}) + } + return rest, sections +} + +// raw returns the value of an alias the user typed, which Viper does not see because only the +// primary flag is bound, and otherwise the layered value of the primary flag. +func (r *registration) raw(cmd *cobra.Command, v *viper.Viper, option *Option, primary string) any { + for _, name := range option.Aliases { + flag := cmd.Flags().Lookup(name) + if flag == nil || !flag.Changed { + continue + } + if slice, ok := flag.Value.(pflag.SliceValue); ok { + return slice.GetSlice() + } + return flag.Value.String() + } + return v.Get(primary) +} diff --git a/pkg/component/provideroptions/options.go b/pkg/component/provideroptions/options.go new file mode 100644 index 00000000000..9323e973791 --- /dev/null +++ b/pkg/component/provideroptions/options.go @@ -0,0 +1,294 @@ +// Package provideroptions declares, registers, and resolves the typed options a configuration +// provider adds to `atmos terraform` commands. +// +// A provider declares its options as static package metadata, so the host can register flags and +// render help without starting the plugin. Values follow the repo's flag precedence (command line, +// then environment); the provider's own configuration layer sits below both and is read by the +// provider. Only options the user set explicitly are reported, so a provider can tell an absent +// option from an explicit false, zero, or empty value. +package provideroptions + +import ( + "fmt" + "regexp" + "slices" + "strings" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/perf" +) + +// Option value types. +const ( + TypeString = "string" + TypeBool = "bool" + TypeInt = "int" + TypeList = "list" + TypeMap = "map" +) + +// Modes a configuration provider section can run in. +const ( + ModeNative = "native" + ModeExecutable = "executable" +) + +// Option is one statically declared provider option. +type Option struct { + // Name is the key under which the value reaches the provider, in snake_case. + Name string + // Flag is the long flag name without dashes. It defaults to `-`. + Flag string + // Aliases are additional hidden flag names for the same option. + Aliases []string + Type string + // Default is documented in help. The provider applies it when the option is absent; the host never sends it. + Default any + // Config is the key under the provider's configuration section that supplies the lowest-precedence value. + Config string + // Env lists environment variables in addition to ATMOS__. + Env []string + // Modes lists the section modes the option applies to. Empty means every mode. + Modes []string + // Commands lists the `atmos terraform` subcommands that accept the option. + Commands []string + // Sensitive values are masked, hashed into saved-plan identities, and never logged or written to configuration. + Sensitive bool + // Deprecated is the message shown when the option is used. Empty means the option is current. + Deprecated string + Description string +} + +// Provider groups the options of one enabled configuration section. +type Provider struct { + // Section is the key under `components.terraform` that enabled the provider. + Section string + // Name is the provider name; it prefixes flag and environment variable names. + Name string + Mode string + // Options are the declared options. Registration filters them by mode. + Options []Option +} + +var ( + namePattern = regexp.MustCompile(`^[a-z][a-z0-9_]*$`) + flagPattern = regexp.MustCompile(`^[a-z][a-z0-9-]*$`) + envPattern = regexp.MustCompile(`^[A-Z][A-Z0-9_]*$`) + nonWord = regexp.MustCompile(`[^a-z0-9]+`) +) + +var optionKeys = []string{"name", "flag", "aliases", "type", "default", "config", "env", "modes", "commands", "sensitive", "deprecated", "description"} + +// FlagName returns the primary flag name of an option for the provider. +// +//nolint:lintroller // Pure name derivation; no I/O. +func (o *Option) FlagName(provider string) string { + if o.Flag != "" { + return o.Flag + } + return slug(provider, "-") + "-" + strings.ReplaceAll(o.Name, "_", "-") +} + +// EnvNames returns the environment variables that supply the option, Atmos-prefixed name first. +// +//nolint:lintroller // Pure name derivation; no I/O. +func (o *Option) EnvNames(provider string) []string { + primary := "ATMOS_" + strings.ToUpper(slug(provider, "_")) + "_" + strings.ToUpper(o.Name) + return append([]string{primary}, o.Env...) +} + +// slug makes a provider name safe for flag and environment variable names: `vendor/tool` becomes `vendor-tool`. +func slug(provider, separator string) string { + return nonWord.ReplaceAllString(strings.ToLower(provider), separator) +} + +// AppliesTo reports whether the option is valid in a section mode. +// +//nolint:lintroller // Pure lookup; no I/O. +func (o *Option) AppliesTo(mode string) bool { + return len(o.Modes) == 0 || slices.Contains(o.Modes, mode) +} + +// Parse validates the `options` metadata of a provider export. The value comes from the package +// manifest, so every problem names the offending option and how to repair it. +func Parse(provider string, raw any) ([]Option, error) { + defer perf.Track(nil, "provideroptions.Parse")() + + if raw == nil { + return nil, nil + } + entries, ok := raw.([]any) + if !ok { + return nil, declarationError("", "`options` must be a list of option declarations") + } + options := make([]Option, 0, len(entries)) + flagsSeen := make(map[string]string) + for index, entry := range entries { + fields, ok := entry.(map[string]any) + if !ok { + return nil, declarationError(fmt.Sprintf("#%d", index), "an option declaration must be a mapping") + } + option, err := parseOption(provider, fields) + if err != nil { + return nil, err + } + if err := recordFlags(provider, &option, flagsSeen); err != nil { + return nil, err + } + options = append(options, option) + } + return options, nil +} + +func recordFlags(provider string, option *Option, seen map[string]string) error { + for _, name := range append([]string{option.FlagName(provider)}, option.Aliases...) { + if previous, exists := seen[name]; exists { + return declarationError(option.Name, fmt.Sprintf("flag `--%s` is already used by option `%s`", name, previous)) + } + seen[name] = option.Name + } + return nil +} + +func parseOption(provider string, fields map[string]any) (Option, error) { + for key := range fields { + if !slices.Contains(optionKeys, key) { + return Option{}, declarationError(stringField(fields, "name"), fmt.Sprintf("unsupported key `%s`; use one of %s", key, strings.Join(optionKeys, ", "))) + } + } + option := Option{ + Name: stringField(fields, "name"), Flag: stringField(fields, "flag"), Type: stringField(fields, "type"), + Config: stringField(fields, "config"), Deprecated: stringField(fields, "deprecated"), Description: stringField(fields, "description"), + } + option.Sensitive, _ = fields["sensitive"].(bool) + var err error + for target, key := range map[*[]string]string{&option.Aliases: "aliases", &option.Env: "env", &option.Modes: "modes", &option.Commands: "commands"} { + if *target, err = stringList(fields[key]); err != nil { + return Option{}, declarationError(option.Name, fmt.Sprintf("`%s` must be a list of strings", key)) + } + } + if option.Default, err = typedDefault(option.Type, fields["default"]); err != nil { + return Option{}, declarationError(option.Name, err.Error()) + } + if err := validateOption(provider, &option); err != nil { + return Option{}, err + } + return option, nil +} + +func validateOption(provider string, option *Option) error { + if err := validateShape(option); err != nil { + return err + } + for _, name := range append([]string{option.FlagName(provider)}, option.Aliases...) { + if !flagPattern.MatchString(name) { + return declarationError(option.Name, fmt.Sprintf("flag name %q must be lowercase words separated by dashes", name)) + } + } + for _, name := range option.Env { + if !envPattern.MatchString(name) { + return declarationError(option.Name, fmt.Sprintf("environment variable %q must be upper case with underscores", name)) + } + } + return validateModes(option) +} + +func validateShape(option *Option) error { + switch { + case !namePattern.MatchString(option.Name): + return declarationError(option.Name, "`name` must be snake_case, for example `iam_assume_role`") + case !slices.Contains([]string{TypeString, TypeBool, TypeInt, TypeList, TypeMap}, option.Type): + return declarationError(option.Name, "`type` must be one of string, bool, int, list, or map") + case option.Description == "": + return declarationError(option.Name, "`description` is required because it is the help text") + case len(option.Commands) == 0: + return declarationError(option.Name, "`commands` must list the terraform subcommands that accept the option") + case option.Sensitive && (option.Config != "" || option.Default != nil): + return declarationError(option.Name, "a sensitive option cannot have a `config` key or a `default`, because secrets must not be written to configuration") + } + return nil +} + +func validateModes(option *Option) error { + for _, mode := range option.Modes { + if mode != ModeNative && mode != ModeExecutable { + return declarationError(option.Name, fmt.Sprintf("mode %q is not one of native or executable", mode)) + } + } + return nil +} + +func stringField(fields map[string]any, key string) string { + value, _ := fields[key].(string) + return value +} + +func stringList(raw any) ([]string, error) { + if raw == nil { + return nil, nil + } + items, ok := raw.([]any) + if !ok { + return nil, errUtils.ErrProviderOption + } + result := make([]string, 0, len(items)) + for _, item := range items { + text, ok := item.(string) + if !ok || text == "" { + return nil, errUtils.ErrProviderOption + } + result = append(result, text) + } + return result, nil +} + +// defaultCheckers accept a declared default of each option type. +var defaultCheckers = map[string]func(any) (any, bool){ + TypeString: func(raw any) (any, bool) { text, ok := raw.(string); return text, ok }, + TypeBool: func(raw any) (any, bool) { flag, ok := raw.(bool); return flag, ok }, + TypeInt: integer, + TypeList: func(raw any) (any, bool) { + items, err := stringList(raw) + return items, err == nil + }, +} + +// typedDefault checks that a declared default matches the option type. +func typedDefault(optionType string, raw any) (any, error) { + if raw == nil { + return nil, nil + } + if optionType == TypeMap { + return nil, fmt.Errorf("%w: a map option cannot declare a default; set it in configuration instead", errUtils.ErrProviderOption) + } + if check := defaultCheckers[optionType]; check != nil { + if value, ok := check(raw); ok { + return value, nil + } + } + return nil, fmt.Errorf("%w: `default` does not match type %s", errUtils.ErrProviderOption, optionType) +} + +func integer(raw any) (any, bool) { + switch number := raw.(type) { + case int: + return number, true + case int64: + return int(number), true + case float64: + whole := int(number) + return whole, float64(whole) == number + } + return nil, false +} + +func declarationError(option, problem string) error { + label := "an option" + if option != "" { + label = "option `" + option + "`" + } + return errUtils.Build(errUtils.ErrProviderOption). + WithExplanationf("The package metadata declares %s incorrectly: %s.", label, problem). + WithHint("Fix the `options` list of the configuration export in the package's `plugin.yaml`."). + Err() +} diff --git a/pkg/component/provideroptions/provideroptions_test.go b/pkg/component/provideroptions/provideroptions_test.go new file mode 100644 index 00000000000..66bab85e7af --- /dev/null +++ b/pkg/component/provideroptions/provideroptions_test.go @@ -0,0 +1,246 @@ +package provideroptions + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/schema" +) + +// Compile-time sentinels for the schema fields these tests depend on. +var _ = schema.ComponentProviderOption{Value: "", Sensitive: true} + +func declaration(fields map[string]any) any { + base := map[string]any{"name": "level", "type": "string", "description": "A level.", "commands": []any{"plan"}} + for key, value := range fields { + base[key] = value + } + return []any{base} +} + +func TestParseAcceptsEveryType(t *testing.T) { + raw := []any{ + map[string]any{"name": "feature", "type": "map", "config": "features", "env": []any{"TG_FEATURE"}, "description": "Features.", "commands": []any{"plan", "apply"}, "modes": []any{"native", "executable"}}, + map[string]any{"name": "retries", "type": "int", "default": 3, "description": "Retries.", "commands": []any{"plan"}, "aliases": []any{"retry-count"}}, + map[string]any{"name": "quiet", "type": "bool", "default": false, "description": "Quiet.", "commands": []any{"plan"}}, + map[string]any{"name": "paths", "type": "list", "default": []any{"a"}, "description": "Paths.", "commands": []any{"plan"}}, + map[string]any{"name": "token", "type": "string", "sensitive": true, "description": "Token.", "commands": []any{"plan"}}, + } + options, err := Parse("tool", raw) + require.NoError(t, err) + require.Len(t, options, 5) + assert.Equal(t, "tool-feature", options[0].FlagName("tool")) + assert.Equal(t, []string{"ATMOS_TOOL_FEATURE", "TG_FEATURE"}, options[0].EnvNames("tool")) + assert.Equal(t, 3, options[1].Default) + assert.Equal(t, []string{"a"}, options[3].Default) + assert.True(t, options[4].Sensitive) + assert.True(t, options[0].AppliesTo(ModeExecutable)) + assert.True(t, options[1].AppliesTo(ModeNative), "no modes means every mode") + last, err := Parse("tool", nil) + require.NoError(t, err) + assert.Nil(t, last) +} + +func TestParseRejectsInvalidDeclarations(t *testing.T) { + cases := map[string]any{ + "not a list": "options", + "not a mapping": []any{"level"}, + "unknown key": declaration(map[string]any{"flavor": "x"}), + "bad name": declaration(map[string]any{"name": "Level"}), + "bad type": declaration(map[string]any{"type": "float"}), + "missing help": declaration(map[string]any{"description": ""}), + "no commands": declaration(map[string]any{"commands": nil}), + "commands type": declaration(map[string]any{"commands": "plan"}), + "secret in config": declaration(map[string]any{"sensitive": true, "config": "level"}), + "secret default": declaration(map[string]any{"sensitive": true, "default": "x"}), + "default mismatch": declaration(map[string]any{"type": "int", "default": "x"}), + "map default": declaration(map[string]any{"type": "map", "default": map[string]any{}}), + "bad flag": declaration(map[string]any{"flag": "Bad_Flag"}), + "bad env": declaration(map[string]any{"env": []any{"lower"}}), + "bad mode": declaration(map[string]any{"modes": []any{"fast"}}), + "duplicate aliases": declaration(map[string]any{"aliases": []any{"tool-level"}}), + } + for name, raw := range cases { + t.Run(name, func(t *testing.T) { + _, err := Parse("tool", raw) + require.ErrorIs(t, err, errUtils.ErrProviderOption) + }) + } +} + +func TestParseRejectsTwoOptionsWithOneFlag(t *testing.T) { + _, err := Parse("tool", []any{ + map[string]any{"name": "one", "type": "string", "description": "One.", "commands": []any{"plan"}, "flag": "same"}, + map[string]any{"name": "two", "type": "string", "description": "Two.", "commands": []any{"plan"}, "flag": "same"}, + }) + require.ErrorIs(t, err, errUtils.ErrProviderOption) +} + +// newTree builds a terraform-like command with two subcommands. +func newTree() (root, plan, apply *cobra.Command) { + root = &cobra.Command{Use: "terraform"} + plan = &cobra.Command{Use: "plan", RunE: func(*cobra.Command, []string) error { return nil }} + apply = &cobra.Command{Use: "apply", RunE: func(*cobra.Command, []string) error { return nil }} + root.AddCommand(plan, apply) + return root, plan, apply +} + +func providerFor(t *testing.T, section string, raw []any) Provider { + t.Helper() + options, err := Parse("tool", raw) + require.NoError(t, err) + return Provider{Section: section, Name: "tool", Mode: ModeNative, Options: options} +} + +func TestRegisterAddsFlagsOnlyWhereTheyApply(t *testing.T) { + root, plan, apply := newTree() + provider := providerFor(t, "tool", []any{ + map[string]any{"name": "level", "type": "string", "description": "A level.", "commands": []any{"plan"}}, + map[string]any{"name": "fast", "type": "bool", "description": "Fast.", "commands": []any{"plan", "apply"}, "modes": []any{"executable"}}, + map[string]any{"name": "elsewhere", "type": "string", "description": "Missing command.", "commands": []any{"destroy"}}, + map[string]any{"name": "old", "type": "string", "description": "Old.", "commands": []any{"apply"}, "deprecated": "use --tool-level", "aliases": []any{"tool-legacy"}}, + }) + require.NoError(t, Register(root, []Provider{provider})) + assert.NotNil(t, plan.Flags().Lookup("tool-level")) + assert.Nil(t, apply.Flags().Lookup("tool-level")) + assert.Nil(t, plan.Flags().Lookup("tool-fast"), "an executable-only option is not registered in native mode") + assert.True(t, apply.Flags().Lookup("tool-old").Deprecated != "") + assert.True(t, apply.Flags().Lookup("tool-legacy").Hidden) + // Registering again is a no-op, not a collision with itself. + require.NoError(t, Register(root, []Provider{provider})) +} + +func TestRegisterRejectsCollisions(t *testing.T) { + root, plan, _ := newTree() + plan.Flags().Bool("tool-level", false, "an Atmos flag") + provider := providerFor(t, "tool", []any{ + map[string]any{"name": "level", "type": "string", "description": "A level.", "commands": []any{"plan"}}, + }) + err := Register(root, []Provider{provider}) + require.ErrorIs(t, err, errUtils.ErrProviderOptionCollision) + + root, plan, _ = newTree() + plan.PersistentFlags().Bool("all", false, "selection") + reserved := providerFor(t, "tool", []any{ + map[string]any{"name": "everything", "flag": "all", "type": "bool", "description": "All.", "commands": []any{"plan"}}, + }) + require.ErrorIs(t, Register(root, []Provider{reserved}), errUtils.ErrProviderOptionCollision) +} + +func TestRegisterRejectsTwoProvidersWithOneFlag(t *testing.T) { + root, _, _ := newTree() + raw := []any{map[string]any{"name": "level", "type": "string", "flag": "shared-level", "description": "A level.", "commands": []any{"plan"}}} + first := providerFor(t, "one", raw) + first.Name = "one" + second := providerFor(t, "two", raw) + second.Name = "two" + require.ErrorIs(t, Register(root, []Provider{first, second}), errUtils.ErrProviderOptionCollision) +} + +func resolveWith(t *testing.T, raw []any, args []string, env map[string]string) (map[string]map[string]schema.ComponentProviderOption, error) { + t.Helper() + for name, value := range env { + t.Setenv(name, value) + } + root, plan, _ := newTree() + require.NoError(t, Register(root, []Provider{providerFor(t, "tool", raw)})) + require.NoError(t, plan.ParseFlags(args)) + return Resolve(plan, viper.New()) +} + +var sample = []any{ + map[string]any{"name": "feature", "type": "map", "env": []any{"TG_TEST_FEATURE"}, "description": "Features.", "commands": []any{"plan"}}, + map[string]any{"name": "level", "type": "string", "default": "info", "description": "Level.", "commands": []any{"plan"}}, + map[string]any{"name": "retries", "type": "int", "description": "Retries.", "commands": []any{"plan"}}, + map[string]any{"name": "quiet", "type": "bool", "description": "Quiet.", "commands": []any{"plan"}}, + map[string]any{"name": "paths", "type": "list", "description": "Paths.", "commands": []any{"plan"}}, + map[string]any{"name": "token", "type": "string", "sensitive": true, "description": "Token.", "commands": []any{"plan"}}, +} + +func TestResolveReportsOnlyExplicitOptions(t *testing.T) { + resolved, err := resolveWith(t, sample, nil, nil) + require.NoError(t, err) + assert.Empty(t, resolved, "defaults are not explicit values") +} + +func TestResolvePreservesExplicitFalseZeroAndEmpty(t *testing.T) { + resolved, err := resolveWith(t, sample, []string{"--tool-quiet=false", "--tool-retries=0", "--tool-level=", "--tool-paths="}, nil) + require.NoError(t, err) + values := resolved["tool"] + assert.Equal(t, false, values["quiet"].Value) + assert.Equal(t, 0, values["retries"].Value) + assert.Equal(t, "", values["level"].Value) + assert.NotNil(t, values["paths"].Value) + assert.Len(t, values, 4) +} + +func TestResolveMapsAndListsFromTheCommandLine(t *testing.T) { + resolved, err := resolveWith(t, sample, []string{"--tool-feature", "alpha=true", "--tool-feature=beta=two", "--tool-paths", "a", "--tool-paths", "b"}, nil) + require.NoError(t, err) + assert.Equal(t, map[string]any{"alpha": "true", "beta": "two"}, resolved["tool"]["feature"].Value) + assert.Equal(t, []string{"a", "b"}, resolved["tool"]["paths"].Value) +} + +func TestResolveCommandLineBeatsEnvironment(t *testing.T) { + resolved, err := resolveWith(t, sample, []string{"--tool-level=cli"}, map[string]string{"ATMOS_TOOL_LEVEL": "env", "ATMOS_TOOL_RETRIES": "7", "TG_TEST_FEATURE": "x=1,y=2"}) + require.NoError(t, err) + values := resolved["tool"] + assert.Equal(t, "cli", values["level"].Value) + assert.Equal(t, 7, values["retries"].Value) + assert.Equal(t, map[string]any{"x": "1", "y": "2"}, values["feature"].Value) +} + +func TestResolveRejectsInvalidValuesWithoutEchoingThem(t *testing.T) { + for name, args := range map[string][]string{ + "bad map": {"--tool-feature=novalue"}, + "empty key": {"--tool-feature==x"}, + } { + t.Run(name, func(t *testing.T) { + _, err := resolveWith(t, sample, args, nil) + require.ErrorIs(t, err, errUtils.ErrProviderOption) + }) + } + // Environment values are parsed by Atmos, so a malformed one is rejected without being echoed. + for name, value := range map[string]string{"ATMOS_TOOL_QUIET": "maybe", "ATMOS_TOOL_RETRIES": "lots"} { + _, err := resolveWith(t, sample, nil, map[string]string{name: value}) + require.ErrorIs(t, err, errUtils.ErrProviderOption) + assert.NotContains(t, err.Error(), value) + } +} + +func TestResolveMarksSensitiveValues(t *testing.T) { + resolved, err := resolveWith(t, sample, []string{"--tool-token=s3cret-value"}, nil) + require.NoError(t, err) + assert.True(t, resolved["tool"]["token"].Sensitive) + assert.Equal(t, "s3cret-value", resolved["tool"]["token"].Value) +} + +func TestResolveAcceptsAliasFlags(t *testing.T) { + raw := []any{map[string]any{"name": "level", "type": "string", "description": "Level.", "commands": []any{"plan"}, "aliases": []any{"tool-lvl"}}} + resolved, err := resolveWith(t, raw, []string{"--tool-lvl=debug"}, nil) + require.NoError(t, err) + assert.Equal(t, "debug", resolved["tool"]["level"].Value) +} + +func TestSplitFlagsGroupsProviderFlags(t *testing.T) { + root, plan, _ := newTree() + plan.Flags().Bool("affected", false, "Atmos flag") + require.NoError(t, Register(root, []Provider{providerFor(t, "tool", sample)})) + rest, sections := SplitFlags(plan.Flags()) + assert.NotNil(t, rest.Lookup("affected")) + assert.Nil(t, rest.Lookup("tool-level")) + require.Len(t, sections, 1) + assert.Equal(t, "TOOL FLAGS", sections[0].Title) + assert.NotNil(t, sections[0].Flags.Lookup("tool-level")) +} + +func TestNamesAreDerivedFromProvidersWithSlashes(t *testing.T) { + option := Option{Name: "iam_role"} + assert.Equal(t, "vendor-tool-iam-role", option.FlagName("vendor/tool")) + assert.Equal(t, []string{"ATMOS_VENDOR_TOOL_IAM_ROLE"}, option.EnvNames("vendor/tool")) +} diff --git a/pkg/component/terraform/configuration.go b/pkg/component/terraform/configuration.go index 8b76b5897ea..053adfd3b35 100644 --- a/pkg/component/terraform/configuration.go +++ b/pkg/component/terraform/configuration.go @@ -23,27 +23,67 @@ import ( u "github.com/cloudposse/atmos/pkg/utils" ) +// prepareConfiguration prepares a provider-owned component whose saved plan, if any, still has its +// retained working directory. Execution uses prepareConfigurationForExecution, which can also +// re-provision the directory of a plan restored on another runner. func prepareConfiguration(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (*schema.PreparedComponentConfiguration, error) { + prepared, rebuild, err := prepareConfigurationForExecution(ctx, config, info) + if err == nil && rebuild != nil { + return nil, fmt.Errorf("%w: reviewed working directory changed", errUtils.ErrPlanVerificationFailed) + } + return prepared, err +} + +// prepareConfigurationForExecution is prepareConfiguration that reports a pending rebuild: the +// returned reviewedRebuild is non-nil when the reviewed plan was verified but its working directory +// must be re-provisioned and checked before the plan can be applied. +func prepareConfigurationForExecution(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (*schema.PreparedComponentConfiguration, *reviewedRebuild, error) { if _, owned := info.ComponentSettingsSection["configuration"]; !owned { - return nil, nil + return nil, nil, nil } - if config.ComponentConfigurations == nil { - return nil, errUtils.ErrPluginUnsupportedExtension + if err := checkConfigurationPreconditions(config, info); err != nil { + return nil, nil, err } - if err := checkComponentRestrictions(info); err != nil { - return nil, err + if info.DryRun { + return nil, nil, nil } - if err := checkStackOverrides(info); err != nil { - return nil, err + if err := resolveConfigurationBinary(info); err != nil { + return nil, nil, err } - if info.DryRun { - return nil, nil + prepared, rebuild, err := obtainConfiguration(ctx, config, info) + if err != nil || prepared == nil { + return prepared, nil, err } - // Plugins do not inherit PATH. Resolve the selected host executable before - // Terragrunt evaluates version constraints or dependency outputs. + if err = applyStackOverrides(config, info, prepared); err != nil { + return nil, nil, err + } + if err = applyIAMRole(ctx, info, prepared.IAM); err != nil { + return nil, nil, err + } + applyPreparedConfiguration(config, info, prepared) + return prepared, rebuild, nil +} + +// checkConfigurationPreconditions rejects what no preparation can fix: no provider, a restricted +// component, or a stack that overrides what the provider owns. +func checkConfigurationPreconditions(config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) error { + if config.ComponentConfigurations == nil { + return errUtils.ErrPluginUnsupportedExtension + } + dropCIPlanLocation(info) + if err := checkComponentRestrictions(info); err != nil { + return err + } + return checkStackOverrides(info) +} + +// resolveConfigurationBinary resolves the selected Terraform executable to an absolute path. +// Plugins do not inherit PATH, so this happens before Terragrunt evaluates version constraints +// or dependency outputs. +func resolveConfigurationBinary(info *schema.ConfigAndStacksInfo) error { binary, err := exec.LookPath(info.Command) if err != nil { - return nil, errUtils.Build(fmt.Errorf("%w: Terraform executable of component %q in stack %q: %w", errUtils.ErrPluginInvalidConfig, info.ComponentFromArg, info.Stack, err)). + return errUtils.Build(fmt.Errorf("%w: Terraform executable of component %q in stack %q: %w", errUtils.ErrPluginInvalidConfig, info.ComponentFromArg, info.Stack, err)). WithContext("component", info.ComponentFromArg). WithContext("stack", info.Stack). WithContext("executable", info.Command). @@ -52,27 +92,32 @@ func prepareConfiguration(ctx context.Context, config *schema.AtmosConfiguration } binary, err = filepath.Abs(binary) if err != nil { - return nil, fmt.Errorf("%w: %w", errUtils.ErrPluginInvalidConfig, err) + return fmt.Errorf("%w: %w", errUtils.ErrPluginInvalidConfig, err) } info.Command = binary - var prepared *schema.PreparedComponentConfiguration - if usesConfigurationPlan(info) { - if err = useRetainedWorkdir(config, info); err != nil { - return nil, err - } - prepared, err = restoreConfigurationPlan(ctx, config, info) - } else { - prepared, err = config.ComponentConfigurations.Prepare(ctx, info) - } - if err != nil || prepared == nil { - return prepared, err - } - if err = applyStackOverrides(config, info, prepared); err != nil { - return nil, err - } - if err = applyIAMRole(ctx, info, prepared.IAM); err != nil { - return nil, err - } + return nil +} + +// obtainConfiguration evaluates the unit, or restores the reviewed preparation of a saved plan. The +// rebuild is non-nil when the saved plan lost its working directory and must be re-provisioned. +func obtainConfiguration(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (*schema.PreparedComponentConfiguration, *reviewedRebuild, error) { + if !usesConfigurationPlan(info) { + prepared, err := config.ComponentConfigurations.Prepare(ctx, info) + return prepared, nil, err + } + if err := useRetainedWorkdir(config, info); err != nil { + return nil, nil, err + } + prepared, rebuild, err := restoreOrRebuildConfigurationPlan(ctx, config, info) + if err != nil || rebuild == nil { + return prepared, rebuild, err + } + rebuild.prepared, err = prepareForRebuild(ctx, config, info, rebuild) + return rebuild.prepared, rebuild, err +} + +// applyPreparedConfiguration records the prepared values on the invocation. +func applyPreparedConfiguration(config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, prepared *schema.PreparedComponentConfiguration) { info.ComponentVarsSection = prepared.Inputs info.ComponentExecution = prepared.Execution info.ComponentBackendType, info.ComponentBackendSection = prepared.BackendType, prepared.Backend @@ -91,6 +136,27 @@ func prepareConfiguration(ctx context.Context, config *schema.AtmosConfiguration info.ComponentSection["backend"] = prepared.Backend config.Components.Terraform.AutoGenerateBackendFile = !prepared.BackendGenerated warnOnCacheLocalState(info, prepared) +} + +// prepareForRebuild evaluates the unit again for a plan restored without its working directory, the +// way `plan` did, so the directory is regenerated from the checkout's own configuration instead of +// from the restored record. The evaluation must reproduce the reviewed backend. The plan file already +// embodies the inputs, so none are kept. +func prepareForRebuild(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, rebuild *reviewedRebuild) (*schema.PreparedComponentConfiguration, error) { + fresh := *info + fresh.UseTerraformPlan, fresh.PlanFile, fresh.StoredPlanFile = false, "", "" + prepared, err := config.ComponentConfigurations.Prepare(ctx, &fresh) + if err != nil || prepared == nil { + return nil, err + } + digest, err := backendIdentityDigest(prepared.Backend) + if err != nil { + return nil, err + } + if digest != rebuild.plan.BackendDigest || prepared.BackendType != rebuild.plan.Prepared.BackendType || prepared.Workspace != rebuild.plan.Prepared.Workspace { + return nil, fmt.Errorf("%w: reviewed backend identity changed", errUtils.ErrPlanVerificationFailed) + } + prepared.Inputs = map[string]any{} return prepared, nil } diff --git a/pkg/component/terraform/configuration_plan.go b/pkg/component/terraform/configuration_plan.go index 389a6ff0029..5b9c29ff746 100644 --- a/pkg/component/terraform/configuration_plan.go +++ b/pkg/component/terraform/configuration_plan.go @@ -15,22 +15,31 @@ import ( "strings" errUtils "github.com/cloudposse/atmos/errors" + ciplanfile "github.com/cloudposse/atmos/pkg/ci/plugins/terraform/planfile" "github.com/cloudposse/atmos/pkg/schema" ) +// freshPlanName is the file `deploy` writes the plan it generates for verification to. +const freshPlanName = "new.plan" + const configurationPlanSuffix = ".atmos.json" // configurationPlanVersion is bumped whenever the stored binding changes shape. -const configurationPlanVersion = 2 +const configurationPlanVersion = 3 // configurationPlan is the private record stored beside a saved plan. It binds the plan to the // exact preparation it was made from. Evaluated inputs and backend settings are not stored: // the plan file already embodies the inputs, and the backend is re-resolved at apply time and // compared by BackendDigest, so credentials in backend settings never reach this file. +// +// RebuildDigest and LockDigest let a runner that holds only the restored artifacts prove that a +// workdir it re-provisioned from the checkout equals the reviewed one: RebuildDigest covers the +// files restoration regenerates (module source and generated files, not the plan, its record, +// variable files, state, or the lock file), and LockDigest the provider lock file ("" when absent). type configurationPlan struct { Version int Stack, Component, Identity, EngineDigest, PlanDigest, WorkingDirectory, WorkingDigest string - BackendDigest string + BackendDigest, RebuildDigest, LockDigest string Prepared *schema.PreparedComponentConfiguration } @@ -41,8 +50,20 @@ func ownsConfigurationPlan(info *schema.ConfigAndStacksInfo) bool { return owned } +// usesConfigurationPlan reports whether the invocation applies a saved plan. A downloaded +// StoredPlanFile alone does not: it is a reference that `deploy` compares a fresh plan against, and +// the fresh plan is what gets applied. func usesConfigurationPlan(info *schema.ConfigAndStacksInfo) bool { - return info.UseTerraformPlan || info.PlanFile != "" || info.StoredPlanFile != "" + return info.UseTerraformPlan || info.PlanFile != "" +} + +// dropCIPlanLocation forgets the plan path the CI download hook records while it fetches a stored +// plan for `deploy`. Every way a user names a plan to apply also sets UseTerraformPlan, so a PlanFile +// that comes with a StoredPlanFile and no UseTerraformPlan is only the place the hook looked. +func dropCIPlanLocation(info *schema.ConfigAndStacksInfo) { + if info.PlanFile != "" && !info.UseTerraformPlan && info.StoredPlanFile != "" { + info.PlanFile = "" + } } func planRuntime(config *schema.AtmosConfiguration) (schema.ComponentConfigurationPlanRuntime, error) { @@ -64,58 +85,67 @@ func configurationPlanPath(config *schema.AtmosConfiguration, info *schema.Confi } // restoreConfigurationPlan verifies the reviewed artifact before returning its original preparation. -// The original execution directory is retained; transport to another runner requires an artifact adapter. +// It requires the retained working directory; a runner that holds only the restored artifacts goes +// through restoreOrRebuildConfigurationPlan instead, which re-provisions the directory. func restoreConfigurationPlan(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (*schema.PreparedComponentConfiguration, error) { - if !restoresConfigurationPlan(info) { - return nil, fmt.Errorf("%w: plugin saved plans require direct apply of the original artifact", errUtils.ErrPluginUnsupportedExtension) - } - runtime, err := planRuntime(config) + prepared, rebuild, err := restoreOrRebuildConfigurationPlan(ctx, config, info) if err != nil { return nil, err } + if rebuild != nil { + return nil, fmt.Errorf("%w: reviewed working directory changed", errUtils.ErrPlanVerificationFailed) + } + return prepared, nil +} + +// restoreOrRebuildConfigurationPlan verifies everything about a reviewed plan that does not depend on +// the working directory: the record's coordinates, the plan bytes, the engine, the provider, options +// and watched sources, and the backend. The directory itself is then either the retained one (its +// digest equals the reviewed digest), or it holds nothing but the restored artifacts and must be +// re-provisioned (a non-nil rebuild), or it is unverifiable and the plan is rejected. +func restoreOrRebuildConfigurationPlan(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) (*schema.PreparedComponentConfiguration, *reviewedRebuild, error) { + if !restoresConfigurationPlan(info) { + return nil, nil, fmt.Errorf("%w: plugin saved plans require direct apply of the original artifact", errUtils.ErrPluginUnsupportedExtension) + } + if _, err := planRuntime(config); err != nil { + return nil, nil, err + } path := configurationPlanPath(config, info) plan, err := loadConfigurationPlan(path, info) if err != nil { - return nil, err + return nil, nil, err } - identity, err := runtime.PlanIdentity(ctx, info, plan.Prepared.Sources) - if err != nil { - return nil, err + if err := verifyReviewedArtifacts(ctx, config, info, plan, path); err != nil { + return nil, nil, err } - artifactMatches, err := configurationArtifactMatches(config, info, plan, path) + retained, err := workdirMatches(plan, path) if err != nil { - return nil, err - } - if identity != plan.Identity || !artifactMatches { - return nil, fmt.Errorf("%w: plugin, source, engine, workdir, or reviewed artifact changed; create a new plan", errUtils.ErrPlanVerificationFailed) - } - if err := verifyReviewedBackendAndWorkdir(ctx, config, info, plan, path); err != nil { - return nil, err - } - if err := restoreSensitiveContent(plan.WorkingDirectory, plan.Prepared.Files); err != nil { - return nil, err + return nil, nil, err + } + var rebuild *reviewedRebuild + if retained { + // The retained workdir is verified, so it holds the reviewed bytes of sensitive files. A rebuild + // instead writes them again from a fresh preparation. + if err := restoreSensitiveContent(plan.WorkingDirectory, plan.Prepared.Files); err != nil { + return nil, nil, err + } + } else if rebuild, err = newReviewedRebuild(info, plan, path); err != nil { + return nil, nil, err } // Terraform runs inside the workdir, so a path relative to the project would not resolve there. absolute, err := filepath.Abs(path) if err != nil { - return nil, err + return nil, nil, err } info.UseTerraformPlan = true info.PlanFile = absolute - return plan.Prepared, nil -} - -// verifyReviewedBackendAndWorkdir rejects a changed backend identity or a changed retained working directory. -func verifyReviewedBackendAndWorkdir(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, plan *configurationPlan, path string) error { - if err := verifyConfigurationPlanState(ctx, config, info, plan); err != nil { - return err - } - return verifyConfigurationPlanWorkdir(plan, path) + return plan.Prepared, rebuild, nil } -// restoresConfigurationPlan reports whether the invocation applies the original, locally stored artifact. +// restoresConfigurationPlan reports whether the invocation applies a reviewed artifact. The downloaded +// stored plan that `deploy` verifies against is never applied itself, so it must not be the plan to apply. func restoresConfigurationPlan(info *schema.ConfigAndStacksInfo) bool { - return info.StoredPlanFile == "" && (info.SubCommand == "apply" || info.SubCommand == "deploy") + return (info.StoredPlanFile == "" || info.StoredPlanFile != info.PlanFile) && (info.SubCommand == "apply" || info.SubCommand == "deploy") } // loadConfigurationPlan reads the companion binding and checks it targets this component. @@ -184,16 +214,38 @@ func configurationArtifactMatches(config *schema.AtmosConfiguration, info *schem return digest == plan.PlanDigest && engine == plan.EngineDigest && workdir == plan.WorkingDirectory, nil } -// verifyConfigurationPlanWorkdir rejects a working directory whose retained bytes changed since review. -func verifyConfigurationPlanWorkdir(plan *configurationPlan, path string) error { - workingDigest, err := configurationWorkdirDigest(plan.WorkingDirectory, path) +// verifyReviewedArtifacts checks everything about a reviewed plan that does not depend on the working +// directory: provider identity and watched sources, plan bytes, engine, and backend. +func verifyReviewedArtifacts(ctx context.Context, config *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, plan *configurationPlan, path string) error { + runtime, err := planRuntime(config) if err != nil { return err } - if workingDigest != plan.WorkingDigest { - return fmt.Errorf("%w: reviewed working directory changed", errUtils.ErrPlanVerificationFailed) + identity, err := runtime.PlanIdentity(ctx, info, plan.Prepared.Sources) + if err != nil { + return err } - return nil + artifactMatches, err := configurationArtifactMatches(config, info, plan, path) + if err != nil { + return err + } + if identity != plan.Identity || !artifactMatches { + return fmt.Errorf("%w: plugin, source, engine, workdir, or reviewed artifact changed; create a new plan", errUtils.ErrPlanVerificationFailed) + } + return verifyConfigurationPlanState(ctx, config, info, plan) +} + +// workdirMatches reports whether the retained working directory still holds exactly the reviewed +// bytes. A directory that no longer exists simply does not match. +func workdirMatches(plan *configurationPlan, path string) (bool, error) { + workingDigest, err := configurationWorkdirDigest(plan.WorkingDirectory, path) + if errors.Is(err, fs.ErrNotExist) { + return false, nil + } + if err != nil { + return false, err + } + return workingDigest == plan.WorkingDigest, nil } // recordConfigurationPlan stores a private companion beside the completed plan. @@ -247,13 +299,22 @@ func newConfigurationPlan(info *schema.ConfigAndStacksInfo, execCtx *componentEx if err != nil { return nil, err } + rebuildDigest, err := configurationRebuildDigest(execCtx.workingDir, path, transientWorkdirFiles(info)) + if err != nil { + return nil, err + } + lock, err := lockFileDigest(execCtx.workingDir) + if err != nil { + return nil, err + } // Inputs and backend values stay out of the record; see configurationPlan. Sensitive generated // files, such as a backend file with credentials, keep only their place: apply reads their bytes - // back from the retained workdir, whose digest proves they are the reviewed ones. + // back from the retained workdir, whose digest proves they are the reviewed ones, and a rebuild + // writes them again from a fresh preparation that must match RebuildDigest. stored := *execCtx.preparedConfiguration stored.Inputs, stored.Backend = nil, nil stored.Files = withoutSensitiveContent(stored.Files) - return &configurationPlan{WorkingDigest: workingDigest, Version: configurationPlanVersion, Stack: info.Stack, Component: info.ComponentFromArg, Identity: identity, EngineDigest: engineDigest, PlanDigest: planDigest, WorkingDirectory: filepath.Clean(execCtx.workingDir), BackendDigest: backendDigest, Prepared: &stored}, nil + return &configurationPlan{WorkingDigest: workingDigest, Version: configurationPlanVersion, Stack: info.Stack, Component: info.ComponentFromArg, Identity: identity, EngineDigest: engineDigest, PlanDigest: planDigest, WorkingDirectory: filepath.Clean(execCtx.workingDir), BackendDigest: backendDigest, RebuildDigest: rebuildDigest, LockDigest: lock, Prepared: &stored}, nil } // withoutSensitiveContent copies files, dropping the bytes of every sensitive one. @@ -372,6 +433,12 @@ func verifyConfigurationPlanState(ctx context.Context, config *schema.AtmosConfi // configurationWorkdirDigest binds retained module/configuration bytes, excluding mutable execution data. func configurationWorkdirDigest(root, planPath string) (string, error) { + return workdirDigest(root, planPath, nil) +} + +// workdirDigest hashes the retained files below root, additionally skipping the top-level files +// that ignore selects by their slash-separated path relative to root. +func workdirDigest(root, planPath string, ignore func(relative string) bool) (string, error) { // An explicit plan path may be absolute while the directory is relative, or the reverse. // Both must compare equal, or the plan file itself would be hashed into the directory digest. root, planPath, err := absolutePaths(root, planPath) @@ -389,7 +456,7 @@ func configurationWorkdirDigest(root, planPath string) (string, error) { } return nil } - if ignoredWorkdirFile(path, planPath, entry.Name()) { + if ignoredWorkdirFile(path, planPath, entry.Name()) || ignoredRelative(root, path, ignore) { return nil } return recordWorkdirFile(root, path, entry, files) @@ -405,6 +472,15 @@ func configurationWorkdirDigest(root, planPath string) (string, error) { return hex.EncodeToString(digest[:]), nil } +// ignoredRelative applies a caller's filter to the slash-separated path relative to root. +func ignoredRelative(root, path string, ignore func(relative string) bool) bool { + if ignore == nil { + return false + } + relative, err := filepath.Rel(root, path) + return err == nil && ignore(filepath.ToSlash(relative)) +} + // absolutePaths returns both paths absolute and with symlinks resolved, so one file reached through // two spellings (for example /var and /private/var on macOS) compares equal. func absolutePaths(root, planPath string) (string, string, error) { @@ -437,9 +513,14 @@ func skipWorkdirDirectory(root, path, name string) bool { return path != root && (name == ".terraform" || name == ".git" || name == ".terragrunt-cache" || name == ".atmos") } -// ignoredWorkdirFile reports whether a file is the plan itself, its binding, or mutable state. +// ignoredWorkdirFile reports whether a file is a plan, its binding, or mutable state. Plan files are +// reviewed artifacts, not configuration: besides the plan itself that includes an earlier plan +// still lying in the directory, the stored plan `deploy` downloads for comparison, and the fresh +// plan it generates. func ignoredWorkdirFile(path, planPath, name string) bool { - return path == planPath || strings.HasSuffix(name, configurationPlanSuffix) || strings.HasPrefix(name, ".atmos-plan-") || strings.HasPrefix(name, "terraform.tfstate") + return path == planPath || strings.HasSuffix(name, configurationPlanSuffix) || strings.HasSuffix(name, ".planfile") || + name == ciplanfile.StoredPlanPrefix+ciplanfile.PlanFilename || name == freshPlanName || + strings.HasPrefix(name, ".atmos-plan-") || strings.HasPrefix(name, "terraform.tfstate") } // recordWorkdirFile digests one retained file by its slash-separated path relative to the root. diff --git a/pkg/component/terraform/configuration_plan_pipeline_test.go b/pkg/component/terraform/configuration_plan_pipeline_test.go index 95dfae2893c..72e9ec3ec4e 100644 --- a/pkg/component/terraform/configuration_plan_pipeline_test.go +++ b/pkg/component/terraform/configuration_plan_pipeline_test.go @@ -31,14 +31,16 @@ func (r reviewedPlanRuntime) ResolveState(context.Context, *schema.ConfigAndStac // reviewedPlanProject is an isolated workdir-enabled component whose module can change after review. type reviewedPlanProject struct { root, module, workdir, state string - config *schema.AtmosConfiguration - provider *MockComponentConfigurationRuntime + // explicitWorkdir pins the workdir with metadata.working_directory. Units use the default location. + explicitWorkdir bool + config *schema.AtmosConfiguration + provider *MockComponentConfigurationRuntime } func newReviewedPlanProject(t *testing.T) *reviewedPlanProject { t.Helper() root := t.TempDir() - project := &reviewedPlanProject{root: root, module: filepath.Join(root, "module"), workdir: filepath.Join(root, "chosen"), state: filepath.Join(root, "state", "terraform.tfstate")} + project := &reviewedPlanProject{root: root, module: filepath.Join(root, "module"), workdir: filepath.Join(root, "chosen"), state: filepath.Join(root, "state", "terraform.tfstate"), explicitWorkdir: true} require.NoError(t, os.MkdirAll(project.module, 0o755)) require.NoError(t, os.WriteFile(filepath.Join(project.module, "main.tf"), []byte("# reviewed module"), 0o644)) project.config = &schema.AtmosConfiguration{BasePath: root, BasePathAbsolute: root, TerraformDirAbsolutePath: filepath.Join(root, "components")} @@ -53,13 +55,17 @@ func (p *reviewedPlanProject) info(t *testing.T, subCommand string) *schema.Conf t.Helper() binary, err := os.Executable() require.NoError(t, err) + metadata := map[string]any{} + if p.explicitWorkdir { + metadata["working_directory"] = p.workdir + } return &schema.ConfigAndStacksInfo{ Stack: "dev", ComponentFromArg: "app", Component: "app", FinalComponent: "app", Command: binary, SubCommand: subCommand, ComponentSettingsSection: map[string]any{"configuration": true}, ComponentEnvSection: map[string]any{}, ComponentSection: map[string]any{ "component": "app", "atmos_component": "app", "atmos_stack": "dev", "source": map[string]any{"uri": p.module}, "provision": map[string]any{"workdir": map[string]any{"enabled": true}}, - "metadata": map[string]any{"working_directory": p.workdir}, + "metadata": metadata, }, } } @@ -82,6 +88,21 @@ func (p *reviewedPlanProject) review(t *testing.T) string { return planPath } +// reviewInDefaultWorkdir is review for a unit: the workdir is wherever provisioning places it. +func (p *reviewedPlanProject) reviewInDefaultWorkdir(t *testing.T) string { + t.Helper() + p.explicitWorkdir = false + info := p.info(t, "plan") + p.provider.EXPECT().Prepare(gomock.Any(), info).Return(p.prepared(), nil) + execution, err := testExecutor(t).prepareComponentExecution(t.Context(), provisioner.OutputWriters{}, p.config, info, false) + require.NoError(t, err) + p.workdir = execution.workingDir + planPath := filepath.Join(execution.workingDir, "reviewed.planfile") + require.NoError(t, os.WriteFile(planPath, []byte("reviewed plan"), 0o600)) + require.NoError(t, recordConfigurationPlan(t.Context(), p.config, info, execution, []string{"-out=" + planPath})) + return planPath +} + // reviewedApply returns an apply invocation of the reviewed plan, as a new process would build it: // nothing has been provisioned, so the retained workdir has to be located from configuration. func (p *reviewedPlanProject) reviewedApply(t *testing.T, planPath string) *schema.ConfigAndStacksInfo { @@ -174,3 +195,210 @@ func TestPrepareInitExecutionKeepsReviewedPlanWorkspace(t *testing.T) { }) } } + +// freshRunner models a new runner that checked out the same repository at the same path: nothing +// of the earlier run remains except the artifacts the CI plan store restored. It returns the plan +// file and its record bytes after wiping the workdir, then recreates the workdir with only the +// restored artifacts. +func (p *reviewedPlanProject) freshRunner(t *testing.T, planPath string, restore ...string) { + t.Helper() + artifacts := map[string][]byte{} + for _, name := range append([]string{planPath, planPath + configurationPlanSuffix}, restore...) { + data, err := os.ReadFile(name) + require.NoError(t, err) + artifacts[name] = data + } + require.NoError(t, os.RemoveAll(p.workdir)) + require.NoError(t, os.MkdirAll(p.workdir, 0o755)) + for name, data := range artifacts { + require.NoError(t, os.WriteFile(name, data, 0o600)) + } +} + +// freshApply prepares an apply of the restored plan; the provider must re-evaluate exactly once. +func (p *reviewedPlanProject) freshApply(t *testing.T, planPath string, prepared *schema.PreparedComponentConfiguration) (*schema.ConfigAndStacksInfo, *componentExecContext, error) { + t.Helper() + apply := p.reviewedApply(t, planPath) + cleared := *apply + cleared.UseTerraformPlan, cleared.PlanFile = false, "" + p.provider.EXPECT().Prepare(gomock.Any(), gomock.Cond(func(info *schema.ConfigAndStacksInfo) bool { + return !info.UseTerraformPlan && info.PlanFile == "" && info.SubCommand == "apply" + })).Return(prepared, nil).MaxTimes(1) + execution, err := testExecutor(t).prepareComponentExecution(t.Context(), provisioner.OutputWriters{}, p.config, apply, false) + return apply, execution, err +} + +func TestApplyOfRestoredPlanRebuildsWorkdirOnAFreshRunner(t *testing.T) { + project := newReviewedPlanProject(t) + planPath := project.reviewInDefaultWorkdir(t) + project.freshRunner(t, planPath) + + apply, execution, err := project.freshApply(t, planPath, project.prepared()) + require.NoError(t, err) + + require.Equal(t, project.workdir, execution.componentPath) + rebuilt, err := os.ReadFile(filepath.Join(project.workdir, "main.tf")) + require.NoError(t, err) + require.Equal(t, "# reviewed module", string(rebuilt), "the module is re-provisioned from the checkout") + plan, err := os.ReadFile(planPath) + require.NoError(t, err) + require.Equal(t, "reviewed plan", string(plan), "the restored plan is kept in place for apply") + require.FileExists(t, planPath+configurationPlanSuffix) + require.Empty(t, execution.preparedConfiguration.Inputs, "the plan file carries the inputs") + require.True(t, apply.UseTerraformPlan) + require.Equal(t, planPath, apply.PlanFile) +} + +func TestApplyOfRestoredPlanRejectsWhatCannotBeReproduced(t *testing.T) { + tests := []struct { + name string + want error + change func(t *testing.T, project *reviewedPlanProject, planPath string) + }{ + {"module source revision changed", errUtils.ErrPlanVerificationFailed, func(t *testing.T, project *reviewedPlanProject, _ string) { + require.NoError(t, os.WriteFile(filepath.Join(project.module, "main.tf"), []byte("# another revision"), 0o644)) + }}, + {"extra file in the module", errUtils.ErrPlanVerificationFailed, func(t *testing.T, project *reviewedPlanProject, _ string) { + require.NoError(t, os.WriteFile(filepath.Join(project.module, "extra.tf"), []byte("# added"), 0o644)) + }}, + {"plan bytes changed", errUtils.ErrPlanVerificationFailed, func(t *testing.T, _ *reviewedPlanProject, planPath string) { + require.NoError(t, os.WriteFile(planPath, []byte("unreviewed plan"), 0o600)) + }}, + {"binding missing", errUtils.ErrSavedPlanNotFound, func(t *testing.T, _ *reviewedPlanProject, planPath string) { + require.NoError(t, os.Remove(planPath+configurationPlanSuffix)) + }}, + {"workdir holds unverifiable content", errUtils.ErrPlanVerificationFailed, func(t *testing.T, project *reviewedPlanProject, _ string) { + require.NoError(t, os.WriteFile(filepath.Join(project.workdir, "main.tf"), []byte("# stale"), 0o644)) + }}, + {"lock file differs from the reviewed one", errUtils.ErrPlanVerificationFailed, func(t *testing.T, project *reviewedPlanProject, _ string) { + require.NoError(t, os.WriteFile(filepath.Join(project.workdir, ".terraform.lock.hcl"), []byte("# unreviewed providers"), 0o644)) + }}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + project := newReviewedPlanProject(t) + planPath := project.reviewInDefaultWorkdir(t) + project.freshRunner(t, planPath) + test.change(t, project, planPath) + + _, execution, err := project.freshApply(t, planPath, project.prepared()) + require.ErrorIs(t, err, test.want) + require.Nil(t, execution) + }) + } +} + +func TestApplyOfRestoredPlanVerifiesTheRestoredLockFile(t *testing.T) { + project := newReviewedPlanProject(t) + planPath := project.reviewInDefaultWorkdir(t) + lock := filepath.Join(project.workdir, ".terraform.lock.hcl") + require.NoError(t, os.WriteFile(lock, []byte("# reviewed providers"), 0o644)) + // The record is made after init has written the lock file, so re-record with it present. + info := project.info(t, "plan") + execution := &componentExecContext{preparedConfiguration: project.prepared(), componentPath: project.workdir, workingDir: project.workdir} + require.NoError(t, recordConfigurationPlan(t.Context(), project.config, info, execution, []string{"-out=" + planPath})) + project.freshRunner(t, planPath, lock) + + _, execution, err := project.freshApply(t, planPath, project.prepared()) + require.NoError(t, err) + restored, err := os.ReadFile(lock) + require.NoError(t, err) + require.Equal(t, "# reviewed providers", string(restored)) + require.NotNil(t, execution) +} + +func TestApplyOfRestoredPlanRejectsChangedBackendAndFailedPreparation(t *testing.T) { + project := newReviewedPlanProject(t) + planPath := project.reviewInDefaultWorkdir(t) + project.freshRunner(t, planPath) + + moved := project.prepared() + moved.Backend = map[string]any{"path": filepath.Join(project.root, "elsewhere")} + apply := project.reviewedApply(t, planPath) + project.provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).Return(moved, nil) + _, err := testExecutor(t).prepareComponentExecution(t.Context(), provisioner.OutputWriters{}, project.config, apply, false) + require.ErrorIs(t, err, errUtils.ErrPlanVerificationFailed, "a backend other than the reviewed one must not apply the plan") + + project.freshRunner(t, planPath) + failing := project.reviewedApply(t, planPath) + project.provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).Return(nil, context.Canceled) + _, err = testExecutor(t).prepareComponentExecution(t.Context(), provisioner.OutputWriters{}, project.config, failing, false) + require.ErrorIs(t, err, context.Canceled) +} + +func TestStoredPlanIsAComparisonReferenceNotAPlanToApply(t *testing.T) { + project := newReviewedPlanProject(t) + deploy := project.info(t, "deploy") + deploy.StoredPlanFile = filepath.Join(project.workdir, "stored.plan.tfplan") + require.False(t, usesConfigurationPlan(deploy), "a downloaded plan used for drift verification must not trigger a saved-plan restore") + project.provider.EXPECT().Prepare(gomock.Any(), deploy).Return(project.prepared(), nil) + prepared, err := prepareConfiguration(t.Context(), project.config, deploy) + require.NoError(t, err) + require.NotEmpty(t, prepared.Inputs, "an ordinary preparation evaluates the unit again") +} + +func TestReviewedRebuildAcceptsOnlyTheRestoredArtifacts(t *testing.T) { + dir := t.TempDir() + workdir := filepath.Join(dir, "work") + planPath := filepath.Join(workdir, "reviewed.planfile") + rebuild := &reviewedRebuild{plan: &configurationPlan{}, planPath: planPath, workdir: workdir} + + only, err := rebuild.holdsOnlyTransport() + require.NoError(t, err) + require.True(t, only, "a workdir that does not exist yet holds nothing unverifiable") + + require.NoError(t, os.MkdirAll(workdir, 0o755)) + for _, name := range []string{"reviewed.planfile", "reviewed.planfile" + configurationPlanSuffix, terraformLockFile} { + require.NoError(t, os.WriteFile(filepath.Join(workdir, name), []byte(name), 0o600)) + } + only, err = rebuild.holdsOnlyTransport() + require.NoError(t, err) + require.True(t, only) + + require.NoError(t, os.WriteFile(filepath.Join(workdir, "other.planfile"), nil, 0o600)) + only, err = rebuild.holdsOnlyTransport() + require.NoError(t, err) + require.False(t, only, "another plan file is not part of the restored artifact set") + + // A plan kept outside the workdir does not excuse files inside it. + external := &reviewedRebuild{plan: &configurationPlan{}, planPath: filepath.Join(dir, "elsewhere.planfile"), workdir: workdir} + only, err = external.holdsOnlyTransport() + require.NoError(t, err) + require.False(t, only) +} + +func TestReviewedRebuildStagesAndReturnsTheArtifacts(t *testing.T) { + workdir := filepath.Join(t.TempDir(), "work") + rebuild := &reviewedRebuild{plan: &configurationPlan{}, planPath: filepath.Join(workdir, "reviewed.planfile"), workdir: workdir} + + restore, err := rebuild.stage() + require.NoError(t, err) + require.NoError(t, restore(), "staging a workdir that does not exist is a no-op") + + require.NoError(t, os.MkdirAll(workdir, 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(workdir, "reviewed.planfile"), []byte("plan"), 0o600)) + require.NoError(t, os.WriteFile(filepath.Join(workdir, terraformLockFile), []byte("restored lock"), 0o600)) + restore, err = rebuild.stage() + require.NoError(t, err) + require.NoDirExists(t, workdir, "provisioning gets an empty place") + + // Provisioning writes a lock file of its own; the restored one wins. + require.NoError(t, os.MkdirAll(workdir, 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(workdir, terraformLockFile), []byte("copied lock"), 0o600)) + require.NoError(t, restore()) + plan, err := os.ReadFile(filepath.Join(workdir, "reviewed.planfile")) + require.NoError(t, err) + require.Equal(t, "plan", string(plan)) + lock, err := os.ReadFile(filepath.Join(workdir, terraformLockFile)) + require.NoError(t, err) + require.Equal(t, "restored lock", string(lock)) + holding, err := filepath.Glob(filepath.Join(filepath.Dir(workdir), ".atmos-restore-*")) + require.NoError(t, err) + require.Empty(t, holding, "the holding directory is removed") +} + +func TestNewReviewedRebuildRequiresAnOldEnoughRecord(t *testing.T) { + info := &schema.ConfigAndStacksInfo{Stack: "dev", ComponentFromArg: "app", ComponentSettingsSection: map[string]any{"configuration": true}} + _, err := newReviewedRebuild(info, &configurationPlan{WorkingDirectory: t.TempDir()}, "plan") + require.ErrorIs(t, err, errUtils.ErrPlanVerificationFailed, "a record without a rebuild digest cannot prove a rebuilt workdir") +} diff --git a/pkg/component/terraform/configuration_plan_test.go b/pkg/component/terraform/configuration_plan_test.go index d8cce0da94c..cb73243d6ed 100644 --- a/pkg/component/terraform/configuration_plan_test.go +++ b/pkg/component/terraform/configuration_plan_test.go @@ -383,3 +383,50 @@ func TestConfigurationWorkdirDigestIgnoresPlanReachedThroughSymlink(t *testing.T require.NoError(t, err) require.Equal(t, direct, viaLink) } + +func TestConfigurationWorkdirDigestIgnoresPlanArtifacts(t *testing.T) { + dir := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(dir, "main.tf"), []byte("module"), 0o600)) + baseline, err := configurationWorkdirDigest(dir, filepath.Join(dir, "reviewed.planfile")) + require.NoError(t, err) + + // Plans are reviewed artifacts, not configuration: an earlier plan, the stored plan that deploy + // downloads, and the fresh plan it generates must not make the directory look edited. + for _, name := range []string{"earlier.planfile", "stored.plan.tfplan", "new.plan"} { + require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("plan "+name), 0o600)) + } + withPlans, err := configurationWorkdirDigest(dir, filepath.Join(dir, "reviewed.planfile")) + require.NoError(t, err) + require.Equal(t, baseline, withPlans) + + require.NoError(t, os.WriteFile(filepath.Join(dir, "extra.tf"), []byte("added"), 0o600)) + edited, err := configurationWorkdirDigest(dir, filepath.Join(dir, "reviewed.planfile")) + require.NoError(t, err) + require.NotEqual(t, baseline, edited) +} + +func TestDropCIPlanLocationKeepsEveryPlanTheUserNamed(t *testing.T) { + tests := []struct { + name string + info schema.ConfigAndStacksInfo + wantPlan string + }{ + {"hook recorded the location while downloading a stored plan", schema.ConfigAndStacksInfo{PlanFile: "w/plan", StoredPlanFile: "w/stored"}, ""}, + {"a plan the user named", schema.ConfigAndStacksInfo{PlanFile: "w/plan", UseTerraformPlan: true, StoredPlanFile: "w/stored"}, "w/plan"}, + {"a plan named without any stored plan", schema.ConfigAndStacksInfo{PlanFile: "w/plan"}, "w/plan"}, + {"nothing named", schema.ConfigAndStacksInfo{}, ""}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + dropCIPlanLocation(&test.info) + require.Equal(t, test.wantPlan, test.info.PlanFile) + }) + } +} + +func TestRestoreRefusesToApplyTheStoredPlanItself(t *testing.T) { + info := &schema.ConfigAndStacksInfo{SubCommand: "deploy", PlanFile: "w/stored", StoredPlanFile: "w/stored"} + require.False(t, restoresConfigurationPlan(info), "the plan deploy compares against is never what gets applied") + info.PlanFile = "w/new.plan" + require.True(t, restoresConfigurationPlan(info), "the fresh plan that matched it is") +} diff --git a/pkg/component/terraform/configuration_restore.go b/pkg/component/terraform/configuration_restore.go new file mode 100644 index 00000000000..f80cfae4ab5 --- /dev/null +++ b/pkg/component/terraform/configuration_restore.go @@ -0,0 +1,233 @@ +package terraform + +import ( + "context" + "errors" + "fmt" + "io/fs" + "os" + "path/filepath" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/component/configuration" + "github.com/cloudposse/atmos/pkg/provisioner" + "github.com/cloudposse/atmos/pkg/schema" +) + +// terraformLockFile is the provider lock file. It travels with the plan because Terraform checks the +// plan's provider selections against it, so a different lock can change which providers apply. +const terraformLockFile = ".terraform.lock.hcl" + +// workdirMode is the permission of a re-created working directory. +const workdirMode = 0o755 + +// reviewedRebuild describes a reviewed plan that reached a runner without its working directory: +// the plan and its record were restored (for example from the planfile store into a fresh checkout) +// but nothing else of the original run was. The workdir is re-provisioned from the checkout and must +// then equal what was reviewed. +// +// What is verified before anything is rebuilt: the record's stack and component, the plan bytes, the +// engine binary, the provider identity with its options and watched source files, and the backend. +// What is rebuilt, never trusted: the working directory. The module source is provisioned again from +// the checkout and the generated files are written again from a fresh preparation, then the result +// must match RebuildDigest (and the lock file LockDigest) from the record. Any mismatch rejects the plan. +type reviewedRebuild struct { + plan *configurationPlan + planPath string + workdir string + transient []string + // prepared is the fresh preparation the workdir is regenerated from. + prepared *schema.PreparedComponentConfiguration +} + +// newReviewedRebuild accepts a workdir that is absent or holds only the restored artifacts, and +// rejects anything else: files that are not part of the transport cannot be verified. +func newReviewedRebuild(info *schema.ConfigAndStacksInfo, plan *configurationPlan, planPath string) (*reviewedRebuild, error) { + rebuild := &reviewedRebuild{plan: plan, planPath: planPath, workdir: plan.WorkingDirectory, transient: transientWorkdirFiles(info)} + if plan.RebuildDigest == "" { + return nil, fmt.Errorf("%w: reviewed working directory changed", errUtils.ErrPlanVerificationFailed) + } + only, err := rebuild.holdsOnlyTransport() + if err != nil { + return nil, err + } + if !only { + return nil, errUtils.Build(fmt.Errorf("%w: reviewed working directory changed", errUtils.ErrPlanVerificationFailed)). + WithExplanationf("The working directory `%s` holds files that were not part of the reviewed plan, so it cannot be verified.", plan.WorkingDirectory). + WithHint("Remove the directory and restore only the plan, its record, and the lock file, or apply on the runner that created the plan."). + Err() + } + return rebuild, nil +} + +// transientWorkdirFiles names the files each execution rewrites from its inputs. They carry values +// the plan file already embodies, so they are not part of what a rebuild must reproduce. +func transientWorkdirFiles(info *schema.ConfigAndStacksInfo) []string { + var names []string + for _, suffix := range []string{".terraform.tfvars.json", ".terraform.test.tfvars.json"} { + if name, ok := configurationArtifactName(info, suffix); ok { + names = append(names, name) + } + } + return names +} + +// configurationRebuildDigest hashes the files a rebuild regenerates: the retained directory without +// the plan, its record, state, variable files, and the lock file (which has its own digest). +func configurationRebuildDigest(root, planPath string, transient []string) (string, error) { + return workdirDigest(root, planPath, func(relative string) bool { + if relative == terraformLockFile { + return true + } + for _, name := range transient { + if relative == name { + return true + } + } + return false + }) +} + +// lockFileDigest returns the digest of the provider lock file beside the plan, or "" when there is none. +func lockFileDigest(dir string) (string, error) { + digest, err := fileDigest(filepath.Join(dir, terraformLockFile)) + if errors.Is(err, fs.ErrNotExist) { + return "", nil + } + return digest, err +} + +// transportFiles lists the restored artifacts that may sit in the workdir: the plan, its record, and the lock file. +func (r *reviewedRebuild) transportFiles() map[string]bool { + files := map[string]bool{terraformLockFile: true} + if sameDirectory(filepath.Dir(r.planPath), r.workdir) { + files[filepath.Base(r.planPath)] = true + files[filepath.Base(r.planPath)+configurationPlanSuffix] = true + } + return files +} + +func sameDirectory(first, second string) bool { + a, errA := resolvedPath(first) + b, errB := resolvedPath(second) + return errA == nil && errB == nil && a == b +} + +// holdsOnlyTransport reports whether the workdir is absent, empty, or contains just the restored artifacts. +func (r *reviewedRebuild) holdsOnlyTransport() (bool, error) { + entries, err := os.ReadDir(r.workdir) + if errors.Is(err, fs.ErrNotExist) { + return true, nil + } + if err != nil { + return false, err + } + allowed := r.transportFiles() + for _, entry := range entries { + if entry.IsDir() || !allowed[entry.Name()] { + return false, nil + } + } + return true, nil +} + +// stage moves the restored artifacts aside so the workdir can be provisioned into an empty place, and +// returns the function that puts them back. Provisioning refuses a directory it does not own. +func (r *reviewedRebuild) stage() (func() error, error) { + entries, err := os.ReadDir(r.workdir) + if errors.Is(err, fs.ErrNotExist) || len(entries) == 0 { + return func() error { return nil }, nil + } + if err != nil { + return nil, err + } + holding, err := os.MkdirTemp(filepath.Dir(r.workdir), ".atmos-restore-*") + if err != nil { + return nil, err + } + names := make([]string, 0, len(entries)) + for _, entry := range entries { + if err := os.Rename(filepath.Join(r.workdir, entry.Name()), filepath.Join(holding, entry.Name())); err != nil { + return nil, errors.Join(err, putBack(holding, r.workdir, names)) + } + names = append(names, entry.Name()) + } + if err := os.Remove(r.workdir); err != nil { + return nil, errors.Join(err, putBack(holding, r.workdir, names)) + } + return func() error { return putBack(holding, r.workdir, names) }, nil +} + +// putBack returns staged artifacts to the workdir, replacing what provisioning wrote under the same +// name, and removes the holding directory. +func putBack(holding, workdir string, names []string) error { + if err := os.MkdirAll(workdir, workdirMode); err != nil { + return err + } + for _, name := range names { + destination := filepath.Join(workdir, name) + if err := os.Remove(destination); err != nil && !errors.Is(err, fs.ErrNotExist) { + return err + } + if err := os.Rename(filepath.Join(holding, name), destination); err != nil { + return err + } + } + return os.Remove(holding) +} + +// verify compares the re-provisioned directory to the reviewed one. +func (r *reviewedRebuild) verify(workdir string) error { + digest, err := configurationRebuildDigest(workdir, r.planPath, r.transient) + if err != nil { + return err + } + if digest != r.plan.RebuildDigest { + return errUtils.Build(fmt.Errorf("%w: the re-provisioned working directory differs from the reviewed one", errUtils.ErrPlanVerificationFailed)). + WithExplanation("The module source or generated files in this checkout do not reproduce what was reviewed (a different module revision, a floating source reference, or a different checkout path)."). + WithHint("Create a new plan from this revision with `atmos terraform plan`."). + Err() + } + lock, err := lockFileDigest(workdir) + if err != nil { + return err + } + if lock != r.plan.LockDigest { + return errUtils.Build(fmt.Errorf("%w: the provider lock file differs from the reviewed one", errUtils.ErrPlanVerificationFailed)). + WithHint("Restore `.terraform.lock.hcl` together with the plan (`atmos terraform planfile download` does), or create a new plan."). + Err() + } + return nil +} + +// rebuildReviewedWorkdir re-provisions the working directory of a reviewed plan on a runner that only +// holds the restored artifacts. The caller verifies the result once execution has written its own +// files (generated backend configuration), before anything runs. +func (e *Executor) rebuildReviewedWorkdir(ctx context.Context, writers provisioner.OutputWriters, atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, rebuild *reviewedRebuild) (path string, err error) { + restore, err := rebuild.stage() + if err != nil { + return "", err + } + defer func() { + // The restored artifacts return in every case so the user can inspect or retry. + if restoreErr := restore(); restoreErr != nil { + err = errors.Join(err, restoreErr) + } + }() + path, err = e.resolveAndProvisionComponentPath(ctx, writers, atmosConfig, info) + if err != nil { + return "", err + } + if !sameDirectory(path, rebuild.workdir) { + return "", fmt.Errorf("%w: the working directory resolved to %s instead of the reviewed %s", errUtils.ErrPlanVerificationFailed, path, rebuild.workdir) + } + if err = configuration.WriteFiles(path, rebuild.prepared.Files); err != nil { + return "", err + } + // The artifacts go back before verification: a restored lock file replaces any copied from beside the unit. + if err = restore(); err != nil { + return "", err + } + restore = func() error { return nil } + return path, nil +} diff --git a/pkg/component/terraform/configuration_toolchain_test.go b/pkg/component/terraform/configuration_toolchain_test.go index d77bbb0f0b6..a1d3612e82f 100644 --- a/pkg/component/terraform/configuration_toolchain_test.go +++ b/pkg/component/terraform/configuration_toolchain_test.go @@ -4,9 +4,11 @@ import ( "bytes" "context" "encoding/json" + "fmt" "os" "path/filepath" "runtime" + "strconv" "strings" "sync" "testing" @@ -27,6 +29,9 @@ import ( // arguments, and environment of every Terraform subprocess without any Unix-only binary. const testEnvToolchainProbe = "_ATMOS_TEST_TOOLCHAIN_PROBE" +// testEnvProbeExit makes a toolchain probe exit with that code after it recorded a command other than --version. +const testEnvProbeExit = "_ATMOS_TEST_PROBE_EXIT" + // toolchainProbe is one recorded subprocess invocation. type toolchainProbe struct { Executable string `json:"executable"` @@ -38,6 +43,10 @@ type toolchainProbe struct { Token string `json:"token"` Ambient string `json:"ambient"` Identity string `json:"identity"` + // Terragrunt executable mode: the TG_* variables Atmos sets for the unit. + NonInteractive string `json:"non_interactive"` + TFPath string `json:"tf_path"` + WebIdentity string `json:"web_identity"` } func runToolchainProbeForTest(path string) int { @@ -47,6 +56,7 @@ func runToolchainProbeForTest(path string) int { Executable: executable, Directory: directory, Arguments: os.Args[1:], Path: os.Getenv("PATH"), Profile: os.Getenv("AWS_PROFILE"), Custom: os.Getenv("CUSTOM_VALUE"), Token: os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE"), Ambient: os.Getenv("ATMOS_TOOLCHAIN_AMBIENT_ONLY"), Identity: os.Getenv("ATMOS_IDENTITY"), + NonInteractive: os.Getenv("TG_NON_INTERACTIVE"), TFPath: os.Getenv("TG_TF_PATH"), WebIdentity: os.Getenv("TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN"), } file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600) if err != nil { @@ -56,6 +66,14 @@ func runToolchainProbeForTest(path string) int { if err := json.NewEncoder(file).Encode(probe); err != nil { return 1 } + // Acting as terragrunt, the probe reports a version and can be told to fail the command. + if len(os.Args) == 2 && os.Args[1] == "--version" { + fmt.Println("terragrunt version v1.2.1") + return 0 + } + if code, err := strconv.Atoi(os.Getenv(testEnvProbeExit)); err == nil { + return code + } return 0 } @@ -519,3 +537,96 @@ func TestConfigurationToolchainPreservesIdentityPath(t *testing.T) { require.Less(t, indexOf(entries, filepath.Dir(harness.tools["tofu@1.0.0"])), indexOf(entries, identityBin), name) } } + +// unitHarness prepares a toolchain harness whose pinned terragrunt is the test binary, plus the unit +// directory executable mode runs in. +func unitHarness(t *testing.T) (*toolchainHarness, *schema.ConfigAndStacksInfo, string) { + t.Helper() + harness := newToolchainHarness(t, "1.0.0") + harness.config.Toolchain.Aliases["terragrunt"] = "gruntwork-io/terragrunt" + pinned := installToolchainFixture(t, harness.config.Toolchain.InstallPath, "gruntwork-io", "terragrunt", "1.2.1", "terragrunt") + unit := filepath.Join(harness.config.BasePathAbsolute, "live", "dev", "app") + require.NoError(t, os.MkdirAll(unit, 0o755)) + probe := filepath.Join(t.TempDir(), "probe.jsonl") + info := harness.info(t, &toolchainScenario{identity: "development", tofuVersion: "1.0.0", toolVersion: "1.0.0"}, probe) + info.ComponentSettingsSection = map[string]any{"configuration": map[string]any{"engine": "terragrunt", "provider": "terragrunt", "source": "live/dev/app/terragrunt.hcl"}} + info.AdditionalArgsAndFlags = []string{"-no-color"} + tools, _ := info.ComponentSection["dependencies"].(map[string]any)["tools"].(map[string]any) + tools["terragrunt"] = "1.2.1" + return harness, info, pinned +} + +// Executable mode runs the pinned terragrunt in the unit directory, with the identity and toolchain Atmos +// resolved, and never touches native preparation. +func TestExecuteTerragruntUnitRunsThePinnedExecutableInTheUnit(t *testing.T) { + harness, info, pinned := unitHarness(t) + probePath := info.ComponentEnvSection[testEnvToolchainProbe].(string) + info.ComponentProviderOptions = map[string]map[string]schema.ComponentProviderOption{"terragrunt": { + "feature": {Value: map[string]any{"alpha": "true"}}, + "iam_assume_role_web_identity_token": {Value: "token-value", Sensitive: true}, + }} + harness.config.Components.Terraform.ConfigurationProviders = map[string]schema.ComponentConfiguration{ + "terragrunt": {Enabled: true, Mode: "executable", Options: map[string]any{"features": map[string]any{"beta": "from-config"}}}, + } + + require.NoError(t, harness.executor.executeTerragruntUnit(t.Context(), harness.config, info, true)) + + probes := readToolchainProbes(t, probePath) + require.Len(t, probes, 2, "one version probe and one unit command") + require.Equal(t, []string{"--version"}, probes[0].Arguments) + run := probes[1] + unit := filepath.Join(harness.config.BasePathAbsolute, "live", "dev", "app") + require.Equal(t, physical(t, pinned), physical(t, run.Executable), "the toolchain-pinned terragrunt runs, not the ambient PATH") + require.Equal(t, physical(t, unit), physical(t, run.Directory)) + require.Equal(t, []string{"--working-dir", unit, "run", "--feature", "alpha=true", "--feature", "beta=from-config", "--", "plan", "-no-color"}, run.Arguments) + require.Equal(t, "true", run.NonInteractive) + require.Equal(t, harness.tools["tofu@1.0.0"], run.TFPath, "terragrunt runs the engine Atmos selected") + require.Equal(t, "development", run.Profile, "the Atmos identity reaches the unit") + require.Equal(t, "token-value", run.WebIdentity) + for _, argument := range run.Arguments { + require.NotContains(t, argument, "token-value", "a sensitive option never appears in argv") + } + require.Equal(t, []string{"authenticate", "toolchain"}, harness.events, "native preparation never starts") +} + +func TestExecuteTerragruntUnitPropagatesTheUnitExitCode(t *testing.T) { + harness, info, _ := unitHarness(t) + info.ComponentEnvSection[testEnvProbeExit] = "3" + err := harness.executor.executeTerragruntUnit(t.Context(), harness.config, info, true) + var exit errUtils.ExitCodeError + require.ErrorAs(t, err, &exit) + require.Equal(t, 3, exit.Code) +} + +func TestExecuteTerragruntUnitRejectsWhatItCannotHonorBeforeRunning(t *testing.T) { + harness, info, _ := unitHarness(t) + probePath := info.ComponentEnvSection[testEnvToolchainProbe].(string) + info.ComponentVarsSection = map[string]any{"region": "us-east-1"} + require.ErrorIs(t, harness.executor.executeTerragruntUnit(t.Context(), harness.config, info, true), errUtils.ErrExecutableModeUnsupported) + require.Empty(t, readToolchainProbes(t, probePath), "nothing ran") +} + +func TestExecuteTerragruntUnitExplainsAMissingExecutable(t *testing.T) { + harness, info, _ := unitHarness(t) + delete(info.ComponentSection["dependencies"].(map[string]any)["tools"].(map[string]any), "terragrunt") + err := harness.executor.executeTerragruntUnit(t.Context(), harness.config, info, true) + require.ErrorIs(t, err, errUtils.ErrExecutableNotFound) +} + +func TestExecuteTerragruntUnitDryRunRunsNothing(t *testing.T) { + harness, info, _ := unitHarness(t) + probePath := info.ComponentEnvSection[testEnvToolchainProbe].(string) + info.DryRun = true + require.NoError(t, harness.executor.executeTerragruntUnit(t.Context(), harness.config, info, true)) + require.Empty(t, readToolchainProbes(t, probePath)) +} + +func TestProviderSectionFollowsTheProviderName(t *testing.T) { + config := &schema.AtmosConfiguration{} + config.Components.Terraform.ConfigurationProviders = map[string]schema.ComponentConfiguration{ + "tg": {Enabled: true, Provider: "terragrunt"}, + "other": {Enabled: false, Provider: "terragrunt"}, + } + require.Equal(t, "tg", providerSection(config, "terragrunt")) + require.Equal(t, "unknown", providerSection(config, "unknown")) +} diff --git a/pkg/component/terraform/execute.go b/pkg/component/terraform/execute.go index 47286c20105..98df74ec169 100644 --- a/pkg/component/terraform/execute.go +++ b/pkg/component/terraform/execute.go @@ -13,6 +13,7 @@ import ( errUtils "github.com/cloudposse/atmos/errors" "github.com/cloudposse/atmos/pkg/auth/broker" "github.com/cloudposse/atmos/pkg/component" + "github.com/cloudposse/atmos/pkg/component/terragruntexec" cfg "github.com/cloudposse/atmos/pkg/config" "github.com/cloudposse/atmos/pkg/dependencies" log "github.com/cloudposse/atmos/pkg/logger" @@ -208,6 +209,11 @@ func (e *Executor) execute(info schema.ConfigAndStacksInfo, opts ...component.Ex // which creates the file, so it is also removed when a later preparation step fails. defer cleanupTerraformRC(&info) + // Executable mode runs the unit through the pinned terragrunt executable instead of native adaptation. + if terragruntexec.Owns(&info) { + return e.executeTerragruntUnit(component.ContextFromOptions(opts...), &atmosConfig, &info, shouldProcess, opts...) + } + // Resolve paths, install toolchain, write varfiles, validate, run hooks, and build env. execCtx, err := e.prepareComponentExecution(component.ContextFromOptions(opts...), executionOutputWriters(opts...), &atmosConfig, &info, shouldProcess) if errors.Is(err, errUtils.ErrComponentExcluded) || errors.Is(err, errUtils.ErrComponentRunIgnored) { diff --git a/pkg/component/terraform/execute_pipeline.go b/pkg/component/terraform/execute_pipeline.go index 064b931632d..4de1c5bd204 100644 --- a/pkg/component/terraform/execute_pipeline.go +++ b/pkg/component/terraform/execute_pipeline.go @@ -34,6 +34,8 @@ type componentExecContext struct { workingDir string tenv *dependencies.ToolchainEnvironment planPolicy *planfile.Guard + // rebuild is set when the working directory was re-provisioned for a restored plan; it is verified before any command runs. + rebuild *reviewedRebuild } // prepareComponentExecution consolidates all per-component setup into one call: @@ -55,7 +57,7 @@ func (e *Executor) prepareComponentExecution( if err != nil { return nil, err } - prepared, err := prepareConfiguration(ctx, atmosConfig, info) + prepared, rebuild, err := prepareConfigurationForExecution(ctx, atmosConfig, info) if err != nil { return nil, err } @@ -69,10 +71,17 @@ func (e *Executor) prepareComponentExecution( } var componentPath string - if prepared != nil && usesConfigurationPlan(info) { + switch { + case rebuild != nil: + // The plan was restored without its workdir: provision it again and prove it equals the reviewed one. + componentPath, err = e.rebuildReviewedWorkdir(ctx, writers, atmosConfig, info, rebuild) + if err != nil { + return nil, err + } + case prepared != nil && usesConfigurationPlan(info): // A reviewed plan uses the retained workdir; provisioning could replace its modules. componentPath = ConstructTerraformComponentWorkingDir(atmosConfig, info) - } else { + default: componentPath, err = e.resolveAndProvisionComponentPath(ctx, writers, atmosConfig, info) if err != nil { return nil, err @@ -108,6 +117,12 @@ func (e *Executor) prepareComponentExecution( if err = e.runPreExecutionSteps(atmosConfig, info, workingDir, tenv); err != nil { return nil, err } + // Execution has now written its own files, so the directory is complete and must equal the reviewed one. + if rebuild != nil { + if err = rebuild.verify(workingDir); err != nil { + return nil, err + } + } return &componentExecContext{ preparedConfiguration: prepared, @@ -117,6 +132,7 @@ func (e *Executor) prepareComponentExecution( planFile: planFile, workingDir: workingDir, tenv: tenv, + rebuild: rebuild, }, nil } diff --git a/pkg/component/terraform/execute_terragrunt.go b/pkg/component/terraform/execute_terragrunt.go new file mode 100644 index 00000000000..9ae97d4d092 --- /dev/null +++ b/pkg/component/terraform/execute_terragrunt.go @@ -0,0 +1,105 @@ +package terraform + +import ( + "context" + "os" + "os/exec" + "strings" + + "github.com/cloudposse/atmos/pkg/component" + "github.com/cloudposse/atmos/pkg/component/terragruntexec" + "github.com/cloudposse/atmos/pkg/perf" + "github.com/cloudposse/atmos/pkg/schema" + tfoutput "github.com/cloudposse/atmos/pkg/terraform/output" +) + +// terragruntTool is the tool name resolved through the toolchain; tests replace it with a test executable. +var terragruntTool = terragruntexec.Binary + +// terragruntHost runs terragrunt commands through the Atmos shell layer, so output is streamed through +// the UI, secrets are masked, interrupts are forwarded, and exit codes survive. +type terragruntHost struct { + executor *Executor + atmosConfig *schema.AtmosConfiguration + info *schema.ConfigAndStacksInfo + opts []component.ExecutionOption +} + +// Version asks the executable for its version in the same environment the unit will run in. +func (h *terragruntHost) Version(ctx context.Context, binary string, env []string) (string, error) { + defer perf.Track(h.atmosConfig, "terraform.terragruntHost.Version")() + + command := exec.CommandContext(ctx, binary, "--version") + base := h.info.SanitizedEnv + if base == nil { + base = os.Environ() + } + command.Env = append(append([]string{}, base...), env...) + output, err := command.CombinedOutput() + return strings.TrimSpace(string(output)), err +} + +// Execute runs one terragrunt command to completion. +func (h *terragruntHost) Execute(_ context.Context, command *terragruntexec.Command) error { + defer perf.Track(h.atmosConfig, "terraform.terragruntHost.Execute")() + + opts := append([]component.ExecutionOption{}, h.opts...) + opts = append(opts, component.WithEnvironment(h.info.SanitizedEnv)) + return h.executor.services.ExecuteShellCommand(*h.atmosConfig, command.Binary, command.Args, command.WorkingDir, command.Env, command.DryRun, h.info.RedirectStdErr, opts...) +} + +// executeTerragruntUnit runs a unit in executable mode: one pinned `terragrunt` command in the unit +// directory, with the authentication, toolchain, and environment Atmos resolved for the component. +// Native preparation, generated files, varfiles, and backend files do not apply; Terragrunt owns +// hooks, error handling, excludes, and IAM roles here. +func (e *Executor) executeTerragruntUnit(ctx context.Context, atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, shouldProcess bool, opts ...component.ExecutionOption) error { + if err := terragruntexec.CheckSupported(info); err != nil { + return err + } + if err := checkComponentRestrictions(info); err != nil { + return err + } + tenv, err := e.prepareConfigurationEnvironment(ctx, atmosConfig, info, shouldProcess) + if err != nil { + return err + } + binary := terragruntTool + if tenv != nil { + binary = tenv.Resolve(binary) + } + configuration, _ := info.ComponentSettingsSection["configuration"].(map[string]any) + unit, _ := configuration["source"].(string) + provider, _ := configuration["provider"].(string) + section := providerSection(atmosConfig, provider) + features, _ := atmosConfig.Components.Terraform.ConfigurationProviders[section].Options["features"].(map[string]any) + request := &terragruntexec.Request{ + Component: info.ComponentFromArg, Stack: info.Stack, Binary: binary, Engine: info.Command, + Unit: unit, Root: atmosConfig.BasePathAbsolute, SubCommand: info.SubCommand, SubCommand2: info.SubCommand2, + Arguments: info.AdditionalArgsAndFlags, Options: info.ComponentProviderOptions[section], Features: features, + Environment: info.ComponentEnvList, DryRun: info.DryRun, SkipInit: info.SkipInit, + } + err = terragruntexec.Run(ctx, &terragruntHost{executor: e, atmosConfig: atmosConfig, info: info, opts: opts}, request) + info.ExecMetadataRawExitCode = resolveExitCode(err) + if err = e.finishMainTerraformCommand(atmosConfig, info, err, false); err != nil { + return err + } + if !info.DryRun { + invalidateTerraformStateCache(info.Stack, info.ComponentFromArg) + tfoutput.InvalidateComponentOutputs(info.Stack, info.ComponentFromArg) + } + return nil +} + +// providerSection returns the key under `components.terraform` that enabled the provider. +func providerSection(atmosConfig *schema.AtmosConfiguration, provider string) string { + for section, settings := range atmosConfig.Components.Terraform.ConfigurationProviders { + name := section + if settings.Provider != "" { + name = settings.Provider + } + if settings.Enabled && name == provider { + return section + } + } + return provider +} diff --git a/pkg/component/terraform/plan_diff_preparation.go b/pkg/component/terraform/plan_diff_preparation.go index 9823e606a33..fe46eb809ab 100644 --- a/pkg/component/terraform/plan_diff_preparation.go +++ b/pkg/component/terraform/plan_diff_preparation.go @@ -65,11 +65,17 @@ func FilterPlanDiffFlags(args []string) []string { func (s *Operations) GenerateNewPlanFile(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, componentPath string, tmpDir string) (string, error) { defer perf.Track(atmosConfig, "terraform.Operations.GenerateNewPlanFile")() + // Terraform runs inside the component directory, so a relative directory (a workdir below a + // relative base path) would not resolve to the same place there. + absoluteDir, err := filepath.Abs(tmpDir) + if err != nil { + return "", err + } // Create a temporary file for the new plan - newPlanFile := filepath.Join(tmpDir, "new.plan") + newPlanFile := filepath.Join(absoluteDir, freshPlanName) // Run terraform init before plan - if err := s.runTerraformInit(atmosConfig, componentPath, info); err != nil { + if err = s.runTerraformInit(atmosConfig, componentPath, info); err != nil { return "", err } @@ -91,7 +97,7 @@ func (s *Operations) GenerateNewPlanFile(atmosConfig *schema.AtmosConfiguration, planInfo.AdditionalArgsAndFlags = planArgs // Execute the plan command using the standard Atmos terraform execution - err := s.host.ExecuteTerraform(planInfo) + err = s.host.ExecuteTerraform(planInfo) if err != nil { // If the error is ErrPlanHasDiff, we want to propagate that error if errors.Is(err, errUtils.ErrPlanHasDiff) { diff --git a/pkg/component/terraform/shell.go b/pkg/component/terraform/shell.go index 6184d3f6d10..bd6991585ee 100644 --- a/pkg/component/terraform/shell.go +++ b/pkg/component/terraform/shell.go @@ -10,6 +10,7 @@ import ( auth "github.com/cloudposse/atmos/pkg/auth" authdeferred "github.com/cloudposse/atmos/pkg/auth/deferred" "github.com/cloudposse/atmos/pkg/component" + "github.com/cloudposse/atmos/pkg/component/terragruntexec" "github.com/cloudposse/atmos/pkg/config" log "github.com/cloudposse/atmos/pkg/logger" "github.com/cloudposse/atmos/pkg/perf" @@ -130,6 +131,11 @@ func (e *Executor) ExecuteTerraformShell(opts *tf.ShellOptions, atmosConfig *sch return err } + // A shell in the provisioned module would not be the unit Terragrunt runs. + if terragruntexec.Owns(&info) { + return terragruntexec.CheckCommand(&info, "shell") + } + componentPath, err := u.GetComponentPath(atmosConfig, "terraform", info.ComponentFolderPrefix, info.FinalComponent) if err != nil { return err diff --git a/pkg/component/terraform/verify_plan.go b/pkg/component/terraform/verify_plan.go index b6c66f9feb4..9bd78b4070e 100644 --- a/pkg/component/terraform/verify_plan.go +++ b/pkg/component/terraform/verify_plan.go @@ -122,10 +122,9 @@ func (s *Operations) loadStoredAndFreshPlans(atmosConfig *schema.AtmosConfigurat return plans, fmt.Errorf("error getting JSON for stored plan: %w", err) } - // Generate a fresh plan at the canonical planfile path in the component dir, - // where terraform expects it, rather than in a temp dir. - freshPlanPath := ConstructTerraformComponentPlanfilePath(atmosConfig, processedInfo) - plans.freshPlanFile, err = s.GenerateNewPlanFile(atmosConfig, processedInfo, componentPath, filepath.Dir(freshPlanPath)) + // Generate a fresh plan in the component dir, where terraform expects it, rather than in a temp + // dir. For a workdir-enabled component that is its workdir, which componentPath already is. + plans.freshPlanFile, err = s.GenerateNewPlanFile(atmosConfig, processedInfo, componentPath, componentPath) if err != nil { return plans, fmt.Errorf("error generating fresh plan for verification: %w", err) } diff --git a/pkg/component/terragruntexec/mock_host_test.go b/pkg/component/terragruntexec/mock_host_test.go new file mode 100644 index 00000000000..8f615994291 --- /dev/null +++ b/pkg/component/terragruntexec/mock_host_test.go @@ -0,0 +1,70 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cloudposse/atmos/pkg/component/terragruntexec (interfaces: Host) +// +// Generated by this command: +// +// mockgen -destination=mock_host_test.go -package=terragruntexec . Host +// + +// Package terragruntexec is a generated GoMock package. +package terragruntexec + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockHost is a mock of Host interface. +type MockHost struct { + ctrl *gomock.Controller + recorder *MockHostMockRecorder + isgomock struct{} +} + +// MockHostMockRecorder is the mock recorder for MockHost. +type MockHostMockRecorder struct { + mock *MockHost +} + +// NewMockHost creates a new mock instance. +func NewMockHost(ctrl *gomock.Controller) *MockHost { + mock := &MockHost{ctrl: ctrl} + mock.recorder = &MockHostMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHost) EXPECT() *MockHostMockRecorder { + return m.recorder +} + +// Execute mocks base method. +func (m *MockHost) Execute(ctx context.Context, command *Command) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Execute", ctx, command) + ret0, _ := ret[0].(error) + return ret0 +} + +// Execute indicates an expected call of Execute. +func (mr *MockHostMockRecorder) Execute(ctx, command any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockHost)(nil).Execute), ctx, command) +} + +// Version mocks base method. +func (m *MockHost) Version(ctx context.Context, binary string, env []string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Version", ctx, binary, env) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Version indicates an expected call of Version. +func (mr *MockHostMockRecorder) Version(ctx, binary, env any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockHost)(nil).Version), ctx, binary, env) +} diff --git a/pkg/component/terragruntexec/terragruntexec.go b/pkg/component/terragruntexec/terragruntexec.go new file mode 100644 index 00000000000..91091a49ff3 --- /dev/null +++ b/pkg/component/terragruntexec/terragruntexec.go @@ -0,0 +1,299 @@ +// Package terragruntexec runs a Terragrunt unit through a pinned `terragrunt` executable. +// +// Executable mode is the migration path next to native adaptation. Atmos still owns which units +// run, their order, authentication, the toolchain, the environment, and the UI. This package only +// translates one Atmos terraform invocation into one `terragrunt run` command for one unit, and +// never schedules anything: `--all` is expanded by Atmos into one command per unit. +package terragruntexec + +import ( + "context" + "errors" + "fmt" + "io/fs" + "maps" + "os/exec" + "path/filepath" + "regexp" + "slices" + "strings" + + "github.com/Masterminds/semver/v3" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/perf" + "github.com/cloudposse/atmos/pkg/schema" +) + +const ( + // Engine is the engine name executable-mode units are listed with. + Engine = "terragrunt" + // Binary is the tool name pinned in `dependencies.tools` or `.tool-versions`. + Binary = "terragrunt" + // MinimumVersion is the oldest Terragrunt with the `run` command and `--working-dir` this mode uses. + MinimumVersion = "1.0.0" + + unitFileName = "terragrunt.hcl" +) + +// Command is one terragrunt invocation. +type Command struct { + Binary string + Args []string + Env []string + WorkingDir string + DryRun bool +} + +// Host supplies what the executable needs from Atmos. Production code runs commands through the +// Atmos shell layer, which streams output through the UI, masks secrets, forwards interrupts, and +// returns the process exit code; tests inject a fake. +// +//go:generate go run go.uber.org/mock/mockgen -destination=mock_host_test.go -package=terragruntexec . Host +type Host interface { + // Version runs ` --version` and returns its output. + Version(ctx context.Context, binary string, env []string) (string, error) + // Execute runs the command to completion. + Execute(ctx context.Context, command *Command) error +} + +// Request describes one unit invocation. +type Request struct { + Component, Stack string + // Binary is the resolved terragrunt executable and Engine the resolved OpenTofu or Terraform one. + Binary, Engine string + // Unit is the project-relative path of the unit file; Root is the project directory. + Unit, Root string + SubCommand string + SubCommand2 string + // Arguments are the engine arguments passed after `--` on the Atmos command line. + Arguments []string + // Options are the provider options the user set; only explicit ones are present. + Options map[string]schema.ComponentProviderOption + // Features are the `features` of the provider configuration. Options of the command line and the + // environment replace them per name. + Features map[string]any + Environment []string + DryRun bool + SkipInit bool +} + +// supported maps Atmos terraform subcommands to the engine command they run. Subcommands that +// Atmos implements itself, such as shell and clean, are not here because they have no +// engine equivalent in a unit. +var supported = map[string]bool{ + "apply": true, "deploy": true, "destroy": true, "fmt": true, "force-unlock": true, "get": true, + "graph": true, "import": true, "init": true, "output": true, "plan": true, "providers": true, + "refresh": true, "show": true, "state": true, "taint": true, "test": true, "untaint": true, + "validate": true, "workspace": true, +} + +var versionPattern = regexp.MustCompile(`v?(\d+\.\d+\.\d+)`) + +// Owns reports whether the component runs through the terragrunt executable. The discovery engine +// recorded in the component settings decides, so one project section always runs in one mode. +func Owns(info *schema.ConfigAndStacksInfo) bool { + defer perf.Track(nil, "terragruntexec.Owns")() + + configuration, _ := info.ComponentSettingsSection["configuration"].(map[string]any) + engine, _ := configuration["engine"].(string) + return engine == Engine +} + +// CheckCommand rejects an Atmos terraform subcommand that has no Terragrunt equivalent for a unit. +func CheckCommand(info *schema.ConfigAndStacksInfo, command string) error { + defer perf.Track(nil, "terragruntexec.CheckCommand")() + + if !supported[command] { + return unsupported(info, fmt.Sprintf("`atmos terraform %s` has no Terragrunt equivalent for a unit", command), + "Run `terragrunt` directly in the unit directory for this command, or switch the section to `mode: native`.") + } + return nil +} + +// CheckSupported rejects invocations that executable mode cannot honor, before anything runs. +func CheckSupported(info *schema.ConfigAndStacksInfo) error { + defer perf.Track(nil, "terragruntexec.CheckSupported")() + + if err := CheckCommand(info, info.SubCommand); err != nil { + return err + } + if info.UseTerraformPlan || info.PlanFile != "" || info.StoredPlanFile != "" { + return unsupported(info, "saved plans managed by Atmos (`--from-plan`, `--planfile`)", + "Pass the plan file yourself after `--`, for example `atmos terraform plan -s -- -out=plan.tfplan`.") + } + if len(info.ComponentVarsSection) > 0 { + return unsupported(info, "stack `vars` for a Terragrunt unit", + "Set inputs in the unit's `terragrunt.hcl`; Terragrunt owns the variables in this mode.") + } + if len(info.ComponentProvidersSection) > 0 { + return unsupported(info, "stack `providers` overrides for a Terragrunt unit", + "Configure providers in the unit's `terragrunt.hcl`; Terragrunt owns generated files in this mode.") + } + return nil +} + +func unsupported(info *schema.ConfigAndStacksInfo, what, hint string) error { + return errUtils.Build(errUtils.ErrExecutableModeUnsupported). + WithExplanationf("Component `%s` in stack `%s` runs through the terragrunt executable, which does not support %s.", info.ComponentFromArg, info.Stack, what). + WithContext("component", info.ComponentFromArg). + WithContext("stack", info.Stack). + WithHint(hint). + Err() +} + +// UnitDirectory returns the directory that holds the unit file and the `--config` value needed when +// the file is not named terragrunt.hcl. +func UnitDirectory(root, unit string) (directory, config string) { + defer perf.Track(nil, "terragruntexec.UnitDirectory")() + + path := filepath.Join(root, filepath.FromSlash(unit)) + if filepath.Base(path) != unitFileName { + config = path + } + return filepath.Dir(path), config +} + +// BuildCommand translates one Atmos invocation into a `terragrunt run` command. Provider options +// become flags of `run`, which is where Terragrunt defines them; a sensitive option travels through the environment so it never appears in +// an argument list. Engine arguments follow `--` untouched. +func BuildCommand(request *Request) *Command { + defer perf.Track(nil, "terragruntexec.BuildCommand")() + + directory, config := UnitDirectory(request.Root, request.Unit) + args := []string{"--working-dir", directory, "run"} + if config != "" { + args = append(args, "--config", config) + } + if request.SkipInit { + args = append(args, "--no-auto-init") + } + optionArgs, optionEnv := optionFlags(request.Options, request.Features) + args = append(append(args, optionArgs...), "--") + args = append(args, engineArguments(request)...) + env := slices.Clone(request.Environment) + env = withDefault(env, "TG_NON_INTERACTIVE", "true") + // Forward the engine output untouched, so plan, output -json, and show -json stay pipeable and + // read like the native output instead of carrying Terragrunt log prefixes. + env = withDefault(env, "TG_TF_FORWARD_STDOUT", "true") + if request.Engine != "" { + env = withDefault(env, "TG_TF_PATH", request.Engine) + } + env = append(env, optionEnv...) + return &Command{Binary: request.Binary, Args: args, Env: env, WorkingDir: directory, DryRun: request.DryRun} +} + +// engineArguments is the command after `--`. `deploy` is `apply` that does not ask for approval. +func engineArguments(request *Request) []string { + command := request.SubCommand + args := []string{command} + if command == "deploy" { + args = []string{"apply", "-auto-approve"} + } + if request.SubCommand2 != "" { + args = append(args, request.SubCommand2) + } + return append(args, request.Arguments...) +} + +// withDefault appends a variable unless the environment already sets it, so an `env` entry of the +// component wins over the default. +func withDefault(env []string, key, value string) []string { + for _, entry := range env { + if name, _, found := strings.Cut(entry, "="); found && name == key { + return env + } + } + return append(env, key+"="+value) +} + +// optionFlags maps provider options to Terragrunt global flags, in a stable order. +func optionFlags(options map[string]schema.ComponentProviderOption, configured map[string]any) (args, env []string) { + features := maps.Clone(configured) + if features == nil { + features = map[string]any{} + } + if names, ok := options["feature"].Value.(map[string]any); ok { + maps.Copy(features, names) + } + for _, name := range slices.Sorted(maps.Keys(features)) { + args = append(args, "--feature", name+"="+fmt.Sprint(features[name])) + } + for _, flag := range []struct{ option, flag string }{ + {"iam_assume_role", "--iam-assume-role"}, + {"iam_assume_role_duration", "--iam-assume-role-duration"}, + {"iam_assume_role_session_name", "--iam-assume-role-session-name"}, + {"download_dir", "--download-dir"}, + } { + if option, set := options[flag.option]; set { + args = append(args, flag.flag, fmt.Sprint(option.Value)) + } + } + if token, set := options["iam_assume_role_web_identity_token"]; set { + env = append(env, "TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN="+fmt.Sprint(token.Value)) + } + return args, env +} + +// CheckVersion verifies that the executable exists and is not older than MinimumVersion. +func CheckVersion(ctx context.Context, host Host, binary string, env []string) error { + defer perf.Track(nil, "terragruntexec.CheckVersion")() + + output, err := host.Version(ctx, binary, env) + if err != nil { + // An interrupt is not a missing executable. + if ctxErr := ctx.Err(); ctxErr != nil { + return ctxErr + } + if errors.Is(err, exec.ErrNotFound) || errors.Is(err, fs.ErrNotExist) { + return notFound(binary, err) + } + return errUtils.Build(errUtils.ErrExecutableNotFound). + WithCause(err). + WithExplanationf("`%s --version` failed.", binary). + WithHint("Check that the pinned terragrunt executable runs on this machine."). + Err() + } + match := versionPattern.FindStringSubmatch(output) + if match == nil { + return versionError("the version output could not be read", binary) + } + found, err := semver.NewVersion(match[1]) + if err != nil { + return versionError("the version output could not be read", binary) + } + if found.LessThan(semver.MustParse(MinimumVersion)) { + return versionError(fmt.Sprintf("version %s is older than the minimum %s", found, MinimumVersion), binary) + } + return nil +} + +func notFound(binary string, cause error) error { + return errUtils.Build(errUtils.ErrExecutableNotFound). + WithCause(cause). + WithExplanationf("Executable mode runs units with `%s`, which was not found.", binary). + WithHint("Pin terragrunt for the project, for example `terragrunt 1.2.1` in `.tool-versions` or `dependencies.tools` in `atmos.yaml`; Atmos installs and uses the pinned version."). + WithHintf("Or install terragrunt %s or newer and put it on PATH.", MinimumVersion). + Err() +} + +func versionError(problem, binary string) error { + return errUtils.Build(errUtils.ErrExecutableVersion). + WithExplanationf("`%s`: %s.", binary, problem). + WithHintf("Executable mode requires terragrunt %s or newer. Pin a newer version in `.tool-versions` or `dependencies.tools`.", MinimumVersion). + Err() +} + +// Run checks the executable and runs the unit's command. A dry run skips the version probe, so it +// works without the executable installed and has no side effects. +func Run(ctx context.Context, host Host, request *Request) error { + defer perf.Track(nil, "terragruntexec.Run")() + + command := BuildCommand(request) + if !request.DryRun { + if err := CheckVersion(ctx, host, request.Binary, command.Env); err != nil { + return err + } + } + return host.Execute(ctx, command) +} diff --git a/pkg/component/terragruntexec/terragruntexec_test.go b/pkg/component/terragruntexec/terragruntexec_test.go new file mode 100644 index 00000000000..95d6477015a --- /dev/null +++ b/pkg/component/terragruntexec/terragruntexec_test.go @@ -0,0 +1,279 @@ +package terragruntexec + +import ( + "context" + "errors" + "os/exec" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/schema" +) + +// Compile-time sentinels for the schema fields these tests depend on. +var ( + _ = schema.ComponentProviderOption{Value: "", Sensitive: true} + _ = schema.ConfigAndStacksInfo{ComponentVarsSection: nil, ComponentProvidersSection: nil, UseTerraformPlan: true} +) + +func request() *Request { + return &Request{ + Component: "app", Stack: "live/dev", Binary: "/tools/terragrunt", Engine: "/tools/tofu", + Root: "project", Unit: "live/dev/app/terragrunt.hcl", SubCommand: "plan", + Arguments: []string{"-no-color"}, Environment: []string{"AWS_PROFILE=dev"}, + } +} + +func envValue(env []string, key string) (string, bool) { + for index := len(env) - 1; index >= 0; index-- { + if name, value, found := splitEnv(env[index]); found && name == key { + return value, true + } + } + return "", false +} + +func splitEnv(entry string) (name, value string, found bool) { + for index := range entry { + if entry[index] == '=' { + return entry[:index], entry[index+1:], true + } + } + return entry, "", false +} + +func TestBuildCommandRunsTheUnitDirectoryWithEngineArgumentsAfterTheSeparator(t *testing.T) { + command := BuildCommand(request()) + directory := filepath.Join("project", "live", "dev", "app") + assert.Equal(t, []string{"--working-dir", directory, "run", "--", "plan", "-no-color"}, command.Args) + assert.Equal(t, directory, command.WorkingDir) + assert.Equal(t, "/tools/terragrunt", command.Binary) + assert.False(t, command.DryRun) +} + +func TestBuildCommandEnvironment(t *testing.T) { + command := BuildCommand(request()) + value, found := envValue(command.Env, "AWS_PROFILE") + assert.True(t, found) + assert.Equal(t, "dev", value) + for key, want := range map[string]string{"TG_NON_INTERACTIVE": "true", "TG_TF_FORWARD_STDOUT": "true", "TG_TF_PATH": "/tools/tofu"} { + got, found := envValue(command.Env, key) + assert.True(t, found, key) + assert.Equal(t, want, got, key) + } + + // A component `env` entry wins over the default Atmos would add. + explicit := request() + explicit.Environment = append(explicit.Environment, "TG_TF_PATH=/custom/tofu", "TG_NON_INTERACTIVE=false") + got, _ := envValue(BuildCommand(explicit).Env, "TG_TF_PATH") + assert.Equal(t, "/custom/tofu", got) + got, _ = envValue(BuildCommand(explicit).Env, "TG_NON_INTERACTIVE") + assert.Equal(t, "false", got) + + // The input slice is never modified. + assert.Equal(t, []string{"AWS_PROFILE=dev"}, request().Environment) +} + +func TestBuildCommandMapsSubcommands(t *testing.T) { + cases := map[string]struct { + subcommand, second string + arguments []string + want []string + }{ + "deploy applies without asking": {subcommand: "deploy", want: []string{"apply", "-auto-approve"}}, + "apply keeps user arguments": {subcommand: "apply", arguments: []string{"-auto-approve"}, want: []string{"apply", "-auto-approve"}}, + "workspace subcommand": {subcommand: "workspace", second: "select", arguments: []string{"dev"}, want: []string{"workspace", "select", "dev"}}, + "output json": {subcommand: "output", arguments: []string{"-json"}, want: []string{"output", "-json"}}, + "no arguments": {subcommand: "validate", want: []string{"validate"}}, + } + for name, test := range cases { + t.Run(name, func(t *testing.T) { + r := request() + r.SubCommand, r.SubCommand2, r.Arguments = test.subcommand, test.second, test.arguments + args := BuildCommand(r).Args + separator := -1 + for index, arg := range args { + if arg == "--" { + separator = index + break + } + } + require.GreaterOrEqual(t, separator, 0) + assert.Equal(t, test.want, args[separator+1:]) + }) + } +} + +func TestBuildCommandUsesConfigAndSkipInit(t *testing.T) { + r := request() + r.Unit, r.SkipInit = "live/dev/app/custom.hcl", true + args := BuildCommand(r).Args + directory := filepath.Join("project", "live", "dev", "app") + assert.Equal(t, []string{"--working-dir", directory, "run", "--config", filepath.Join(directory, "custom.hcl"), "--no-auto-init", "--"}, args[:7]) +} + +func TestBuildCommandOptions(t *testing.T) { + r := request() + r.Features = map[string]any{"alpha": true, "beta": "from-config"} + r.Options = map[string]schema.ComponentProviderOption{ + "feature": {Value: map[string]any{"beta": "from-cli", "gamma": "3"}}, + "iam_assume_role": {Value: "arn:aws:iam::1:role/x"}, + "iam_assume_role_duration": {Value: 900}, + "iam_assume_role_session_name": {Value: "ci"}, + "download_dir": {Value: "/cache"}, + "iam_assume_role_web_identity_token": {Value: "s3cret", Sensitive: true}, + } + command := BuildCommand(r) + want := []string{ + "--feature", "alpha=true", "--feature", "beta=from-cli", "--feature", "gamma=3", + "--iam-assume-role", "arn:aws:iam::1:role/x", "--iam-assume-role-duration", "900", + "--iam-assume-role-session-name", "ci", "--download-dir", "/cache", "--", + } + assert.Equal(t, want, command.Args[3:3+len(want)]) + for _, arg := range command.Args { + assert.NotContains(t, arg, "s3cret", "a sensitive value never appears in argv") + } + token, found := envValue(command.Env, "TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN") + assert.True(t, found) + assert.Equal(t, "s3cret", token) +} + +func TestBuildCommandOmitsAbsentOptions(t *testing.T) { + r := request() + assert.Equal(t, []string{"--working-dir", filepath.Join("project", "live", "dev", "app"), "run", "--", "plan", "-no-color"}, BuildCommand(r).Args) + _, found := envValue(BuildCommand(r).Env, "TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN") + assert.False(t, found) +} + +func unitInfo(subcommand string) *schema.ConfigAndStacksInfo { + return &schema.ConfigAndStacksInfo{ + SubCommand: subcommand, ComponentFromArg: "app", Stack: "live/dev", + ComponentSettingsSection: map[string]any{"configuration": map[string]any{"engine": "terragrunt"}}, + } +} + +func TestOwnsFollowsTheDiscoveryEngine(t *testing.T) { + assert.True(t, Owns(unitInfo("plan"))) + native := unitInfo("plan") + native.ComponentSettingsSection["configuration"] = map[string]any{"engine": "opentofu"} + assert.False(t, Owns(native)) + assert.False(t, Owns(&schema.ConfigAndStacksInfo{})) +} + +func TestCheckSupported(t *testing.T) { + for _, command := range []string{"plan", "apply", "deploy", "destroy", "init", "output", "state", "workspace", "validate", "import"} { + require.NoError(t, CheckSupported(unitInfo(command)), command) + } + for _, command := range []string{"shell", "clean", "generate", "console-ui"} { + require.ErrorIs(t, CheckSupported(unitInfo(command)), errUtils.ErrExecutableModeUnsupported, command) + } + + saved := unitInfo("apply") + saved.UseTerraformPlan = true + require.ErrorIs(t, CheckSupported(saved), errUtils.ErrExecutableModeUnsupported) + file := unitInfo("apply") + file.PlanFile = "plan.tfplan" + require.ErrorIs(t, CheckSupported(file), errUtils.ErrExecutableModeUnsupported) + + vars := unitInfo("plan") + vars.ComponentVarsSection = map[string]any{"region": "us-east-1"} + require.ErrorIs(t, CheckSupported(vars), errUtils.ErrExecutableModeUnsupported) + providers := unitInfo("plan") + providers.ComponentProvidersSection = map[string]any{"aws": map[string]any{}} + require.ErrorIs(t, CheckSupported(providers), errUtils.ErrExecutableModeUnsupported) +} + +func TestCheckVersion(t *testing.T) { + cases := map[string]struct { + output string + err error + target error + }{ + "current": {output: "terragrunt version v1.2.1"}, + "minimum": {output: "terragrunt version v1.0.0"}, + "without prefix": {output: "terragrunt version 2.0.0\n"}, + "too old": {output: "terragrunt version v0.99.9", target: errUtils.ErrExecutableVersion}, + "unreadable": {output: "unexpected", target: errUtils.ErrExecutableVersion}, + "missing": {err: exec.ErrNotFound, target: errUtils.ErrExecutableNotFound}, + "failing": {err: errors.New("exit status 1"), target: errUtils.ErrExecutableNotFound}, + } + for name, test := range cases { + t.Run(name, func(t *testing.T) { + host := NewMockHost(gomock.NewController(t)) + host.EXPECT().Version(gomock.Any(), "terragrunt", []string{"A=1"}).Return(test.output, test.err) + err := CheckVersion(context.Background(), host, "terragrunt", []string{"A=1"}) + if test.target == nil { + require.NoError(t, err) + return + } + require.ErrorIs(t, err, test.target) + }) + } +} + +func TestRunChecksTheVersionThenExecutes(t *testing.T) { + controller := gomock.NewController(t) + host := NewMockHost(controller) + gomock.InOrder( + host.EXPECT().Version(gomock.Any(), "/tools/terragrunt", gomock.Any()).Return("terragrunt version v1.2.1", nil), + host.EXPECT().Execute(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, command *Command) error { + assert.Equal(t, "/tools/terragrunt", command.Binary) + assert.Equal(t, "run", command.Args[2]) + return nil + }), + ) + require.NoError(t, Run(context.Background(), host, request())) +} + +func TestRunPropagatesTheUnitFailure(t *testing.T) { + failure := errUtils.ExitCodeError{Code: 3} + host := NewMockHost(gomock.NewController(t)) + host.EXPECT().Version(gomock.Any(), gomock.Any(), gomock.Any()).Return("terragrunt version v1.2.1", nil) + host.EXPECT().Execute(gomock.Any(), gomock.Any()).Return(failure) + err := Run(context.Background(), host, request()) + var exit errUtils.ExitCodeError + require.ErrorAs(t, err, &exit) + assert.Equal(t, 3, exit.Code) +} + +func TestRunDoesNotExecuteWhenTheVersionIsUnsupported(t *testing.T) { + host := NewMockHost(gomock.NewController(t)) + host.EXPECT().Version(gomock.Any(), gomock.Any(), gomock.Any()).Return("terragrunt version v0.1.0", nil) + host.EXPECT().Execute(gomock.Any(), gomock.Any()).Times(0) + require.ErrorIs(t, Run(context.Background(), host, request()), errUtils.ErrExecutableVersion) +} + +func TestDryRunSkipsTheVersionProbe(t *testing.T) { + host := NewMockHost(gomock.NewController(t)) + host.EXPECT().Version(gomock.Any(), gomock.Any(), gomock.Any()).Times(0) + host.EXPECT().Execute(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, command *Command) error { + assert.True(t, command.DryRun) + return nil + }) + r := request() + r.DryRun = true + require.NoError(t, Run(context.Background(), host, r)) +} + +func TestUnitDirectory(t *testing.T) { + directory, config := UnitDirectory("project", "live/dev/app/terragrunt.hcl") + assert.Equal(t, filepath.Join("project", "live", "dev", "app"), directory) + assert.Empty(t, config) + directory, config = UnitDirectory("project", "live/dev/app/other.hcl") + assert.Equal(t, filepath.Join("project", "live", "dev", "app"), directory) + assert.Equal(t, filepath.Join("project", "live", "dev", "app", "other.hcl"), config) +} + +func TestCancellationIsNotReportedAsAMissingExecutable(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + host := NewMockHost(gomock.NewController(t)) + host.EXPECT().Version(gomock.Any(), gomock.Any(), gomock.Any()).Return("", errors.New("signal: killed")) + host.EXPECT().Execute(gomock.Any(), gomock.Any()).Times(0) + require.ErrorIs(t, Run(ctx, host, request()), context.Canceled) +} diff --git a/pkg/config/config.go b/pkg/config/config.go index fc65ae2dadb..703cbbb79ac 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -90,6 +90,7 @@ func InitCliConfigWithContext(ctx context.Context, configAndStacksInfo schema.Co } } + atmosConfig.ComponentProviderOptions = configAndStacksInfo.ComponentProviderOptions if err := configuration.Attach(ctx, &atmosConfig, configAndStacksInfo.SubCommand); err != nil { return atmosConfig, err } diff --git a/pkg/flags/standard_parser.go b/pkg/flags/standard_parser.go index 1db97e20452..1333d2ce630 100644 --- a/pkg/flags/standard_parser.go +++ b/pkg/flags/standard_parser.go @@ -276,6 +276,27 @@ func (p *StandardParser) buildStandardOptions(parsedConfig *ParsedConfig, compon } } +// IsFlagExplicitlySet reports whether the user set the named flag on the command line or through +// an environment variable registered with it, of any flag type. Unlike viper.IsSet, a registered +// default does not count, so an absent flag is distinguishable from an explicit false, zero, or empty value. +func (p *StandardParser) IsFlagExplicitlySet(cmd *cobra.Command, flagName string) bool { + defer perf.Track(nil, "flags.StandardParser.IsFlagExplicitlySet")() + + if _, changed := lookupCommandFlag(cmd, flagName); changed { + return true + } + reg := p.parser.registry.Get(flagName) + if reg == nil { + return false + } + for _, envVar := range reg.GetEnvVars() { + if _, ok := os.LookupEnv(envVar); ok { + return true + } + } + return false +} + // IsBoolFlagExplicitlySet reports whether the named boolean flag was explicitly set // by the user via CLI or via an environment variable registered with the flag. // diff --git a/pkg/flags/standard_parser_tristate_test.go b/pkg/flags/standard_parser_tristate_test.go index 0e4f1f84185..38c3926031b 100644 --- a/pkg/flags/standard_parser_tristate_test.go +++ b/pkg/flags/standard_parser_tristate_test.go @@ -118,3 +118,42 @@ func TestIsBoolFlagExplicitlySet(t *testing.T) { assert.False(t, val, "unknown flag should return false value") }) } + +// TestIsFlagExplicitlySet verifies the type-independent explicit detection used by provider options. +func TestIsFlagExplicitlySet(t *testing.T) { + newParser := func(t *testing.T) (*flags.StandardParser, *cobra.Command) { + t.Helper() + parser := flags.NewStandardParser( + flags.WithStringFlag("level", "", "info", "Level"), + flags.WithEnvVars("level", "ATMOS_TEST_EXPLICIT_LEVEL"), + flags.WithIntFlag("retries", "", 3, "Retries"), + ) + cmd := &cobra.Command{Use: "plan"} + parser.RegisterFlags(cmd) + require.NoError(t, parser.BindToViper(viper.New())) + return parser, cmd + } + + t.Run("a registered default is not explicit", func(t *testing.T) { + parser, cmd := newParser(t) + assert.False(t, parser.IsFlagExplicitlySet(cmd, "level")) + assert.False(t, parser.IsFlagExplicitlySet(cmd, "retries")) + }) + t.Run("a command line value is explicit even when it equals the default or is zero", func(t *testing.T) { + parser, cmd := newParser(t) + require.NoError(t, cmd.Flags().Set("level", "")) + require.NoError(t, cmd.Flags().Set("retries", "0")) + assert.True(t, parser.IsFlagExplicitlySet(cmd, "level")) + assert.True(t, parser.IsFlagExplicitlySet(cmd, "retries")) + }) + t.Run("a registered environment variable is explicit, even when empty", func(t *testing.T) { + parser, cmd := newParser(t) + t.Setenv("ATMOS_TEST_EXPLICIT_LEVEL", "") + assert.True(t, parser.IsFlagExplicitlySet(cmd, "level")) + assert.False(t, parser.IsFlagExplicitlySet(cmd, "retries"), "a flag without an environment binding is unaffected") + }) + t.Run("an unknown flag is never explicit", func(t *testing.T) { + parser, cmd := newParser(t) + assert.False(t, parser.IsFlagExplicitlySet(cmd, "unknown")) + }) +} diff --git a/pkg/plugin/adapter/component/diagnostics.go b/pkg/plugin/adapter/component/diagnostics.go index 51b84a37730..eeda4884b4d 100644 --- a/pkg/plugin/adapter/component/diagnostics.go +++ b/pkg/plugin/adapter/component/diagnostics.go @@ -81,6 +81,8 @@ func DetailError(detail *pluginv1.ErrorDetail, class codes.Code) error { if detail == nil { return errUtils.ErrPluginAPI } + // The events that preceded the failure explain it; they show at the Atmos log level, never as the error. + RenderLogs(LogScope{Component: detail.GetUnit(), Stack: detail.GetStack()}, detail.GetLogs()) builder := errUtils.Build(&Failure{Detail: detail, sentinel: sentinelFor(class)}) if where := describeWhere(detail); where != "" { builder.WithExplanation(where) @@ -193,6 +195,10 @@ func WarnDiagnostic(diagnostic *pluginv1.Diagnostic) { if detail.UserSafe && detail.Detail != "" { text += ": " + detail.Detail } + // Preparation reruns before every step of a command, so the same warning would repeat. + if !firstTime("diagnostic", detail.GetUnit(), detail.GetStack(), detail.GetCode(), mask(text)) { + return + } ui.Warning(mask(text)) for _, hint := range detail.Hints { ui.Hint(mask(hint)) diff --git a/pkg/plugin/adapter/component/diagnostics_test.go b/pkg/plugin/adapter/component/diagnostics_test.go index f411bc261f6..75f8cd4b40d 100644 --- a/pkg/plugin/adapter/component/diagnostics_test.go +++ b/pkg/plugin/adapter/component/diagnostics_test.go @@ -1,14 +1,20 @@ package component import ( + "bytes" + "os" + "slices" "strings" "testing" + charm "github.com/charmbracelet/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" errUtils "github.com/cloudposse/atmos/errors" atmosio "github.com/cloudposse/atmos/pkg/io" + log "github.com/cloudposse/atmos/pkg/logger" pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" ) @@ -89,3 +95,117 @@ func TestDiagnosticLocationIsMaskedBeforeItIsAttached(t *testing.T) { assert.NotContains(t, location.File, "tok,en-7d3a") assert.Equal(t, 3, location.Line) } + +// captureLogs sends the Atmos logger to a buffer at the given level for one test. +func captureLogs(t *testing.T, level charm.Level) *bytes.Buffer { + t.Helper() + var output bytes.Buffer + previousLevel := log.GetLevel() + log.SetOutput(&output) + log.SetLevel(level) + ResetShownMessages() + t.Cleanup(func() { + log.SetOutput(os.Stderr) + log.SetLevel(previousLevel) + ResetShownMessages() + }) + return &output +} + +func logEntry(level pluginv1.LogLevel, message string, fields map[string]string) *pluginv1.LogEntry { + return &pluginv1.LogEntry{Level: level, Message: message, Fields: fields, Unit: "live/dev/app"} +} + +func TestRenderLogsHonorsAtmosLevelAndScopesEntries(t *testing.T) { + entries := []*pluginv1.LogEntry{ + logEntry(pluginv1.LogLevel_LOG_LEVEL_TRACE, "trace event", nil), + logEntry(pluginv1.LogLevel_LOG_LEVEL_DEBUG, "debug event", map[string]string{"b": "2", "a": "1"}), + logEntry(pluginv1.LogLevel_LOG_LEVEL_INFO, "info event", nil), + logEntry(pluginv1.LogLevel_LOG_LEVEL_WARN, "warn event", nil), + logEntry(pluginv1.LogLevel_LOG_LEVEL_ERROR, "error event", nil), + logEntry(pluginv1.LogLevel_LOG_LEVEL_UNSPECIFIED, "ignored event", nil), + } + scope := LogScope{Provider: "terragrunt", Component: "app", Stack: "live/dev"} + + warn := captureLogs(t, charm.WarnLevel) + RenderLogs(scope, entries) + assert.Contains(t, warn.String(), "warn event") + assert.Contains(t, warn.String(), "error event") + for _, hidden := range []string{"trace event", "debug event", "info event", "ignored event"} { + assert.NotContains(t, warn.String(), hidden, "hidden by default at the Warn level") + } + assert.Contains(t, warn.String(), "component=app") + assert.Contains(t, warn.String(), "stack=live/dev") + assert.Contains(t, warn.String(), "plugin=terragrunt") + assert.Contains(t, warn.String(), "unit=live/dev/app") + + debug := captureLogs(t, charm.DebugLevel) + RenderLogs(scope, entries) + assert.Contains(t, debug.String(), "debug event") + assert.Contains(t, debug.String(), "a=1 b=2", "fields render in key order") + assert.NotContains(t, debug.String(), "trace event") + + trace := captureLogs(t, log.TraceLevel) + RenderLogs(scope, entries) + assert.Contains(t, trace.String(), "trace event") +} + +func TestRenderLogsMasksSecretsInMessagesAndFields(t *testing.T) { + atmosio.RegisterSecret("log-secret-value-77ab") + output := captureLogs(t, charm.DebugLevel) + + RenderLogs(LogScope{Component: "app", Stack: "dev"}, []*pluginv1.LogEntry{ + logEntry(pluginv1.LogLevel_LOG_LEVEL_DEBUG, "token log-secret-value-77ab leaked", map[string]string{"auth": "Bearer log-secret-value-77ab"}), + }) + + assert.NotContains(t, output.String(), "log-secret-value-77ab") + assert.Contains(t, output.String(), "leaked") +} + +func TestRenderLogsShowsAWarningOncePerComponentAndStack(t *testing.T) { + output := captureLogs(t, charm.DebugLevel) + warning := []*pluginv1.LogEntry{logEntry(pluginv1.LogLevel_LOG_LEVEL_WARN, "state is not encrypted", nil)} + debug := []*pluginv1.LogEntry{logEntry(pluginv1.LogLevel_LOG_LEVEL_DEBUG, "evaluating again", nil)} + + for range 3 { + RenderLogs(LogScope{Component: "app", Stack: "dev"}, append(slices.Clone(warning), debug...)) + } + RenderLogs(LogScope{Component: "app", Stack: "prod"}, warning) + + assert.Equal(t, 2, strings.Count(output.String(), "state is not encrypted"), "once per component and stack") + assert.Equal(t, 3, strings.Count(output.String(), "evaluating again"), "debug events are not deduplicated") +} + +func TestWarnDiagnosticShowsTheSameWarningOncePerInvocation(t *testing.T) { + captureLogs(t, charm.WarnLevel) + warning := &pluginv1.Diagnostic{Detail: &pluginv1.ErrorDetail{Code: "remote_state_encryption_not_generated", Summary: "Encryption is not generated", Unit: "app", Stack: "dev", UserSafe: true, Severity: pluginv1.Severity_SEVERITY_WARNING}} + + assert.True(t, firstTime("diagnostic", "app", "dev", "remote_state_encryption_not_generated", "Encryption is not generated (Component `app` in stack `dev`)"), "unseen before the first call") + ResetShownMessages() + WarnDiagnostic(warning) + assert.False(t, firstTime("diagnostic", "app", "dev", "remote_state_encryption_not_generated", "Encryption is not generated (Component `app` in stack `dev`)"), "the first call recorded it") + WarnDiagnostic(warning) + other := &pluginv1.Diagnostic{Detail: &pluginv1.ErrorDetail{Code: "remote_state_encryption_not_generated", Summary: "Encryption is not generated", Unit: "app", Stack: "prod", Severity: pluginv1.Severity_SEVERITY_WARNING}} + WarnDiagnostic(other) + assert.False(t, firstTime("diagnostic", "app", "prod", "remote_state_encryption_not_generated", "Encryption is not generated (Component `app` in stack `prod`)"), "another stack is its own warning, recorded by its own call") +} + +func TestFailureLogsRenderBeforeTheErrorAtTheAtmosLevel(t *testing.T) { + output := captureLogs(t, charm.DebugLevel) + detail := &pluginv1.ErrorDetail{Code: "evaluation_error", Summary: "Evaluation failed", Unit: "app", Stack: "dev", Logs: []*pluginv1.LogEntry{logEntry(pluginv1.LogLevel_LOG_LEVEL_DEBUG, "reading include", nil)}} + + err := DetailError(detail, codes.InvalidArgument) + + require.ErrorIs(t, err, errUtils.ErrPluginInvalidConfig) + assert.Contains(t, output.String(), "reading include") + assert.NotContains(t, err.Error(), "reading include", "log entries are never part of the error") +} + +func TestHostLogLevelUsesThePluginVocabulary(t *testing.T) { + for level, want := range map[charm.Level]string{log.TraceLevel: "trace", charm.DebugLevel: "debug", charm.InfoLevel: "info", charm.WarnLevel: "warn", charm.ErrorLevel: "error", charm.FatalLevel + 1: "off"} { + previous := log.GetLevel() + log.SetLevel(level) + assert.Equal(t, want, HostLogLevel()) + log.SetLevel(previous) + } +} diff --git a/pkg/plugin/adapter/component/logs.go b/pkg/plugin/adapter/component/logs.go new file mode 100644 index 00000000000..66245258af2 --- /dev/null +++ b/pkg/plugin/adapter/component/logs.go @@ -0,0 +1,119 @@ +package component + +import ( + "maps" + "slices" + "strings" + "sync" + + charm "github.com/charmbracelet/log" + + atmosio "github.com/cloudposse/atmos/pkg/io" + log "github.com/cloudposse/atmos/pkg/logger" + "github.com/cloudposse/atmos/pkg/perf" + pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" +) + +// LogScope identifies the call a plugin's log events belong to. +type LogScope struct { + Provider string + Component string + Stack string +} + +// logOff is the level that tells a plugin to return no log events. +const logOff = "off" + +// shown holds the messages already shown during this invocation, so that the several evaluations one command +// makes (preparation reruns before every step) do not repeat the same warning. +var shown = struct { + sync.Mutex + keys map[string]struct{} +}{keys: map[string]struct{}{}} + +// firstTime reports whether the message identified by parts is shown for the first time in this invocation. +func firstTime(parts ...string) bool { + key := strings.Join(parts, "\x00") + shown.Lock() + defer shown.Unlock() + if _, seen := shown.keys[key]; seen { + return false + } + shown.keys[key] = struct{}{} + return true +} + +// ResetShownMessages forgets which warnings were shown. Tests use it for isolation. +func ResetShownMessages() { + defer perf.Track(nil, "componentadapter.ResetShownMessages")() + + shown.Lock() + defer shown.Unlock() + clear(shown.keys) +} + +// HostLogLevel returns the Atmos log level in the vocabulary of the plugin protocol, so a plugin can skip +// events nobody will see. A level above error means off. +func HostLogLevel() string { + defer perf.Track(nil, "componentadapter.HostLogLevel")() + + level := log.GetLevel() + switch { + case level == log.TraceLevel: + return "trace" + case level > charm.ErrorLevel: + return logOff + default: + return log.LevelToString(level) + } +} + +// RenderLogs shows a plugin's log events through the Atmos logger, on the UI channel (stderr), scoped to the +// component and stack of the call. The Atmos log level decides what is visible: the logger drops events +// below it. Messages and field values are masked. Rendering never fails the call. A warning or error that was +// already shown for the same component and stack in this invocation is not shown again. +func RenderLogs(scope LogScope, entries []*pluginv1.LogEntry) { + defer perf.Track(nil, "componentadapter.RenderLogs")() + + for _, entry := range entries { + level, ok := logLevel(entry.GetLevel()) + if !ok { + continue + } + message := atmosio.MaskString(entry.GetMessage()) + if level >= charm.WarnLevel && !firstTime("log", scope.Component, scope.Stack, entry.GetLevel().String(), entry.GetUnit(), message) { + continue + } + log.Log(level, message, logFields(scope, entry)...) + } +} + +func logLevel(level pluginv1.LogLevel) (charm.Level, bool) { + switch level { + case pluginv1.LogLevel_LOG_LEVEL_TRACE: + return log.TraceLevel, true + case pluginv1.LogLevel_LOG_LEVEL_DEBUG: + return charm.DebugLevel, true + case pluginv1.LogLevel_LOG_LEVEL_INFO: + return charm.InfoLevel, true + case pluginv1.LogLevel_LOG_LEVEL_WARN: + return charm.WarnLevel, true + case pluginv1.LogLevel_LOG_LEVEL_ERROR: + return charm.ErrorLevel, true + } + return 0, false +} + +// logFields lists the scope first, then the event's own fields in key order, all masked. +func logFields(scope LogScope, entry *pluginv1.LogEntry) []any { + fields := make([]any, 0, 8+2*len(entry.GetFields())) + for _, pair := range [][2]string{{"plugin", scope.Provider}, {log.FieldComponent, scope.Component}, {log.FieldStack, scope.Stack}, {"unit", entry.GetUnit()}} { + if pair[1] != "" { + fields = append(fields, pair[0], atmosio.MaskString(pair[1])) + } + } + for _, key := range slices.Sorted(maps.Keys(entry.GetFields())) { + fields = append(fields, key, atmosio.MaskString(entry.Fields[key])) + } + return fields +} diff --git a/pkg/plugin/adapter/component/objects.go b/pkg/plugin/adapter/component/objects.go index 6de2b68abf5..b8e14413c3d 100644 --- a/pkg/plugin/adapter/component/objects.go +++ b/pkg/plugin/adapter/component/objects.go @@ -3,6 +3,10 @@ package component import ( "bytes" "encoding/json" + "maps" + "slices" + "strconv" + "strings" "github.com/zclconf/go-cty/cty" ctyjson "github.com/zclconf/go-cty/cty/json" @@ -74,6 +78,74 @@ func DecodeObject(input *pluginv1.ComponentValue) (map[string]any, error) { return object, nil } +// DecodeInputs adapts the evaluated variables of a component. It behaves like DecodeObject, but a value that +// is not yet known is a defect of the plugin that the user must be able to trace, so the error names the +// input and the path of the unknown value inside it. It never prints a value. +func DecodeInputs(input *pluginv1.ComponentValue) (map[string]any, error) { + defer perf.Track(nil, "componentadapter.DecodeInputs")() + + if input == nil { + return map[string]any{}, nil + } + value, err := decodePlain(input) + if err != nil { + return nil, err + } + if !value.IsWhollyKnown() && !value.IsNull() && (value.Type().IsObjectType() || value.Type().IsMapType()) { + return nil, unknownInputError(value) + } + return DecodeObject(input) +} + +// unknownInputError names the first input, in key order, that holds an unknown value. +func unknownInputError(object cty.Value) error { + if !object.IsKnown() { + return errUtils.Build(errUtils.ErrPluginProtocol). + WithExplanation("The plugin returned the inputs of the component as an unknown value."). + WithHint("Report this to the plugin author: inputs must be fully evaluated before they reach Atmos."). + Err() + } + attributes := object.AsValueMap() + for _, name := range slices.Sorted(maps.Keys(attributes)) { + if attributes[name].IsWhollyKnown() { + continue + } + path := name + _ = cty.Walk(attributes[name], func(at cty.Path, current cty.Value) (bool, error) { + if current.IsKnown() { + return true, nil + } + path = name + formatPath(at) + return false, nil + }) + return errUtils.Build(errUtils.ErrPluginProtocol). + WithExplanationf("The input `%s` is not known when the component is prepared, so Atmos cannot write it to the variable file.", path). + WithContext("input", name). + WithHint("Terraform computes unknown values during apply; an input must be known before Terraform starts. Replace it with a value that does not depend on resources that do not exist yet."). + WithHint("If the input comes from a dependency output, give the dependency `mock_outputs` or apply the dependency first."). + Err() + } + return errUtils.ErrPluginProtocol +} + +// formatPath renders a cty path as .key and [index] steps. +func formatPath(path cty.Path) string { + var text strings.Builder + for _, step := range path { + switch step := step.(type) { + case cty.GetAttrStep: + text.WriteString("." + step.Name) + case cty.IndexStep: + if step.Key.Type() == cty.String { + text.WriteString("[" + strconv.Quote(step.Key.AsString()) + "]") + } else { + text.WriteString("[" + step.Key.AsBigFloat().String() + "]") + } + } + } + return text.String() +} + // DecodeValue adapts one fully evaluated value of any type, such as an entry of a value map. // A null value decodes to nil. func DecodeValue(input *pluginv1.ComponentValue) (any, error) { diff --git a/pkg/plugin/adapter/component/objects_test.go b/pkg/plugin/adapter/component/objects_test.go index 0a017483de6..9eca51d4fef 100644 --- a/pkg/plugin/adapter/component/objects_test.go +++ b/pkg/plugin/adapter/component/objects_test.go @@ -2,14 +2,18 @@ package component import ( "encoding/json" + "math/big" + "strings" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zclconf/go-cty/cty" ctyjson "github.com/zclconf/go-cty/cty/json" "github.com/zclconf/go-cty/cty/msgpack" errUtils "github.com/cloudposse/atmos/errors" + atmosio "github.com/cloudposse/atmos/pkg/io" pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" ) @@ -102,3 +106,62 @@ func TestDecodeStringReadsStringsAndRejectsEverythingElse(t *testing.T) { _, err = DecodeString(&pluginv1.ComponentValue{TypeJson: []byte("{")}) require.Error(t, err) } + +func TestDecodeInputsKeepsExactNumbersNullsAndShapes(t *testing.T) { + exact, _, err := big.ParseFloat("9007199254740993", 10, 512, big.ToNearestEven) + require.NoError(t, err) + value := cty.ObjectVal(map[string]cty.Value{ + "large": cty.NumberVal(exact), + "empty": cty.EmptyTupleVal, + "absent": cty.NullVal(cty.DynamicPseudoType), + "tuple": cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.NumberIntVal(2)}), + "map": cty.MapVal(map[string]cty.Value{"k": cty.StringVal("v")}), + "object": cty.ObjectVal(map[string]cty.Value{"n": cty.NumberFloatVal(0.1)}), + }) + + decoded, err := DecodeInputs(objectWireValue(t, value)) + + require.NoError(t, err) + assert.Equal(t, json.Number("9007199254740993"), decoded["large"]) + assert.Equal(t, []any{}, decoded["empty"]) + assert.Contains(t, decoded, "absent") + assert.Nil(t, decoded["absent"]) + assert.Equal(t, []any{"a", json.Number("2")}, decoded["tuple"]) + assert.Equal(t, map[string]any{"k": "v"}, decoded["map"]) + assert.Equal(t, map[string]any{"n": json.Number("0.1")}, decoded["object"]) + empty, err := DecodeInputs(nil) + require.NoError(t, err) + assert.Empty(t, empty) +} + +func TestDecodeInputsRegistersSensitivePathsForMasking(t *testing.T) { + value := cty.ObjectVal(map[string]cty.Value{"password": cty.StringVal("inputs-secret-value-1f3a"), "public": cty.StringVal("visible-value")}) + encoded := objectWireValue(t, value) + encoded.SensitivePaths = []*pluginv1.ComponentValuePath{{Steps: []*pluginv1.ComponentValueStep{{Selector: &pluginv1.ComponentValueStep_Attribute{Attribute: "password"}}}}} + + _, err := DecodeInputs(encoded) + + require.NoError(t, err) + assert.NotContains(t, atmosio.MaskString("token=inputs-secret-value-1f3a"), "inputs-secret-value-1f3a", "a sensitive input is masked in all output") + assert.Equal(t, "visible-value", atmosio.MaskString("visible-value"), "an input that is not sensitive is left alone") +} + +func TestDecodeInputsNamesTheUnknownInput(t *testing.T) { + value := cty.ObjectVal(map[string]cty.Value{ + "fine": cty.StringVal("ok"), + "zone": cty.ObjectVal(map[string]cty.Value{"ids": cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.UnknownVal(cty.String)})}), + }) + + _, err := DecodeInputs(objectWireValue(t, value)) + + require.ErrorIs(t, err, errUtils.ErrPluginProtocol) + text := err.Error() + strings.Join(errUtils.AllDetails(err), "\n") + assert.Contains(t, text, "zone.ids[1]") + assert.NotContains(t, text, "fine") + assert.NotEmpty(t, errUtils.AllHints(err)) + + _, err = DecodeInputs(objectWireValue(t, cty.UnknownVal(cty.EmptyObject))) + require.ErrorIs(t, err, errUtils.ErrPluginProtocol) + _, err = DecodeInputs(objectWireValue(t, cty.StringVal("not an object"))) + require.ErrorIs(t, err, errUtils.ErrPluginProtocol) +} diff --git a/pkg/plugin/adapter/configuration/discovery.go b/pkg/plugin/adapter/configuration/discovery.go index 797f1b160a5..b22b8dc3b76 100644 --- a/pkg/plugin/adapter/configuration/discovery.go +++ b/pkg/plugin/adapter/configuration/discovery.go @@ -5,6 +5,7 @@ import ( "path/filepath" errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/component/terragruntexec" adapter "github.com/cloudposse/atmos/pkg/plugin/adapter/component" pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" ) @@ -76,6 +77,7 @@ func (s *Session) discoverRequests( if err != nil { return nil, err } + adapter.RenderLogs(adapter.LogScope{Provider: request.Provider}, discovered.GetLogs()) if err := recordDiagnostics(request.Provider, discovered.Diagnostics, failures); err != nil { return nil, err } @@ -127,7 +129,7 @@ func instanceConfig(instance *pluginv1.DiscoveredComponent, imported bool) (map[ if !filepath.IsLocal(instance.Address.Component) { return nil, errUtils.ErrPluginProtocol } - if instance.Engine != terraformType && instance.Engine != "opentofu" { + if instance.Engine != terraformType && instance.Engine != "opentofu" && instance.Engine != terragruntexec.Engine { return nil, errUtils.ErrPluginUnsupportedExtension } config, err := adapter.DecodeObject(instance.Configuration) diff --git a/pkg/plugin/adapter/configuration/imports.go b/pkg/plugin/adapter/configuration/imports.go index 8dacd33d8da..2a27975fde1 100644 --- a/pkg/plugin/adapter/configuration/imports.go +++ b/pkg/plugin/adapter/configuration/imports.go @@ -113,6 +113,7 @@ func (s *Session) resolveImport(ctx context.Context, template *pluginv1.Discover if err != nil { return nil, err } + adapter.RenderLogs(adapter.LogScope{Provider: request.Provider}, discovered.GetLogs()) // A broken unit that is imported by name fails the import, naming the unit: the user asked for it. for _, diagnostic := range discovered.Diagnostics { if diagnosticErr := adapter.DiagnosticError(diagnostic); diagnosticErr != nil { diff --git a/pkg/plugin/adapter/configuration/imports_test.go b/pkg/plugin/adapter/configuration/imports_test.go index 3e6af105e02..745ebcb15f3 100644 --- a/pkg/plugin/adapter/configuration/imports_test.go +++ b/pkg/plugin/adapter/configuration/imports_test.go @@ -277,7 +277,7 @@ func TestImportOfAProviderWithInvalidSettingsReportsTheSetting(t *testing.T) { _, handled, err := session.ImportComponents(t.Context(), "terragrunt://live") require.True(t, handled) require.ErrorIs(t, err, errUtils.ErrPluginInvalidConfig) - require.Contains(t, cockroachErrors.FlattenHints(err), "The only supported mode is `native`") + require.Contains(t, cockroachErrors.FlattenHints(err), "The supported modes are `native` and `executable`") // A scheme no section configures is still not handled here. _, handled, err = session.ImportComponents(t.Context(), "other://live") require.NoError(t, err) diff --git a/pkg/plugin/adapter/configuration/preparation.go b/pkg/plugin/adapter/configuration/preparation.go index 87d05e99ad8..b9134779547 100644 --- a/pkg/plugin/adapter/configuration/preparation.go +++ b/pkg/plugin/adapter/configuration/preparation.go @@ -11,6 +11,7 @@ import ( "google.golang.org/protobuf/proto" errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/component/terragruntexec" "github.com/cloudposse/atmos/pkg/downloader" "github.com/cloudposse/atmos/pkg/perf" adapter "github.com/cloudposse/atmos/pkg/plugin/adapter/component" @@ -28,6 +29,10 @@ func (s *Session) Prepare(ctx context.Context, info *schema.ConfigAndStacksInfo) if err := rejectSavedPlan(info); err != nil { return nil, err } + // Executable mode never reaches native preparation: the two modes must not mix silently. + if terragruntexec.Owns(info) { + return nil, fmt.Errorf("%w: component %q in stack %q runs through the terragrunt executable, so the provider does not prepare it", errUtils.ErrExecutableModeUnsupported, info.ComponentFromArg, info.Stack) + } selected, err := s.componentRequest(ctx, info) if err != nil { return nil, err @@ -52,7 +57,7 @@ func (s *Session) Prepare(ctx context.Context, info *schema.ConfigAndStacksInfo) // rejectSavedPlan refuses a saved plan, which a plugin-provided configuration cannot bind to yet. func rejectSavedPlan(info *schema.ConfigAndStacksInfo) error { - if info.UseTerraformPlan || info.PlanFile != "" || info.StoredPlanFile != "" { + if info.UseTerraformPlan || info.PlanFile != "" { return fmt.Errorf("%w: plugin saved-plan binding is not implemented", errUtils.ErrPluginUnsupportedExtension) } return nil @@ -69,6 +74,7 @@ func runProviderPrepare(ctx context.Context, info *schema.ConfigAndStacksInfo, s if err != nil { return nil, err } + adapter.RenderLogs(logScope(selected.request, info), result.GetLogs()) // An error diagnostic fails the preparation; warnings are printed below. for _, diagnostic := range result.Diagnostics { if err = adapter.DiagnosticError(diagnostic); err != nil { @@ -81,6 +87,11 @@ func runProviderPrepare(ctx context.Context, info *schema.ConfigAndStacksInfo, s return result, nil } +// logScope names the component and stack a plugin's log events belong to. +func logScope(request *pluginv1.ComponentRequest, info *schema.ConfigAndStacksInfo) adapter.LogScope { + return adapter.LogScope{Provider: request.GetProvider(), Component: info.ComponentFromArg, Stack: info.Stack} +} + // checkSourceOverride rejects a stack that points the component at another module. The module // belongs to the unit's own `terraform { source }`; every other `source` attribute (version, ttl, // included paths) is ordinary configuration and merges normally. @@ -161,11 +172,12 @@ func (s *Session) componentRequest(ctx context.Context, info *schema.ConfigAndSt env := preparationEnvironment(info) env["ATMOS_TERRAFORM_BINARY"] = info.Command env["TF_WORKSPACE"] = info.TerraformWorkspace + mode, options := s.providerOperation(instance.Provider) request := &pluginv1.ComponentRequest{ Provider: instance.Provider, Address: instance.Address, Source: instance.Source, RootDirectory: s.root, Configuration: instance.Configuration, ProviderConfiguration: s.providerSettings(instance.Provider), - Invocation: &pluginv1.Invocation{Environment: env}, - Operation: &pluginv1.ComponentOperation{Command: info.SubCommand, Mode: "native", TerraformArguments: slices.Clone(info.AdditionalArgsAndFlags)}, + Invocation: &pluginv1.Invocation{Environment: env, LogLevel: adapter.HostLogLevel()}, + Operation: &pluginv1.ComponentOperation{Command: info.SubCommand, Mode: mode, Options: options, TerraformArguments: slices.Clone(info.AdditionalArgsAndFlags)}, } return &selectedComponent{request: request, provider: provider, instance: instance}, nil } @@ -191,7 +203,7 @@ func (s *Session) instanceFor(info *schema.ConfigAndStacksInfo) *pluginv1.Discov } func preparedConfiguration(result *pluginv1.PrepareComponentResponse) (*schema.PreparedComponentConfiguration, error) { - inputs, err := adapter.DecodeObject(result.Inputs) + inputs, err := adapter.DecodeInputs(result.Inputs) if err != nil { return nil, err } diff --git a/pkg/plugin/adapter/configuration/preparation_test.go b/pkg/plugin/adapter/configuration/preparation_test.go index 6fff7662009..4a4d866e6dd 100644 --- a/pkg/plugin/adapter/configuration/preparation_test.go +++ b/pkg/plugin/adapter/configuration/preparation_test.go @@ -1,15 +1,21 @@ package configuration import ( + "bytes" "context" + "encoding/json" "errors" + "os" + "strings" "testing" "time" + charm "github.com/charmbracelet/log" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" errUtils "github.com/cloudposse/atmos/errors" + log "github.com/cloudposse/atmos/pkg/logger" adapter "github.com/cloudposse/atmos/pkg/plugin/adapter/component" pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" "github.com/cloudposse/atmos/pkg/schema" @@ -230,3 +236,220 @@ func TestPrepareRejectsAnExecutableChangeSinceDiscovery(t *testing.T) { _, err := session.Prepare(t.Context(), info) require.ErrorIs(t, err, errUtils.ErrComponentBinaryChanged) } + +// Compile-time sentinels for the schema fields the option tests depend on. +var ( + _ = schema.ComponentProviderOption{Value: "", Sensitive: true} + _ = schema.AtmosConfiguration{ComponentProviderOptions: nil} + _ = schema.ConfigAndStacksInfo{ComponentProviderOptions: nil} +) + +func optionsConfig(t *testing.T, mode string) *schema.AtmosConfiguration { + t.Helper() + config := enabledConfig(t) + settings := config.Components.Terraform.ConfigurationProviders["terragrunt"] + settings.Mode = mode + config.Components.Terraform.ConfigurationProviders["terragrunt"] = settings + config.ComponentProviderOptions = map[string]map[string]schema.ComponentProviderOption{"terragrunt": { + "quiet": {Value: false}, + "retries": {Value: 0}, + "feature": {Value: map[string]any{"alpha": "true"}}, + "password": {Value: "s3cret", Sensitive: true}, + }} + return config +} + +func TestExplicitOptionsAndModeReachDiscoveryAndPreparation(t *testing.T) { + for _, mode := range []string{"", "native", "executable"} { + t.Run("mode "+mode, func(t *testing.T) { + wantMode := mode + if wantMode == "" { + wantMode = "native" + } + check := func(operation *pluginv1.ComponentOperation) { + require.Equal(t, wantMode, operation.Mode) + require.Len(t, operation.Options, 4) + quiet, err := adapter.DecodeValue(operation.Options["quiet"]) + require.NoError(t, err) + require.Equal(t, false, quiet, "an explicit false is sent, not dropped") + retries, err := adapter.DecodeValue(operation.Options["retries"]) + require.NoError(t, err) + require.Equal(t, json.Number("0"), retries, "an explicit zero is sent, not dropped") + require.Empty(t, operation.Options["quiet"].SensitivePaths) + require.Len(t, operation.Options["password"].SensitivePaths, 1, "a sensitive option is marked at its root") + } + provider := NewMockProvider(gomock.NewController(t)) + provider.EXPECT().ComponentType().Return("terraform").AnyTimes() + provider.EXPECT().Discover(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, request *pluginv1.DiscoverComponentsRequest) (*pluginv1.DiscoverComponentsResponse, error) { + check(request.Operation) + return &pluginv1.DiscoverComponentsResponse{Components: []*pluginv1.DiscoveredComponent{unit(t, "app")}}, nil + }) + if wantMode != "executable" { + provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, request *pluginv1.ComponentRequest) (*pluginv1.PrepareComponentResponse, error) { + check(request.Operation) + return &pluginv1.PrepareComponentResponse{Engine: "opentofu", State: &pluginv1.ComponentStateIdentity{}}, nil + }) + } + session, err := New(t.Context(), optionsConfig(t, mode), "plan", func(context.Context, []string) (map[string]Provider, error) { + return map[string]Provider{"terragrunt": provider}, nil + }) + require.NoError(t, err) + info := &schema.ConfigAndStacksInfo{Stack: "live", ComponentFromArg: "app", SubCommand: "plan", ComponentSettingsSection: map[string]any{"configuration": true}} + if wantMode == "executable" { + // The host never prepares an executable-mode unit; only discovery needs the plugin. + _, err = session.Discover(t.Context()) + require.NoError(t, err) + return + } + _, err = session.Prepare(t.Context(), info) + require.NoError(t, err) + }) + } +} + +func TestOptionsAreAbsentWhenNoneWereSet(t *testing.T) { + session, provider, info := preparationSession(t) + provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, request *pluginv1.ComponentRequest) (*pluginv1.PrepareComponentResponse, error) { + require.Empty(t, request.Operation.Options) + require.Equal(t, "native", request.Operation.Mode) + return &pluginv1.PrepareComponentResponse{Engine: "opentofu", State: &pluginv1.ComponentStateIdentity{}}, nil + }) + _, err := session.Prepare(t.Context(), info) + require.NoError(t, err) +} + +func TestPlanIdentityIncludesTheEffectiveOptions(t *testing.T) { + identity := func(value string) string { + config := enabledConfig(t) + config.ComponentProviderOptions = map[string]map[string]schema.ComponentProviderOption{"terragrunt": {"level": {Value: value}}} + mock := NewMockProvider(gomock.NewController(t)) + mock.EXPECT().ComponentType().Return("terraform").AnyTimes() + mock.EXPECT().Discover(gomock.Any(), gomock.Any()).Return(&pluginv1.DiscoverComponentsResponse{Components: []*pluginv1.DiscoveredComponent{unit(t, "app")}}, nil) + provider := &identifiedProvider{Provider: mock, identity: func(context.Context) (string, error) { return "v1", nil }} + session, err := New(t.Context(), config, "plan", func(context.Context, []string) (map[string]Provider, error) { + return map[string]Provider{"terragrunt": provider}, nil + }) + require.NoError(t, err) + info := &schema.ConfigAndStacksInfo{Stack: "live", ComponentFromArg: "app", SubCommand: "plan", ComponentSettingsSection: map[string]any{"configuration": true}} + sum, err := session.PlanIdentity(t.Context(), info, nil) + require.NoError(t, err) + return sum + } + require.Equal(t, identity("debug"), identity("debug")) + require.NotEqual(t, identity("debug"), identity("info"), "applying a plan reviewed with other options must be refused") +} + +func TestPrepareRefusesAnExecutableModeUnit(t *testing.T) { + session, _, info := preparationSession(t) + info.ComponentSettingsSection = map[string]any{"configuration": map[string]any{"engine": "terragrunt"}} + _, err := session.Prepare(t.Context(), info) + require.ErrorIs(t, err, errUtils.ErrExecutableModeUnsupported) +} + +func TestExecutableDiscoveryEngineIsListed(t *testing.T) { + instance := unit(t, "app") + instance.Engine = "terragrunt" + config, err := instanceConfig(instance, false) + require.NoError(t, err) + require.Equal(t, "terragrunt", config["settings"].(map[string]any)["configuration"].(map[string]any)["engine"]) + + instance.Engine = "pulumi" + _, err = instanceConfig(instance, false) + require.ErrorIs(t, err, errUtils.ErrPluginUnsupportedExtension) +} + +func TestSettingsValidationAcceptsBothModes(t *testing.T) { + for _, mode := range []string{"", "native", "executable"} { + require.NoError(t, validateSettings("terragrunt", &schema.ComponentConfiguration{Mode: mode}), mode) + } + require.ErrorIs(t, validateSettings("terragrunt", &schema.ComponentConfiguration{Mode: "cli"}), errUtils.ErrPluginInvalidConfig) +} + +// captureAtmosLogs sends the Atmos logger to a buffer at the given level for one test. +func captureAtmosLogs(t *testing.T, level charm.Level) *bytes.Buffer { + t.Helper() + var output bytes.Buffer + previous := log.GetLevel() + log.SetOutput(&output) + log.SetLevel(level) + adapter.ResetShownMessages() + t.Cleanup(func() { + log.SetOutput(os.Stderr) + log.SetLevel(previous) + adapter.ResetShownMessages() + }) + return &output +} + +func TestPrepareAsksForTheAtmosLogLevelAndRendersEngineLogsScoped(t *testing.T) { + session, provider, info := preparationSession(t) + var sent *pluginv1.ComponentRequest + provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, request *pluginv1.ComponentRequest) (*pluginv1.PrepareComponentResponse, error) { + sent = request + return &pluginv1.PrepareComponentResponse{ + Engine: "opentofu", State: &pluginv1.ComponentStateIdentity{BackendType: "local"}, + Logs: []*pluginv1.LogEntry{ + {Level: pluginv1.LogLevel_LOG_LEVEL_DEBUG, Message: "reading include", Fields: map[string]string{"file": "root.hcl"}}, + {Level: pluginv1.LogLevel_LOG_LEVEL_TRACE, Message: "very detailed"}, + }, + }, nil + }) + output := captureAtmosLogs(t, charm.DebugLevel) + + _, err := session.Prepare(t.Context(), info) + + require.NoError(t, err) + require.Equal(t, "debug", sent.Invocation.LogLevel, "the plugin is told the Atmos log level") + require.Contains(t, output.String(), "reading include") + require.Contains(t, output.String(), "component=app") + require.Contains(t, output.String(), "stack=live") + require.Contains(t, output.String(), "file=root.hcl") + require.NotContains(t, output.String(), "very detailed", "the Atmos level still decides what is visible") +} + +func TestPrepareNamesAnUnknownInput(t *testing.T) { + session, provider, info := preparationSession(t) + inputs := &pluginv1.ComponentValue{TypeJson: []byte(`["object",{"zone":"string"}]`), Msgpack: []byte{0x81, 0xa4, 'z', 'o', 'n', 'e', 0xd4, 0x00, 0x00}} + provider.EXPECT().Prepare(gomock.Any(), gomock.Any()).Return(&pluginv1.PrepareComponentResponse{Engine: "opentofu", Inputs: inputs, State: &pluginv1.ComponentStateIdentity{}}, nil) + + _, err := session.Prepare(t.Context(), info) + + require.ErrorIs(t, err, errUtils.ErrPluginProtocol) + require.Contains(t, err.Error()+strings.Join(errUtils.AllDetails(err), "\n"), "`zone`") +} + +func TestDiscoveryAndStateRenderEngineLogs(t *testing.T) { + // The request is built when the session starts, so the level must be set before it. + output := captureAtmosLogs(t, charm.DebugLevel) + config := enabledConfig(t) + mock := NewMockProvider(gomock.NewController(t)) + mock.EXPECT().ComponentType().Return("terraform") + var sent *pluginv1.DiscoverComponentsRequest + mock.EXPECT().Discover(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, request *pluginv1.DiscoverComponentsRequest) (*pluginv1.DiscoverComponentsResponse, error) { + sent = request + return &pluginv1.DiscoverComponentsResponse{ + Components: []*pluginv1.DiscoveredComponent{unit(t, "network")}, + Logs: []*pluginv1.LogEntry{{Level: pluginv1.LogLevel_LOG_LEVEL_DEBUG, Message: "scanning live"}}, + }, nil + }) + provider := &stateProviderFixture{Provider: mock, resolve: func(context.Context, *pluginv1.ComponentRequest) (*pluginv1.ResolveComponentStateResponse, error) { + return &pluginv1.ResolveComponentStateResponse{ + State: &pluginv1.ComponentStateIdentity{BackendType: "local"}, + Logs: []*pluginv1.LogEntry{{Level: pluginv1.LogLevel_LOG_LEVEL_DEBUG, Message: "resolving backend"}}, + }, nil + }} + session, err := New(t.Context(), config, "describe", func(context.Context, []string) (map[string]Provider, error) { + return map[string]Provider{"terragrunt": provider}, nil + }) + require.NoError(t, err) + + _, err = session.Discover(t.Context()) + require.NoError(t, err) + _, err = session.ResolveState(t.Context(), &schema.ConfigAndStacksInfo{Stack: "live", ComponentFromArg: "network", SubCommand: "output", ComponentSettingsSection: map[string]any{"configuration": true}}) + require.NoError(t, err) + + require.Equal(t, "debug", sent.Invocation.LogLevel) + require.Contains(t, output.String(), "scanning live") + require.Contains(t, output.String(), "resolving backend") + require.Contains(t, output.String(), "component=network") +} diff --git a/pkg/plugin/adapter/configuration/session.go b/pkg/plugin/adapter/configuration/session.go index a4838469cf3..a299aee8f6f 100644 --- a/pkg/plugin/adapter/configuration/session.go +++ b/pkg/plugin/adapter/configuration/session.go @@ -111,6 +111,12 @@ func (s *Session) addProvider(config *schema.AtmosConfiguration, scheme string, s.rejectSection(scheme, invalidSetting(settingsKey(scheme), "The settings cannot be read", "Remove keys under the section that repeat a built-in setting such as `enabled`, `provider`, `mode`, or `discovery`.")) return } + options, err := operationOptions(config.ComponentProviderOptions[scheme]) + if err != nil { + s.configErr = errors.Join(s.configErr, invalidSetting(settingsKey(scheme), "The provider options of the command line cannot be encoded", "Check the values of the provider flags.")) + return + } + request.Operation.Mode, request.Operation.Options = operationMode(settings), options s.options[scheme] = settings.Options s.importProviders[scheme] = proto.Clone(request).(*pluginv1.DiscoverComponentsRequest) if settings.Discovery.Enabled { @@ -230,5 +236,5 @@ func discoveryRequest(config *schema.AtmosConfiguration, settings *schema.Compon } env := environment() env["ATMOS_TERRAFORM_BINARY"] = config.Components.Terraform.Command - return &pluginv1.DiscoverComponentsRequest{Provider: name, RootDirectory: root, IncludePaths: includes, ExcludePaths: slices.Clone(settings.Discovery.ExcludedPaths), ProviderConfiguration: value, Operation: &pluginv1.ComponentOperation{Command: command, Mode: "native"}, Invocation: &pluginv1.Invocation{Environment: env}}, nil + return &pluginv1.DiscoverComponentsRequest{Provider: name, RootDirectory: root, IncludePaths: includes, ExcludePaths: slices.Clone(settings.Discovery.ExcludedPaths), ProviderConfiguration: value, Operation: &pluginv1.ComponentOperation{Command: command, Mode: "native"}, Invocation: &pluginv1.Invocation{Environment: env, LogLevel: adapter.HostLogLevel()}}, nil } diff --git a/pkg/plugin/adapter/configuration/session_test.go b/pkg/plugin/adapter/configuration/session_test.go index 35d48bd7f6d..bbb6008bbf7 100644 --- a/pkg/plugin/adapter/configuration/session_test.go +++ b/pkg/plugin/adapter/configuration/session_test.go @@ -183,7 +183,7 @@ func TestSessionRejectsConflictingDiscovery(t *testing.T) { want error }{ {name: "unsafe stack", change: func(c *pluginv1.DiscoveredComponent) { c.Address.Stack = "../outside" }, want: errUtils.ErrPluginProtocol}, - {name: "unsupported engine", change: func(c *pluginv1.DiscoveredComponent) { c.Engine = "terragrunt" }, want: errUtils.ErrPluginUnsupportedExtension}, + {name: "unsupported engine", change: func(c *pluginv1.DiscoveredComponent) { c.Engine = "pulumi" }, want: errUtils.ErrPluginUnsupportedExtension}, {name: "invalid values", change: func(c *pluginv1.DiscoveredComponent) { c.Configuration = &pluginv1.ComponentValue{} }, want: errUtils.ErrPluginProtocol}, {name: "duplicate", duplicate: true, want: errUtils.ErrDuplicatePluginExtension}, } { diff --git a/pkg/plugin/adapter/configuration/settings.go b/pkg/plugin/adapter/configuration/settings.go index cda57477e41..061172f93ae 100644 --- a/pkg/plugin/adapter/configuration/settings.go +++ b/pkg/plugin/adapter/configuration/settings.go @@ -6,7 +6,10 @@ import ( "slices" "strings" + "google.golang.org/protobuf/proto" + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/component/provideroptions" adapter "github.com/cloudposse/atmos/pkg/plugin/adapter/component" pluginv1 "github.com/cloudposse/atmos/pkg/plugin/proto/atmos/plugin/v1" "github.com/cloudposse/atmos/pkg/schema" @@ -41,8 +44,8 @@ func invalidSetting(key, problem, hint string) error { // validateSettings checks one enabled provider section without starting a plugin. func validateSettings(section string, settings *schema.ComponentConfiguration) error { - if settings.Mode != "" && settings.Mode != "native" { - return invalidSetting(settingsKey(section, "mode"), "Unsupported mode", "The only supported mode is `native`. Remove `mode`, or fix it with `atmos config set "+settingsKey(section, "mode")+" native`.") + if settings.Mode != "" && settings.Mode != provideroptions.ModeNative && settings.Mode != provideroptions.ModeExecutable { + return invalidSetting(settingsKey(section, "mode"), "Unsupported mode", "The supported modes are `native` and `executable`. Remove `mode`, or fix it with `atmos config set "+settingsKey(section, "mode")+" native`.") } for _, field := range []struct { name string @@ -75,6 +78,50 @@ func validateProviderOptions(section string, provider Provider, request *pluginv return nil } +// operationMode is the mode a section runs in; an unset mode is native. +func operationMode(settings *schema.ComponentConfiguration) string { + if settings.Mode == "" { + return provideroptions.ModeNative + } + return settings.Mode +} + +// operationOptions encodes the options the user set explicitly. Only those are sent, so the provider +// can tell an absent option from an explicit false, zero, or empty one. Sensitive values are marked so +// every consumer masks them. +func operationOptions(options map[string]schema.ComponentProviderOption) (map[string]*pluginv1.ComponentValue, error) { + if len(options) == 0 { + return nil, nil + } + result := make(map[string]*pluginv1.ComponentValue, len(options)) + for name, option := range options { + value, err := adapter.EncodeObject(option.Value) + if err != nil { + return nil, err + } + if option.Sensitive { + value.SensitivePaths = []*pluginv1.ComponentValuePath{{}} + } + result[name] = value + } + return result, nil +} + +// providerOperation returns the mode and a copy of the options of the section that enabled a provider. +func (s *Session) providerOperation(provider string) (string, map[string]*pluginv1.ComponentValue) { + for _, request := range s.importProviders { + if request.Provider != provider || request.Operation == nil { + continue + } + options := make(map[string]*pluginv1.ComponentValue, len(request.Operation.Options)) + for name, value := range request.Operation.Options { + options[name] = proto.Clone(value).(*pluginv1.ComponentValue) + } + return request.Operation.Mode, options + } + return provideroptions.ModeNative, nil +} + // sortedSections lists the configured provider sections in stable order. func (s *Session) sortedSections() []string { sections := make([]string, 0, len(s.importProviders)) diff --git a/pkg/plugin/adapter/configuration/state.go b/pkg/plugin/adapter/configuration/state.go index cb0e6ee150c..863c01e51c8 100644 --- a/pkg/plugin/adapter/configuration/state.go +++ b/pkg/plugin/adapter/configuration/state.go @@ -34,6 +34,7 @@ func (s *Session) ResolveState(ctx context.Context, info *schema.ConfigAndStacks if err != nil { return nil, err } + adapter.RenderLogs(logScope(selected.request, info), result.GetLogs()) if result == nil || result.State == nil { return nil, errUtils.ErrPluginProtocol } diff --git a/pkg/plugin/bootstrap/components.go b/pkg/plugin/bootstrap/components.go index cb28bbedf6d..6b07340542b 100644 --- a/pkg/plugin/bootstrap/components.go +++ b/pkg/plugin/bootstrap/components.go @@ -2,16 +2,22 @@ package bootstrap import ( "context" + "errors" "maps" "slices" "strings" + "github.com/spf13/cobra" + errUtils "github.com/cloudposse/atmos/errors" + "github.com/cloudposse/atmos/pkg/component/provideroptions" + log "github.com/cloudposse/atmos/pkg/logger" "github.com/cloudposse/atmos/pkg/perf" authadapter "github.com/cloudposse/atmos/pkg/plugin/adapter/auth" componentadapter "github.com/cloudposse/atmos/pkg/plugin/adapter/component" "github.com/cloudposse/atmos/pkg/plugin/config" "github.com/cloudposse/atmos/pkg/plugin/extension" + "github.com/cloudposse/atmos/pkg/plugin/install" pluginlock "github.com/cloudposse/atmos/pkg/plugin/lock" "github.com/cloudposse/atmos/pkg/plugin/manifest" "github.com/cloudposse/atmos/pkg/schema" @@ -60,6 +66,157 @@ func LoadComponents(ctx context.Context, atmos *schema.AtmosConfiguration, refer return registry, nil } +// ComponentOptions reads the static option declarations of the enabled configuration providers from +// their package manifests. It never installs, restores, verifies, or starts a package, so command +// registration and help stay cheap. A package that is not installed yet contributes nothing; the +// command that uses the provider reports that instead. +func ComponentOptions(ctx context.Context, atmos *schema.AtmosConfiguration) ([]provideroptions.Provider, error) { + defer perf.Track(atmos, "pluginbootstrap.ComponentOptions")() + + wanted := enabledSections(atmos) + if len(wanted) == 0 { + return nil, nil + } + bindings, err := declaredComponentBindings(ctx, atmos, wanted) + if err != nil { + return nil, err + } + var providers []provideroptions.Provider + for _, binding := range bindings { + declared, err := bindingProviders(atmos, &binding, wanted[binding.Name]) + if err != nil { + return nil, err + } + providers = append(providers, declared...) + } + return providers, nil +} + +// enabledSections lists the enabled configuration sections by the provider they use. +func enabledSections(atmos *schema.AtmosConfiguration) map[string][]string { + wanted := make(map[string][]string) + for section, settings := range atmos.Components.Terraform.ConfigurationProviders { + if !settings.Enabled { + continue + } + name := section + if settings.Provider != "" { + name = settings.Provider + } + wanted[name] = append(wanted[name], section) + } + return wanted +} + +// bindingProviders turns one discovery export into a provider for each section that runs a mode it supports. +func bindingProviders(atmos *schema.AtmosConfiguration, binding *extension.Binding, sections []string) ([]provideroptions.Provider, error) { + options, err := provideroptions.Parse(binding.Name, binding.Metadata["options"]) + if err != nil { + return nil, err + } + modes, err := extension.ComponentModes(binding.Metadata) + if err != nil { + return nil, err + } + var providers []provideroptions.Provider + for _, section := range slices.Sorted(slices.Values(sections)) { + mode := atmos.Components.Terraform.ConfigurationProviders[section].Mode + if mode == "" { + mode = provideroptions.ModeNative + } + if slices.Contains(modes, mode) { + providers = append(providers, provideroptions.Provider{Section: section, Name: binding.Name, Mode: mode, Options: options}) + } + } + return providers, nil +} + +// RegisterComponentFlags adds the options of the enabled configuration providers to the subcommands +// of root they apply to. Declaration and collision problems are returned; a package that cannot be +// read is skipped here because the command that uses the provider reports it when it activates. +func RegisterComponentFlags(ctx context.Context, atmos *schema.AtmosConfiguration, root *cobra.Command) error { + defer perf.Track(atmos, "pluginbootstrap.RegisterComponentFlags")() + + providers, err := ComponentOptions(ctx, atmos) + if err != nil { + if errors.Is(err, errUtils.ErrProviderOption) { + return err + } + log.Debug("Skipped provider flag registration", "error", err) + return nil + } + return provideroptions.Register(root, providers) +} + +// declaredComponentBindings lists the discovery exports of the wanted providers from installed manifests. +func declaredComponentBindings(ctx context.Context, atmos *schema.AtmosConfiguration, wanted map[string][]string) ([]extension.Binding, error) { + state, err := readSelections(ctx, atmos) + if err != nil { + return nil, err + } + file, err := pluginlock.Load(ProjectDirectory(atmos)) + if err != nil { + return nil, err + } + cache, err := install.NewCache(atmos.Plugins.CacheDir) + if err != nil { + return nil, err + } + registry, err := Descriptors() + if err != nil { + return nil, err + } + var result []extension.Binding + for _, alias := range slices.Sorted(maps.Keys(atmos.Plugins.Packages)) { + declaration := atmos.Plugins.Packages[alias] + directory := packageDirectory(alias, state, file, cache) + if !enabled(&declaration) || directory == "" { + continue + } + bindings, err := discoveryBindings(registry, directory, wanted) + if err != nil { + return nil, err + } + result = append(result, bindings...) + } + return result, nil +} + +// discoveryBindings reads a package manifest and keeps the discovery exports of the wanted providers. +func discoveryBindings(registry *extension.Registry, directory string, wanted map[string][]string) ([]extension.Binding, error) { + definition, err := manifest.Load(directory) + if err != nil { + return nil, err + } + bindings, err := registry.Discover(definition.Spec.Capabilities) + if err != nil { + return nil, err + } + var result []extension.Binding + for _, binding := range bindings { + if binding.Capability == extension.ComponentDiscovery && wanted[binding.Name] != nil { + result = append(result, binding) + } + } + return result, nil +} + +// packageDirectory returns where an installed package lives, or empty when it is not installed. +func packageDirectory(alias string, state *config.Selections, file *pluginlock.File, cache *install.Cache) string { + if local, exists := state.Packages[alias]; exists { + return local.Path + } + entry, locked := file.Spec.Packages[alias] + if !locked { + return "" + } + directory, err := cache.Installed(&entry, install.CurrentPlatform()) + if err != nil { + return "" + } + return directory +} + func requireComponentReferences(registry *componentadapter.Registry, references []ComponentReference) error { for _, reference := range references { provider, exists := registry.Get(reference.Provider) diff --git a/pkg/plugin/bootstrap/components_test.go b/pkg/plugin/bootstrap/components_test.go index d1fc6859750..3c9925d46a2 100644 --- a/pkg/plugin/bootstrap/components_test.go +++ b/pkg/plugin/bootstrap/components_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/spf13/cobra" "github.com/stretchr/testify/require" errUtils "github.com/cloudposse/atmos/errors" @@ -205,3 +206,92 @@ func TestMalformedComponentMetadataCannotActivate(t *testing.T) { }) } } + +const optionsManifest = `apiVersion: atmos/v1 +kind: AtmosPluginConfig +metadata: + name: fixture/options + version: 1.0.0 +spec: + runtime: {type: native, protocol: 1, executable: bin/plugin} + compatibility: {protocol: ">=1 <2"} + platforms: + PLATFORM: {executable: bin/plugin} + capabilities: + components: + discovery: + tool: + component_type: terraform + schema: schemas/config.json + modes: [native, executable] + options: + - {name: level, type: string, description: Level., commands: [plan, apply], modes: [executable]} + - {name: always, type: bool, description: Always., commands: [plan]} +` + +func optionsFixture(t *testing.T, mode, manifest string) *schema.AtmosConfiguration { + t.Helper() + directory := localPackageFixture(t) + require.NoError(t, os.Mkdir(filepath.Join(directory, "schemas"), 0o700)) + require.NoError(t, os.WriteFile(filepath.Join(directory, "schemas", "config.json"), []byte(`{"type":"object"}`), 0o600)) + require.NoError(t, os.WriteFile(filepath.Join(directory, "plugin.yaml"), []byte(strings.ReplaceAll(manifest, "PLATFORM", install.CurrentPlatform())), 0o600)) + atmos := &schema.AtmosConfiguration{BasePathConfigDir: t.TempDir(), Plugins: schema.PluginsConfig{Packages: map[string]schema.PluginPackage{"fixture": {Path: directory}}}} + atmos.Components.Terraform.ConfigurationProviders = map[string]schema.ComponentConfiguration{"tool": {Enabled: true, Mode: mode}} + return atmos +} + +func TestComponentOptionsReadStaticMetadataWithoutStartingThePlugin(t *testing.T) { + for mode, want := range map[string][]string{"": {"always"}, "native": {"always"}, "executable": {"level", "always"}} { + providers, err := ComponentOptions(t.Context(), optionsFixture(t, mode, optionsManifest)) + require.NoError(t, err, "the fixture executable does not exist, so nothing may start") + require.Len(t, providers, 1) + require.Equal(t, "tool", providers[0].Section) + names := []string{} + for index := range providers[0].Options { + if providers[0].Options[index].AppliesTo(providers[0].Mode) { + names = append(names, providers[0].Options[index].Name) + } + } + require.ElementsMatch(t, want, names, mode) + } +} + +func TestComponentOptionsIgnoreDisabledAndUnknownProviders(t *testing.T) { + atmos := optionsFixture(t, "", optionsManifest) + atmos.Components.Terraform.ConfigurationProviders = map[string]schema.ComponentConfiguration{"tool": {Enabled: false}, "other": {Enabled: true}} + providers, err := ComponentOptions(t.Context(), atmos) + require.NoError(t, err) + require.Empty(t, providers) + atmos.Components.Terraform.ConfigurationProviders = nil + providers, err = ComponentOptions(t.Context(), atmos) + require.NoError(t, err) + require.Nil(t, providers) +} + +func TestRegisterComponentFlagsAddsFlagsAndReportsDeclarationErrors(t *testing.T) { + root := &cobra.Command{Use: "terraform"} + plan := &cobra.Command{Use: "plan"} + root.AddCommand(plan, &cobra.Command{Use: "apply"}) + require.NoError(t, RegisterComponentFlags(t.Context(), optionsFixture(t, "executable", optionsManifest), root)) + require.NotNil(t, plan.Flags().Lookup("tool-level")) + require.NotNil(t, plan.Flags().Lookup("tool-always")) + + broken := strings.ReplaceAll(optionsManifest, "type: string, description: Level.", "type: float, description: Level.") + err := RegisterComponentFlags(t.Context(), optionsFixture(t, "executable", broken), &cobra.Command{Use: "terraform"}) + require.Error(t, err, "a declaration problem is reported") + + // A package that cannot be read does not break unrelated commands; activation reports it later. + missing := optionsFixture(t, "", optionsManifest) + missing.Plugins.Packages["fixture"] = schema.PluginPackage{Path: filepath.Join(t.TempDir(), "absent")} + require.NoError(t, RegisterComponentFlags(t.Context(), missing, &cobra.Command{Use: "terraform"})) +} + +func TestComponentOptionsSkipPackagesThatAreNotInstalled(t *testing.T) { + atmos := optionsFixture(t, "executable", optionsManifest) + // A registry package with no lock entry has nothing on disk to read, and reading never installs it. + atmos.Plugins.Packages["remote"] = schema.PluginPackage{Source: "oci://registry.example.test/atmos/remote", Version: "1.0.0"} + providers, err := ComponentOptions(t.Context(), atmos) + require.NoError(t, err) + require.Len(t, providers, 1) + require.Equal(t, "tool", providers[0].Name) +} diff --git a/pkg/plugin/extension/component.go b/pkg/plugin/extension/component.go index 97b71e5905f..ce26368dab4 100644 --- a/pkg/plugin/extension/component.go +++ b/pkg/plugin/extension/component.go @@ -3,6 +3,7 @@ package extension import ( "strings" + "github.com/cloudposse/atmos/pkg/component/provideroptions" "github.com/cloudposse/atmos/pkg/perf" ) @@ -30,8 +31,8 @@ func ValidateComponent(binding Binding) error { defer perf.Track(nil, "extension.ValidateComponent")() for key := range binding.Metadata { - if key != "component_type" && key != "schema" { - return invalidMetadata("Unsupported component configuration export metadata.", "Declare only `component_type` and `schema` for this contract version.") + if key != "component_type" && key != "schema" && key != "modes" && key != "options" { + return invalidMetadata("Unsupported component configuration export metadata.", "Declare only `component_type`, `schema`, `modes`, and `options` for this contract version.") } } componentType, ok := binding.Metadata["component_type"].(string) @@ -42,6 +43,36 @@ func ValidateComponent(binding Binding) error { if !ok { return invalidMetadata("The configuration export has no `schema` path.", "Declare a package-local JSON Schema for provider settings.") } - _, err := CompileSchema(binding.Directory, schemaPath) + if _, err := CompileSchema(binding.Directory, schemaPath); err != nil { + return err + } + if _, err := ComponentModes(binding.Metadata); err != nil { + return err + } + _, err := provideroptions.Parse(binding.Name, binding.Metadata["options"]) return err } + +// ComponentModes returns the execution modes a configuration export declares. An export that declares +// none supports only the native mode. +func ComponentModes(metadata map[string]any) ([]string, error) { + defer perf.Track(nil, "extension.ComponentModes")() + + raw, declared := metadata["modes"] + if !declared { + return []string{provideroptions.ModeNative}, nil + } + items, ok := raw.([]any) + if !ok || len(items) == 0 { + return nil, invalidMetadata("The configuration export declares `modes` incorrectly.", "List one or more of `native` and `executable`.") + } + modes := make([]string, 0, len(items)) + for _, item := range items { + mode, _ := item.(string) + if mode != provideroptions.ModeNative && mode != provideroptions.ModeExecutable { + return nil, invalidMetadata("The configuration export declares an unknown mode.", "List one or more of `native` and `executable`.") + } + modes = append(modes, mode) + } + return modes, nil +} diff --git a/pkg/plugin/extension/component_test.go b/pkg/plugin/extension/component_test.go index a0aced90288..4603e638d22 100644 --- a/pkg/plugin/extension/component_test.go +++ b/pkg/plugin/extension/component_test.go @@ -42,3 +42,43 @@ func TestComponentServicesAreIndependentOfExecution(t *testing.T) { require.False(t, IsComponent(capability)) } } + +func TestComponentMetadataValidatesModesAndOptions(t *testing.T) { + t.Parallel() + directory := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(directory, "config.json"), []byte(`{"type":"object"}`), 0o600)) + base := func(extra map[string]any) map[string]any { + metadata := map[string]any{"component_type": "terraform", "schema": "config.json"} + for key, value := range extra { + metadata[key] = value + } + return metadata + } + option := map[string]any{"name": "level", "type": "string", "description": "Level.", "commands": []any{"plan"}} + require.NoError(t, ValidateComponent(Binding{Name: "tool", Directory: directory, Metadata: base(map[string]any{ + "modes": []any{"native", "executable"}, "options": []any{option}, + })})) + for name, extra := range map[string]map[string]any{ + "unknown mode": {"modes": []any{"fast"}}, + "empty modes": {"modes": []any{}}, + "modes not a list": {"modes": "native"}, + "options not a list": {"options": "level"}, + "option without help": {"options": []any{map[string]any{"name": "level", "type": "string", "commands": []any{"plan"}}}}, + } { + t.Run(name, func(t *testing.T) { + t.Parallel() + err := ValidateComponent(Binding{Name: "tool", Directory: directory, Metadata: base(extra)}) + require.Error(t, err) + }) + } +} + +func TestComponentModesDefaultToNative(t *testing.T) { + t.Parallel() + modes, err := ComponentModes(map[string]any{}) + require.NoError(t, err) + require.Equal(t, []string{"native"}, modes) + modes, err = ComponentModes(map[string]any{"modes": []any{"executable", "native"}}) + require.NoError(t, err) + require.Equal(t, []string{"executable", "native"}, modes) +} diff --git a/pkg/plugin/oci/inspect.go b/pkg/plugin/oci/inspect.go index bd6a7a50df4..215b6a6b35b 100644 --- a/pkg/plugin/oci/inspect.go +++ b/pkg/plugin/oci/inspect.go @@ -164,7 +164,16 @@ func inspectDefinition(release *Release, annotations map[string]string) error { if err != nil { return err } - if !maps.Equal(annotations, releaseAnnotations(definition, release.Manifest)) { + expected := releaseAnnotations(definition, release.Manifest) + // The publisher may override the manifest repository with an explicit source; + // it is still held to the same publishable shape. + if source, overridden := annotations[annotationSource]; overridden { + if _, ok := publishableSource(source); !ok { + return errUtils.ErrOCIIntegrity + } + expected[annotationSource] = source + } + if !maps.Equal(annotations, expected) { return errUtils.ErrOCIIntegrity } if len(definition.Spec.Platforms) != len(release.Platforms) { diff --git a/pkg/plugin/oci/metadata_test.go b/pkg/plugin/oci/metadata_test.go index d44648ed43a..5df0a6b0e0b 100644 --- a/pkg/plugin/oci/metadata_test.go +++ b/pkg/plugin/oci/metadata_test.go @@ -5,9 +5,12 @@ import ( "path/filepath" "testing" + v1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/mutate" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" + errUtils "github.com/cloudposse/atmos/errors" "github.com/cloudposse/atmos/pkg/plugin/manifest" pluginoci "github.com/cloudposse/atmos/pkg/plugin/oci" ) @@ -37,3 +40,135 @@ func TestReleasePreservesAuthoredMetadataAcrossPlatforms(t *testing.T) { require.Equal(t, definition.Metadata, installed.Metadata) } } + +const ( + annotationSource = "org.opencontainers.image.source" + annotationTitle = "org.opencontainers.image.title" + annotationDescription = "org.opencontainers.image.description" + annotationImgVersion = "org.opencontainers.image.version" +) + +func writeMetadata(t *testing.T, directory string, mutate func(*manifest.Config)) { + t.Helper() + definition, err := manifest.Load(directory) + require.NoError(t, err) + mutate(definition) + raw, err := yaml.Marshal(definition) + require.NoError(t, err) + require.NoError(t, os.WriteFile(filepath.Join(directory, "plugin.yaml"), raw, 0o600)) +} + +// indexAnnotations returns the annotations on the index, each platform descriptor, and each platform manifest. +func indexAnnotations(t *testing.T, index v1.ImageIndex) []map[string]string { + t.Helper() + root, err := index.IndexManifest() + require.NoError(t, err) + result := []map[string]string{root.Annotations} + for position := range root.Manifests { + descriptor := &root.Manifests[position] + result = append(result, descriptor.Annotations) + image, err := index.Image(descriptor.Digest) + require.NoError(t, err) + imageManifest, err := image.Manifest() + require.NoError(t, err) + result = append(result, imageManifest.Annotations) + } + require.Len(t, result, 5) + return result +} + +func TestReleaseLinksPackageToRepositoryFromManifestMetadata(t *testing.T) { + directory, descriptors := packageFixture(t) + writeMetadata(t, directory, func(definition *manifest.Config) { + definition.Metadata.DisplayName = "Fixture" + definition.Metadata.Description = "A fixture plugin" + definition.Metadata.Repository = "https://github.com/example/atmos-fixture" + }) + index, err := pluginoci.BuildIndex(directory, descriptors) + require.NoError(t, err) + for _, annotations := range indexAnnotations(t, index) { + require.Equal(t, "https://github.com/example/atmos-fixture", annotations[annotationSource]) + require.Equal(t, "Fixture", annotations[annotationTitle]) + require.Equal(t, "A fixture plugin", annotations[annotationDescription]) + require.Equal(t, "1.2.3", annotations[annotationImgVersion]) + } + _, err = pluginoci.Inspect(index, "") + require.NoError(t, err, "derived annotations are part of the verified release shape") +} + +func TestReleaseOmitsSourceWithoutHTTPSRepository(t *testing.T) { + for name, repository := range map[string]string{"absent": "", "ssh": "git@github.com:example/atmos-fixture.git", "plain http": "http://github.com/example/x", "credentials": "https://user:token@github.com/example/x"} { + t.Run(name, func(t *testing.T) { + directory, descriptors := packageFixture(t) + writeMetadata(t, directory, func(definition *manifest.Config) { definition.Metadata.Repository = repository }) + index, err := pluginoci.BuildIndex(directory, descriptors) + require.NoError(t, err) + for _, annotations := range indexAnnotations(t, index) { + require.NotContains(t, annotations, annotationSource, "an unlinkable or credentialed repository must never be published") + } + _, err = pluginoci.Inspect(index, "") + require.NoError(t, err) + }) + } +} + +func TestWithSourceOverridesManifestRepository(t *testing.T) { + directory, descriptors := packageFixture(t) + writeMetadata(t, directory, func(definition *manifest.Config) { definition.Metadata.Repository = "https://github.com/example/old" }) + index, err := pluginoci.BuildIndex(directory, descriptors, pluginoci.WithSource("https://github.com/example/new")) + require.NoError(t, err) + for _, annotations := range indexAnnotations(t, index) { + require.Equal(t, "https://github.com/example/new", annotations[annotationSource]) + } + _, err = pluginoci.Inspect(index, "") + require.NoError(t, err) + plain, err := pluginoci.BuildIndex(directory, descriptors) + require.NoError(t, err) + require.NotEqual(t, mustDigest(t, plain), mustDigest(t, index), "the explicit source is part of the release digest") +} + +func TestWithSourceRejectsUnsafeValues(t *testing.T) { + directory, descriptors := packageFixture(t) + for _, source := range []string{"http://github.com/example/x", "https://user:token@github.com/example/x", "https://github.com/example/x?token=1", "https://github.com/example/x#frag", "ssh://github.com/example/x", "not a url", "https://"} { + t.Run(source, func(t *testing.T) { + _, err := pluginoci.BuildIndex(directory, descriptors, pluginoci.WithSource(source)) + require.ErrorIs(t, err, errUtils.ErrPluginInvalidConfig) + }) + } +} + +func TestInspectRejectsTamperedSourceAnnotation(t *testing.T) { + directory, descriptors := packageFixture(t) + index, err := pluginoci.BuildIndex(directory, descriptors, pluginoci.WithSource("https://github.com/example/new")) + require.NoError(t, err) + for _, forged := range []string{"https://user:token@github.com/example/new", "http://github.com/example/new"} { + root, err := index.IndexManifest() + require.NoError(t, err) + annotations := map[string]string{} + for key, value := range root.Annotations { + annotations[key] = value + } + annotations[annotationSource] = forged + tampered := mutate.Annotations(index, annotations).(v1.ImageIndex) + _, err = pluginoci.Inspect(tampered, "") + require.Error(t, err, forged) + } +} + +func TestGitHubActionsSourceIsDerivedOnlyFromExplicitEnvironment(t *testing.T) { + environment := func(values map[string]string) func(string) string { + return func(key string) string { return values[key] } + } + require.Equal(t, "https://github.com/cloudposse/atmos", pluginoci.GitHubActionsSource(environment(map[string]string{"GITHUB_REPOSITORY": "cloudposse/atmos"}))) + require.Equal(t, "https://ghe.example.com/team/repo", pluginoci.GitHubActionsSource(environment(map[string]string{"GITHUB_SERVER_URL": "https://ghe.example.com/", "GITHUB_REPOSITORY": "team/repo"}))) + require.Empty(t, pluginoci.GitHubActionsSource(environment(nil)), "outside GitHub Actions nothing is derived") + require.Empty(t, pluginoci.GitHubActionsSource(environment(map[string]string{"GITHUB_REPOSITORY": "not-a-slug"}))) + require.Empty(t, pluginoci.GitHubActionsSource(environment(map[string]string{"GITHUB_SERVER_URL": "http://insecure.example.com", "GITHUB_REPOSITORY": "a/b"}))) +} + +func mustDigest(t *testing.T, index v1.ImageIndex) string { + t.Helper() + digest, err := index.Digest() + require.NoError(t, err) + return digest.String() +} diff --git a/pkg/plugin/oci/pack.go b/pkg/plugin/oci/pack.go index c75c39e8efc..78b6286c80f 100644 --- a/pkg/plugin/oci/pack.go +++ b/pkg/plugin/oci/pack.go @@ -8,11 +8,13 @@ import ( "errors" "fmt" "maps" + "net/url" "os" "path/filepath" "slices" "sort" "strings" + "unicode" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/empty" @@ -32,12 +34,17 @@ const ( // ConfigMediaType identifies a plugin platform image's static configuration. ConfigMediaType types.MediaType = "application/vnd.atmos.plugin.config.v1+json" // BundleMediaType identifies a bounded, uncompressed package archive. - BundleMediaType types.MediaType = "application/vnd.atmos.plugin.bundle.v1+tar" - annotationName = "dev.atmos.plugin.name" - annotationVersion = "dev.atmos.plugin.version" - annotationManifest = "dev.atmos.plugin.manifest.digest" - manifestLabel = "dev.atmos.plugin.manifest" - maxBundleSize = 256 << 20 + BundleMediaType types.MediaType = "application/vnd.atmos.plugin.bundle.v1+tar" + annotationName = "dev.atmos.plugin.name" + annotationVersion = "dev.atmos.plugin.version" + annotationManifest = "dev.atmos.plugin.manifest.digest" + annotationSource = "org.opencontainers.image.source" + annotationTitle = "org.opencontainers.image.title" + annotationDescription = "org.opencontainers.image.description" + annotationImageVersion = "org.opencontainers.image.version" + maxSourceLength = 512 + manifestLabel = "dev.atmos.plugin.manifest" + maxBundleSize = 256 << 20 ) // Option adjusts how packing and publishing verify a release. @@ -45,6 +52,62 @@ type Option func(*options) type options struct { checkExecutableFormat bool + source string +} + +// WithSource sets the org.opencontainers.image.source annotation, the metadata +// registries such as GHCR use to link a package to its repository. It overrides +// the repository declared in the plugin manifest. The value must be a plain +// https URL: credentials, query strings, and fragments are rejected so a +// release never publishes anything private. +func WithSource(source string) Option { + defer perf.Track(nil, "pluginoci.WithSource")() + + return func(o *options) { o.source = source } +} + +// GitHubActionsSource derives the repository URL from the GitHub Actions +// environment (GITHUB_SERVER_URL, defaulting to https://github.com, and +// GITHUB_REPOSITORY). It returns an empty string outside GitHub Actions or for +// a value that is not a safe https URL. Callers opt in explicitly; packing +// itself never reads the environment. +func GitHubActionsSource(getenv func(string) string) string { + defer perf.Track(nil, "pluginoci.GitHubActionsSource")() + + slug := getenv("GITHUB_REPOSITORY") + if strings.Count(slug, "/") != 1 || strings.HasPrefix(slug, "/") || strings.HasSuffix(slug, "/") { + return "" + } + server := strings.TrimRight(getenv("GITHUB_SERVER_URL"), "/") + if server == "" { + server = "https://github.com" + } + source, ok := publishableSource(server + "/" + slug) + if !ok { + return "" + } + return source +} + +// publishableSource reports whether a repository reference is safe to publish as the +// image source: an https URL with a host and without credentials, query, or fragment. +func publishableSource(raw string) (string, bool) { + if raw == "" || len(raw) > maxSourceLength || strings.ContainsFunc(raw, unicode.IsSpace) { + return "", false + } + parsed, err := url.Parse(raw) + if err != nil || !plainHTTPSURL(parsed) { + return "", false + } + return raw, true +} + +// plainHTTPSURL reports whether a parsed URL is https with a host and carries nothing but a location. +func plainHTTPSURL(parsed *url.URL) bool { + if parsed.Scheme != "https" || parsed.Host == "" || parsed.User != nil { + return false + } + return parsed.RawQuery == "" && !parsed.ForceQuery && parsed.Fragment == "" } // WithExecutableFormatCheck requires every platform executable to be a native @@ -114,6 +177,13 @@ func BuildIndex(directory string, descriptors *extension.Registry, opts ...Optio return nil, err } annotations := releaseAnnotations(definition, files["plugin.yaml"]) + if configured.source != "" { + source, ok := publishableSource(configured.source) + if !ok { + return nil, fmt.Errorf("%w: the package source must be an https URL without credentials, query, or fragment", errUtils.ErrPluginInvalidConfig) + } + annotations[annotationSource] = source + } platforms := make([]string, 0, len(definition.Spec.Platforms)) for platform := range definition.Spec.Platforms { platforms = append(platforms, platform) @@ -125,7 +195,7 @@ func BuildIndex(directory string, descriptors *extension.Registry, opts ...Optio if err != nil { return nil, err } - img, err := platformImage(directory, definition, parsed, files, configured) + img, err := platformImage(&releaseBuild{directory: directory, definition: definition, files: files, annotations: annotations, options: configured}, parsed) if err != nil { return nil, err } @@ -152,12 +222,38 @@ func parsePlatform(value string) (*v1.Platform, error) { return &v1.Platform{OS: target.OS, Architecture: target.Architecture, Variant: target.Variant}, nil } +// releaseAnnotations derives every annotation from the verified manifest bytes, so a +// release can be re-checked from the manifest alone. The OCI image annotations let +// registries show the package title and link it to its repository. func releaseAnnotations(definition *manifest.Config, raw []byte) map[string]string { digest := sha256.Sum256(raw) - return map[string]string{annotationName: definition.Metadata.Name, annotationVersion: definition.Metadata.Version, annotationManifest: "sha256:" + hex.EncodeToString(digest[:])} + annotations := map[string]string{ + annotationName: definition.Metadata.Name, annotationVersion: definition.Metadata.Version, annotationManifest: "sha256:" + hex.EncodeToString(digest[:]), + annotationTitle: definition.Metadata.Name, annotationImageVersion: definition.Metadata.Version, + } + if definition.Metadata.DisplayName != "" { + annotations[annotationTitle] = definition.Metadata.DisplayName + } + if definition.Metadata.Description != "" { + annotations[annotationDescription] = definition.Metadata.Description + } + if source, ok := publishableSource(definition.Metadata.Repository); ok { + annotations[annotationSource] = source + } + return annotations +} + +// releaseBuild carries the inputs shared by every platform image of one release. +type releaseBuild struct { + directory string + definition *manifest.Config + files map[string][]byte + annotations map[string]string + options *options } -func platformImage(directory string, definition *manifest.Config, parsed *v1.Platform, files map[string][]byte, configured *options) (v1.Image, error) { +func platformImage(build *releaseBuild, parsed *v1.Platform) (v1.Image, error) { + directory, definition, files, configured := build.directory, build.definition, build.files, build.options selection := definition.Spec.Platforms[parsed.String()] executable, err := readPackageFile(directory, selection.Executable, maxBundleSize) if err != nil { @@ -191,7 +287,7 @@ func platformImage(directory string, definition *manifest.Config, parsed *v1.Pla return nil, err } img = mutate.ConfigMediaType(mutate.MediaType(img, types.OCIManifestSchema1), ConfigMediaType) - return mutate.Annotations(img, releaseAnnotations(definition, files["plugin.yaml"])).(v1.Image), nil + return mutate.Annotations(img, build.annotations).(v1.Image), nil } func checkPackedExecutable(name string, executable []byte, platform *v1.Platform) error { diff --git a/pkg/plugin/proto/atmos/plugin/v1/plugin.pb.go b/pkg/plugin/proto/atmos/plugin/v1/plugin.pb.go index b4b5f535362..001d7def3a9 100644 --- a/pkg/plugin/proto/atmos/plugin/v1/plugin.pb.go +++ b/pkg/plugin/proto/atmos/plugin/v1/plugin.pb.go @@ -25,6 +25,65 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// LogLevel is the severity of a LogEntry, from most to least verbose. +type LogLevel int32 + +const ( + LogLevel_LOG_LEVEL_UNSPECIFIED LogLevel = 0 + LogLevel_LOG_LEVEL_TRACE LogLevel = 1 + LogLevel_LOG_LEVEL_DEBUG LogLevel = 2 + LogLevel_LOG_LEVEL_INFO LogLevel = 3 + LogLevel_LOG_LEVEL_WARN LogLevel = 4 + LogLevel_LOG_LEVEL_ERROR LogLevel = 5 +) + +// Enum value maps for LogLevel. +var ( + LogLevel_name = map[int32]string{ + 0: "LOG_LEVEL_UNSPECIFIED", + 1: "LOG_LEVEL_TRACE", + 2: "LOG_LEVEL_DEBUG", + 3: "LOG_LEVEL_INFO", + 4: "LOG_LEVEL_WARN", + 5: "LOG_LEVEL_ERROR", + } + LogLevel_value = map[string]int32{ + "LOG_LEVEL_UNSPECIFIED": 0, + "LOG_LEVEL_TRACE": 1, + "LOG_LEVEL_DEBUG": 2, + "LOG_LEVEL_INFO": 3, + "LOG_LEVEL_WARN": 4, + "LOG_LEVEL_ERROR": 5, + } +) + +func (x LogLevel) Enum() *LogLevel { + p := new(LogLevel) + *p = x + return p +} + +func (x LogLevel) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (LogLevel) Descriptor() protoreflect.EnumDescriptor { + return file_atmos_plugin_v1_plugin_proto_enumTypes[0].Descriptor() +} + +func (LogLevel) Type() protoreflect.EnumType { + return &file_atmos_plugin_v1_plugin_proto_enumTypes[0] +} + +func (x LogLevel) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use LogLevel.Descriptor instead. +func (LogLevel) EnumDescriptor() ([]byte, []int) { + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} +} + // Severity classifies an ErrorDetail. A WARNING never fails a command: the host // prints it on the UI channel and continues. An ERROR fails the commands that // target the named unit, or the whole command when no unit is named. @@ -61,11 +120,11 @@ func (x Severity) String() string { } func (Severity) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[0].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[1].Descriptor() } func (Severity) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[0] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[1] } func (x Severity) Number() protoreflect.EnumNumber { @@ -74,7 +133,7 @@ func (x Severity) Number() protoreflect.EnumNumber { // Deprecated: Use Severity.Descriptor instead. func (Severity) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{1} } type ComponentSource_Kind int32 @@ -113,11 +172,11 @@ func (x ComponentSource_Kind) String() string { } func (ComponentSource_Kind) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[1].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[2].Descriptor() } func (ComponentSource_Kind) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[1] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[2] } func (x ComponentSource_Kind) Number() protoreflect.EnumNumber { @@ -126,7 +185,7 @@ func (x ComponentSource_Kind) Number() protoreflect.EnumNumber { // Deprecated: Use ComponentSource_Kind.Descriptor instead. func (ComponentSource_Kind) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32, 0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33, 0} } type ComponentDependency_Kind int32 @@ -162,11 +221,11 @@ func (x ComponentDependency_Kind) String() string { } func (ComponentDependency_Kind) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[2].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[3].Descriptor() } func (ComponentDependency_Kind) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[2] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[3] } func (x ComponentDependency_Kind) Number() protoreflect.EnumNumber { @@ -175,7 +234,7 @@ func (x ComponentDependency_Kind) Number() protoreflect.EnumNumber { // Deprecated: Use ComponentDependency_Kind.Descriptor instead. func (ComponentDependency_Kind) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33, 0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34, 0} } // Invocation identifies the live call authorized to use the Atmos API broker. @@ -190,8 +249,13 @@ type Invocation struct { Component string `protobuf:"bytes,7,opt,name=component,proto3" json:"component,omitempty"` ComponentType string `protobuf:"bytes,8,opt,name=component_type,json=componentType,proto3" json:"component_type,omitempty"` Interactive bool `protobuf:"varint,9,opt,name=interactive,proto3" json:"interactive,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // The host's effective log level: "trace", "debug", "info", "warn", "error", or "off". Engine log events + // are diagnostic chatter, so a plugin returns LogEntry messages only for "debug" and "trace" and none + // for any other level, including the Atmos default "warn". Anything the user must act on belongs in a + // Diagnostic or an ErrorDetail instead. The host filters entries by its level as well. + LogLevel string `protobuf:"bytes,10,opt,name=log_level,json=logLevel,proto3" json:"log_level,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Invocation) Reset() { @@ -287,6 +351,13 @@ func (x *Invocation) GetInteractive() bool { return false } +func (x *Invocation) GetLogLevel() string { + if x != nil { + return x.LogLevel + } + return "" +} + type Credentials struct { state protoimpl.MessageState `protogen:"open.v1"` Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` @@ -1096,6 +1167,91 @@ func (x *SourceLocation) GetColumn() uint32 { return 0 } +// LogEntry is one structured log event from a plugin's engine, for example a Terragrunt logger event. +// A response carries the entries produced while it was computed, in order. The host renders them through +// the Atmos logger on the UI channel (stderr), scoped to the component and stack of the call, with secret +// masking, at the level each entry carries. They are hidden at the Atmos default level and shown with +// --logs-level=Debug or Trace. Entries never change the outcome of the call and are never written to the +// data channel. +// A plugin must not put evaluated values in message or fields; the host masks them anyway. +type LogEntry struct { + state protoimpl.MessageState `protogen:"open.v1"` + Level LogLevel `protobuf:"varint,1,opt,name=level,proto3,enum=atmos.plugin.v1.LogLevel" json:"level,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + // Structured fields of the event, rendered as key/value pairs. + Fields map[string]string `protobuf:"bytes,3,rep,name=fields,proto3" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Time *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=time,proto3" json:"time,omitempty"` + // Unit the event is about, relative to the project root, when the engine reports one. + Unit string `protobuf:"bytes,5,opt,name=unit,proto3" json:"unit,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LogEntry) Reset() { + *x = LogEntry{} + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LogEntry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogEntry) ProtoMessage() {} + +func (x *LogEntry) ProtoReflect() protoreflect.Message { + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LogEntry.ProtoReflect.Descriptor instead. +func (*LogEntry) Descriptor() ([]byte, []int) { + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{13} +} + +func (x *LogEntry) GetLevel() LogLevel { + if x != nil { + return x.Level + } + return LogLevel_LOG_LEVEL_UNSPECIFIED +} + +func (x *LogEntry) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *LogEntry) GetFields() map[string]string { + if x != nil { + return x.Fields + } + return nil +} + +func (x *LogEntry) GetTime() *timestamppb.Timestamp { + if x != nil { + return x.Time + } + return nil +} + +func (x *LogEntry) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + // ErrorDetail is the structured, user-facing description of a plugin failure. // A plugin returns it as a gRPC status detail (google.rpc.Status.details) on a // failed call, or inside Diagnostic.detail for a per-item failure that must not @@ -1130,14 +1286,18 @@ type ErrorDetail struct { // The operation that failed, such as "discover", "prepare", or "validate". Operation string `protobuf:"bytes,10,opt,name=operation,proto3" json:"operation,omitempty"` // Severity of the problem. Unset means ERROR. - Severity Severity `protobuf:"varint,11,opt,name=severity,proto3,enum=atmos.plugin.v1.Severity" json:"severity,omitempty"` + Severity Severity `protobuf:"varint,11,opt,name=severity,proto3,enum=atmos.plugin.v1.Severity" json:"severity,omitempty"` + // Log entries produced before the failure, in order. Only a failed call's status detail carries them, + // so that Debug and Trace output explains the failure. The host renders them like LogEntry messages + // of a successful response. + Logs []*LogEntry `protobuf:"bytes,12,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ErrorDetail) Reset() { *x = ErrorDetail{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1149,7 +1309,7 @@ func (x *ErrorDetail) String() string { func (*ErrorDetail) ProtoMessage() {} func (x *ErrorDetail) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1162,7 +1322,7 @@ func (x *ErrorDetail) ProtoReflect() protoreflect.Message { // Deprecated: Use ErrorDetail.ProtoReflect.Descriptor instead. func (*ErrorDetail) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{13} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{14} } func (x *ErrorDetail) GetCode() string { @@ -1242,6 +1402,13 @@ func (x *ErrorDetail) GetSeverity() Severity { return Severity_SEVERITY_UNSPECIFIED } +func (x *ErrorDetail) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + // Diagnostic describes one problem. field and message keep their original meaning; // detail adds the structured form and takes precedence when present. type Diagnostic struct { @@ -1255,7 +1422,7 @@ type Diagnostic struct { func (x *Diagnostic) Reset() { *x = Diagnostic{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1267,7 +1434,7 @@ func (x *Diagnostic) String() string { func (*Diagnostic) ProtoMessage() {} func (x *Diagnostic) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1280,7 +1447,7 @@ func (x *Diagnostic) ProtoReflect() protoreflect.Message { // Deprecated: Use Diagnostic.ProtoReflect.Descriptor instead. func (*Diagnostic) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{14} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{15} } func (x *Diagnostic) GetField() string { @@ -1313,7 +1480,7 @@ type ValidateResponse struct { func (x *ValidateResponse) Reset() { *x = ValidateResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1325,7 +1492,7 @@ func (x *ValidateResponse) String() string { func (*ValidateResponse) ProtoMessage() {} func (x *ValidateResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1338,7 +1505,7 @@ func (x *ValidateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ValidateResponse.ProtoReflect.Descriptor instead. func (*ValidateResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{15} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{16} } func (x *ValidateResponse) GetDiagnostics() []*Diagnostic { @@ -1358,7 +1525,7 @@ type Unsupported struct { func (x *Unsupported) Reset() { *x = Unsupported{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1370,7 +1537,7 @@ func (x *Unsupported) String() string { func (*Unsupported) ProtoMessage() {} func (x *Unsupported) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1383,7 +1550,7 @@ func (x *Unsupported) ProtoReflect() protoreflect.Message { // Deprecated: Use Unsupported.ProtoReflect.Descriptor instead. func (*Unsupported) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{16} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{17} } func (x *Unsupported) GetOperation() string { @@ -1410,7 +1577,7 @@ type RefreshRequest struct { func (x *RefreshRequest) Reset() { *x = RefreshRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1422,7 +1589,7 @@ func (x *RefreshRequest) String() string { func (*RefreshRequest) ProtoMessage() {} func (x *RefreshRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1435,7 +1602,7 @@ func (x *RefreshRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RefreshRequest.ProtoReflect.Descriptor instead. func (*RefreshRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{17} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{18} } func (x *RefreshRequest) GetProvider() *ProviderRequest { @@ -1465,7 +1632,7 @@ type RefreshResponse struct { func (x *RefreshResponse) Reset() { *x = RefreshResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1477,7 +1644,7 @@ func (x *RefreshResponse) String() string { func (*RefreshResponse) ProtoMessage() {} func (x *RefreshResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1490,7 +1657,7 @@ func (x *RefreshResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RefreshResponse.ProtoReflect.Descriptor instead. func (*RefreshResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{18} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{19} } func (x *RefreshResponse) GetResult() isRefreshResponse_Result { @@ -1543,7 +1710,7 @@ type EnvironmentResponse struct { func (x *EnvironmentResponse) Reset() { *x = EnvironmentResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1555,7 +1722,7 @@ func (x *EnvironmentResponse) String() string { func (*EnvironmentResponse) ProtoMessage() {} func (x *EnvironmentResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1568,7 +1735,7 @@ func (x *EnvironmentResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EnvironmentResponse.ProtoReflect.Descriptor instead. func (*EnvironmentResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{19} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{20} } func (x *EnvironmentResponse) GetEnvironment() map[string]string { @@ -1588,7 +1755,7 @@ type PrepareEnvironmentRequest struct { func (x *PrepareEnvironmentRequest) Reset() { *x = PrepareEnvironmentRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1600,7 +1767,7 @@ func (x *PrepareEnvironmentRequest) String() string { func (*PrepareEnvironmentRequest) ProtoMessage() {} func (x *PrepareEnvironmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1613,7 +1780,7 @@ func (x *PrepareEnvironmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PrepareEnvironmentRequest.ProtoReflect.Descriptor instead. func (*PrepareEnvironmentRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{20} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{21} } func (x *PrepareEnvironmentRequest) GetProvider() *ProviderRequest { @@ -1642,7 +1809,7 @@ type CredentialPath struct { func (x *CredentialPath) Reset() { *x = CredentialPath{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1654,7 +1821,7 @@ func (x *CredentialPath) String() string { func (*CredentialPath) ProtoMessage() {} func (x *CredentialPath) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1667,7 +1834,7 @@ func (x *CredentialPath) ProtoReflect() protoreflect.Message { // Deprecated: Use CredentialPath.ProtoReflect.Descriptor instead. func (*CredentialPath) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{21} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{22} } func (x *CredentialPath) GetLocation() string { @@ -1707,7 +1874,7 @@ type PathsResponse struct { func (x *PathsResponse) Reset() { *x = PathsResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1719,7 +1886,7 @@ func (x *PathsResponse) String() string { func (*PathsResponse) ProtoMessage() {} func (x *PathsResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1732,7 +1899,7 @@ func (x *PathsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PathsResponse.ProtoReflect.Descriptor instead. func (*PathsResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{22} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{23} } func (x *PathsResponse) GetPaths() []*CredentialPath { @@ -1752,7 +1919,7 @@ type IdentityAuthenticateRequest struct { func (x *IdentityAuthenticateRequest) Reset() { *x = IdentityAuthenticateRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1764,7 +1931,7 @@ func (x *IdentityAuthenticateRequest) String() string { func (*IdentityAuthenticateRequest) ProtoMessage() {} func (x *IdentityAuthenticateRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1777,7 +1944,7 @@ func (x *IdentityAuthenticateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use IdentityAuthenticateRequest.ProtoReflect.Descriptor instead. func (*IdentityAuthenticateRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{23} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{24} } func (x *IdentityAuthenticateRequest) GetIdentity() *IdentityRequest { @@ -1804,7 +1971,7 @@ type IdentityPrepareRequest struct { func (x *IdentityPrepareRequest) Reset() { *x = IdentityPrepareRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1816,7 +1983,7 @@ func (x *IdentityPrepareRequest) String() string { func (*IdentityPrepareRequest) ProtoMessage() {} func (x *IdentityPrepareRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1829,7 +1996,7 @@ func (x *IdentityPrepareRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use IdentityPrepareRequest.ProtoReflect.Descriptor instead. func (*IdentityPrepareRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{24} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{25} } func (x *IdentityPrepareRequest) GetIdentity() *IdentityRequest { @@ -1859,7 +2026,7 @@ type CommandRequest struct { func (x *CommandRequest) Reset() { *x = CommandRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1871,7 +2038,7 @@ func (x *CommandRequest) String() string { func (*CommandRequest) ProtoMessage() {} func (x *CommandRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1884,7 +2051,7 @@ func (x *CommandRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead. func (*CommandRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{25} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{26} } func (x *CommandRequest) GetInvocation() *Invocation { @@ -1924,7 +2091,7 @@ type CommandExit struct { func (x *CommandExit) Reset() { *x = CommandExit{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1936,7 +2103,7 @@ func (x *CommandExit) String() string { func (*CommandExit) ProtoMessage() {} func (x *CommandExit) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1949,7 +2116,7 @@ func (x *CommandExit) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandExit.ProtoReflect.Descriptor instead. func (*CommandExit) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{26} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{27} } func (x *CommandExit) GetCode() uint32 { @@ -1973,7 +2140,7 @@ type CommandEvent struct { func (x *CommandEvent) Reset() { *x = CommandEvent{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1985,7 +2152,7 @@ func (x *CommandEvent) String() string { func (*CommandEvent) ProtoMessage() {} func (x *CommandEvent) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1998,7 +2165,7 @@ func (x *CommandEvent) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandEvent.ProtoReflect.Descriptor instead. func (*CommandEvent) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{27} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{28} } func (x *CommandEvent) GetEvent() isCommandEvent_Event { @@ -2072,7 +2239,7 @@ type ComponentValue struct { func (x *ComponentValue) Reset() { *x = ComponentValue{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2084,7 +2251,7 @@ func (x *ComponentValue) String() string { func (*ComponentValue) ProtoMessage() {} func (x *ComponentValue) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2097,7 +2264,7 @@ func (x *ComponentValue) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValue.ProtoReflect.Descriptor instead. func (*ComponentValue) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{28} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{29} } func (x *ComponentValue) GetTypeJson() []byte { @@ -2130,7 +2297,7 @@ type ComponentValuePath struct { func (x *ComponentValuePath) Reset() { *x = ComponentValuePath{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2142,7 +2309,7 @@ func (x *ComponentValuePath) String() string { func (*ComponentValuePath) ProtoMessage() {} func (x *ComponentValuePath) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2155,7 +2322,7 @@ func (x *ComponentValuePath) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValuePath.ProtoReflect.Descriptor instead. func (*ComponentValuePath) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{29} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{30} } func (x *ComponentValuePath) GetSteps() []*ComponentValueStep { @@ -2178,7 +2345,7 @@ type ComponentValueStep struct { func (x *ComponentValueStep) Reset() { *x = ComponentValueStep{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2190,7 +2357,7 @@ func (x *ComponentValueStep) String() string { func (*ComponentValueStep) ProtoMessage() {} func (x *ComponentValueStep) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2203,7 +2370,7 @@ func (x *ComponentValueStep) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValueStep.ProtoReflect.Descriptor instead. func (*ComponentValueStep) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{30} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{31} } func (x *ComponentValueStep) GetSelector() isComponentValueStep_Selector { @@ -2260,7 +2427,7 @@ type ComponentAddress struct { func (x *ComponentAddress) Reset() { *x = ComponentAddress{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2272,7 +2439,7 @@ func (x *ComponentAddress) String() string { func (*ComponentAddress) ProtoMessage() {} func (x *ComponentAddress) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2285,7 +2452,7 @@ func (x *ComponentAddress) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentAddress.ProtoReflect.Descriptor instead. func (*ComponentAddress) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{31} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32} } func (x *ComponentAddress) GetStack() string { @@ -2322,7 +2489,7 @@ type ComponentSource struct { func (x *ComponentSource) Reset() { *x = ComponentSource{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2334,7 +2501,7 @@ func (x *ComponentSource) String() string { func (*ComponentSource) ProtoMessage() {} func (x *ComponentSource) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2347,7 +2514,7 @@ func (x *ComponentSource) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentSource.ProtoReflect.Descriptor instead. func (*ComponentSource) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33} } func (x *ComponentSource) GetPath() string { @@ -2381,7 +2548,7 @@ type ComponentDependency struct { func (x *ComponentDependency) Reset() { *x = ComponentDependency{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2393,7 +2560,7 @@ func (x *ComponentDependency) String() string { func (*ComponentDependency) ProtoMessage() {} func (x *ComponentDependency) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2406,7 +2573,7 @@ func (x *ComponentDependency) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentDependency.ProtoReflect.Descriptor instead. func (*ComponentDependency) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34} } func (x *ComponentDependency) GetTarget() *ComponentAddress { @@ -2438,7 +2605,7 @@ type DiscoveredComponent struct { func (x *DiscoveredComponent) Reset() { *x = DiscoveredComponent{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2450,7 +2617,7 @@ func (x *DiscoveredComponent) String() string { func (*DiscoveredComponent) ProtoMessage() {} func (x *DiscoveredComponent) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2463,7 +2630,7 @@ func (x *DiscoveredComponent) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoveredComponent.ProtoReflect.Descriptor instead. func (*DiscoveredComponent) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{35} } func (x *DiscoveredComponent) GetAddress() *ComponentAddress { @@ -2530,7 +2697,7 @@ type ComponentEffects struct { func (x *ComponentEffects) Reset() { *x = ComponentEffects{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2542,7 +2709,7 @@ func (x *ComponentEffects) String() string { func (*ComponentEffects) ProtoMessage() {} func (x *ComponentEffects) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2555,7 +2722,7 @@ func (x *ComponentEffects) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentEffects.ProtoReflect.Descriptor instead. func (*ComponentEffects) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{35} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{36} } func (x *ComponentEffects) GetCommands() bool { @@ -2610,7 +2777,7 @@ type ComponentOperation struct { func (x *ComponentOperation) Reset() { *x = ComponentOperation{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2622,7 +2789,7 @@ func (x *ComponentOperation) String() string { func (*ComponentOperation) ProtoMessage() {} func (x *ComponentOperation) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2635,7 +2802,7 @@ func (x *ComponentOperation) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentOperation.ProtoReflect.Descriptor instead. func (*ComponentOperation) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{36} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{37} } func (x *ComponentOperation) GetCommand() string { @@ -2686,7 +2853,7 @@ type DiscoverComponentsRequest struct { func (x *DiscoverComponentsRequest) Reset() { *x = DiscoverComponentsRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2698,7 +2865,7 @@ func (x *DiscoverComponentsRequest) String() string { func (*DiscoverComponentsRequest) ProtoMessage() {} func (x *DiscoverComponentsRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2711,7 +2878,7 @@ func (x *DiscoverComponentsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoverComponentsRequest.ProtoReflect.Descriptor instead. func (*DiscoverComponentsRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{37} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{38} } func (x *DiscoverComponentsRequest) GetInvocation() *Invocation { @@ -2791,14 +2958,16 @@ type DiscoverComponentsResponse struct { // Per-component failures. A diagnostic whose detail names a unit and stack is // reported only to commands that target that component; others keep working. // A diagnostic without a unit is a project-level failure. - Diagnostics []*Diagnostic `protobuf:"bytes,2,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,2,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + // Engine log events produced while discovering. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,3,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *DiscoverComponentsResponse) Reset() { *x = DiscoverComponentsResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2810,7 +2979,7 @@ func (x *DiscoverComponentsResponse) String() string { func (*DiscoverComponentsResponse) ProtoMessage() {} func (x *DiscoverComponentsResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2823,7 +2992,7 @@ func (x *DiscoverComponentsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoverComponentsResponse.ProtoReflect.Descriptor instead. func (*DiscoverComponentsResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{38} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{39} } func (x *DiscoverComponentsResponse) GetComponents() []*DiscoveredComponent { @@ -2840,6 +3009,13 @@ func (x *DiscoverComponentsResponse) GetDiagnostics() []*Diagnostic { return nil } +func (x *DiscoverComponentsResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + type ComponentRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Invocation *Invocation `protobuf:"bytes,1,opt,name=invocation,proto3" json:"invocation,omitempty"` @@ -2857,7 +3033,7 @@ type ComponentRequest struct { func (x *ComponentRequest) Reset() { *x = ComponentRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2869,7 +3045,7 @@ func (x *ComponentRequest) String() string { func (*ComponentRequest) ProtoMessage() {} func (x *ComponentRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2882,7 +3058,7 @@ func (x *ComponentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentRequest.ProtoReflect.Descriptor instead. func (*ComponentRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{39} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{40} } func (x *ComponentRequest) GetInvocation() *Invocation { @@ -2962,7 +3138,7 @@ type ComponentStateIdentity struct { func (x *ComponentStateIdentity) Reset() { *x = ComponentStateIdentity{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2974,7 +3150,7 @@ func (x *ComponentStateIdentity) String() string { func (*ComponentStateIdentity) ProtoMessage() {} func (x *ComponentStateIdentity) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2987,7 +3163,7 @@ func (x *ComponentStateIdentity) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentStateIdentity.ProtoReflect.Descriptor instead. func (*ComponentStateIdentity) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{40} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{41} } func (x *ComponentStateIdentity) GetBackendType() string { @@ -3032,7 +3208,7 @@ type ComponentGeneratedFile struct { func (x *ComponentGeneratedFile) Reset() { *x = ComponentGeneratedFile{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3044,7 +3220,7 @@ func (x *ComponentGeneratedFile) String() string { func (*ComponentGeneratedFile) ProtoMessage() {} func (x *ComponentGeneratedFile) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3057,7 +3233,7 @@ func (x *ComponentGeneratedFile) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentGeneratedFile.ProtoReflect.Descriptor instead. func (*ComponentGeneratedFile) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{41} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{42} } func (x *ComponentGeneratedFile) GetPath() string { @@ -3102,7 +3278,7 @@ type ComponentExecutionConfiguration struct { func (x *ComponentExecutionConfiguration) Reset() { *x = ComponentExecutionConfiguration{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3114,7 +3290,7 @@ func (x *ComponentExecutionConfiguration) String() string { func (*ComponentExecutionConfiguration) ProtoMessage() {} func (x *ComponentExecutionConfiguration) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3127,7 +3303,7 @@ func (x *ComponentExecutionConfiguration) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExecutionConfiguration.ProtoReflect.Descriptor instead. func (*ComponentExecutionConfiguration) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{42} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{43} } func (x *ComponentExecutionConfiguration) GetExtraArguments() []*ComponentExtraArguments { @@ -3171,7 +3347,7 @@ type ComponentExtraArguments struct { func (x *ComponentExtraArguments) Reset() { *x = ComponentExtraArguments{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3183,7 +3359,7 @@ func (x *ComponentExtraArguments) String() string { func (*ComponentExtraArguments) ProtoMessage() {} func (x *ComponentExtraArguments) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3196,7 +3372,7 @@ func (x *ComponentExtraArguments) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExtraArguments.ProtoReflect.Descriptor instead. func (*ComponentExtraArguments) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{43} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{44} } func (x *ComponentExtraArguments) GetCommands() []string { @@ -3251,7 +3427,7 @@ type ComponentHook struct { func (x *ComponentHook) Reset() { *x = ComponentHook{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3263,7 +3439,7 @@ func (x *ComponentHook) String() string { func (*ComponentHook) ProtoMessage() {} func (x *ComponentHook) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3276,7 +3452,7 @@ func (x *ComponentHook) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentHook.ProtoReflect.Descriptor instead. func (*ComponentHook) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{44} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{45} } func (x *ComponentHook) GetName() string { @@ -3329,16 +3505,21 @@ func (x *ComponentHook) GetOnErrors() []string { } type PrepareComponentResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - Engine string `protobuf:"bytes,1,opt,name=engine,proto3" json:"engine,omitempty"` - WorkingDirectory string `protobuf:"bytes,2,opt,name=working_directory,json=workingDirectory,proto3" json:"working_directory,omitempty"` - ModuleSource string `protobuf:"bytes,3,opt,name=module_source,json=moduleSource,proto3" json:"module_source,omitempty"` - Inputs *ComponentValue `protobuf:"bytes,4,opt,name=inputs,proto3" json:"inputs,omitempty"` - State *ComponentStateIdentity `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty"` - Files []*ComponentGeneratedFile `protobuf:"bytes,6,rep,name=files,proto3" json:"files,omitempty"` - Dependencies []*ComponentDependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` - Sources []*ComponentSource `protobuf:"bytes,8,rep,name=sources,proto3" json:"sources,omitempty"` - Diagnostics []*Diagnostic `protobuf:"bytes,9,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Engine string `protobuf:"bytes,1,opt,name=engine,proto3" json:"engine,omitempty"` + WorkingDirectory string `protobuf:"bytes,2,opt,name=working_directory,json=workingDirectory,proto3" json:"working_directory,omitempty"` + ModuleSource string `protobuf:"bytes,3,opt,name=module_source,json=moduleSource,proto3" json:"module_source,omitempty"` + // The evaluated variables of the unit, an object. Numbers keep their exact decimal value, null and + // empty collections are preserved, and the value is wholly known: an unknown value is a plugin bug and + // the host rejects it naming the input. sensitive_paths mark every input path the unit declared + // sensitive. The host masks those values in all output and logs and keeps them out of variable files, + // exactly like secrets. + Inputs *ComponentValue `protobuf:"bytes,4,opt,name=inputs,proto3" json:"inputs,omitempty"` + State *ComponentStateIdentity `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty"` + Files []*ComponentGeneratedFile `protobuf:"bytes,6,rep,name=files,proto3" json:"files,omitempty"` + Dependencies []*ComponentDependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` + Sources []*ComponentSource `protobuf:"bytes,8,rep,name=sources,proto3" json:"sources,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,9,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` // A returned generated file owns the backend block. The host must not also // emit its default backend file. BackendGenerated bool `protobuf:"varint,10,opt,name=backend_generated,json=backendGenerated,proto3" json:"backend_generated,omitempty"` @@ -3346,28 +3527,35 @@ type PrepareComponentResponse struct { // Maps each input name to the authored file, line, and column that produced // its value, for provenance reporting. Missing entries mean unknown origin. InputOrigins map[string]*SourceLocation `protobuf:"bytes,12,rep,name=input_origins,json=inputOrigins,proto3" json:"input_origins,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - // Fields 13-18 are reserved for Terragrunt parity. The host does not read - // them yet; a plugin that cannot honor a setting must reject it with an - // ErrorDetail instead of returning it, and must leave these fields unset. - // Engine executable selected by terraform_binary. + // Fields 13-18 carry Terragrunt settings that decide how the host runs the unit. The host reads + // 13 to 17. A plugin that cannot honor a setting must reject it with an ErrorDetail instead of + // returning a value the host would silently ignore. + // Engine executable selected by terraform_binary. Empty means the engine of the component. TerraformBinary string `protobuf:"bytes,13,opt,name=terraform_binary,json=terraformBinary,proto3" json:"terraform_binary,omitempty"` - // errors block: retry and ignore policies. + // errors block: retry and ignore policies. The host applies them around the engine subprocess. Errors *ComponentErrorsConfiguration `protobuf:"bytes,14,opt,name=errors,proto3" json:"errors,omitempty"` - // exclude block: conditional unit exclusion. + // exclude block, set only when its condition holds and it applies to the current operation. + // The host skips the operation for the component and runs nothing. See ComponentExclude. Exclude *ComponentExclude `protobuf:"bytes,15,opt,name=exclude,proto3" json:"exclude,omitempty"` // iam_role, iam_assume_role_session_name, iam_assume_role_duration, iam_web_identity_token. + // The host assumes the role, never the plugin. Iam *ComponentIam `protobuf:"bytes,16,opt,name=iam,proto3" json:"iam,omitempty"` - // encryption block as opaque, provider-defined data. + // encryption block as opaque, provider-defined data (state and plan encryption settings). Encryption *ComponentValue `protobuf:"bytes,17,opt,name=encryption,proto3" json:"encryption,omitempty"` - // feature flag name to its evaluated value rendered as a string. - FeatureFlags map[string]string `protobuf:"bytes,18,rep,name=feature_flags,json=featureFlags,proto3" json:"feature_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // Feature flag name to its evaluated value rendered as a string. Informational: the plugin has + // already applied the flags while evaluating the unit, so they are reflected in every other field. + // The host keeps them with the prepared configuration for display and no host behavior depends on + // them. A plugin may leave this field unset. + FeatureFlags map[string]string `protobuf:"bytes,18,rep,name=feature_flags,json=featureFlags,proto3" json:"feature_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // Engine log events produced while preparing. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,19,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *PrepareComponentResponse) Reset() { *x = PrepareComponentResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3379,7 +3567,7 @@ func (x *PrepareComponentResponse) String() string { func (*PrepareComponentResponse) ProtoMessage() {} func (x *PrepareComponentResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3392,7 +3580,7 @@ func (x *PrepareComponentResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PrepareComponentResponse.ProtoReflect.Descriptor instead. func (*PrepareComponentResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{45} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{46} } func (x *PrepareComponentResponse) GetEngine() string { @@ -3521,7 +3709,15 @@ func (x *PrepareComponentResponse) GetFeatureFlags() map[string]string { return nil } -// ComponentErrorsConfiguration mirrors the Terragrunt errors block. Reserved; not implemented. +func (x *PrepareComponentResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + +// ComponentErrorsConfiguration mirrors the Terragrunt errors block. The host retries or ignores a failed +// engine command according to these policies, in declaration order. type ComponentErrorsConfiguration struct { state protoimpl.MessageState `protogen:"open.v1"` Retry []*ComponentRetryPolicy `protobuf:"bytes,1,rep,name=retry,proto3" json:"retry,omitempty"` @@ -3532,7 +3728,7 @@ type ComponentErrorsConfiguration struct { func (x *ComponentErrorsConfiguration) Reset() { *x = ComponentErrorsConfiguration{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3544,7 +3740,7 @@ func (x *ComponentErrorsConfiguration) String() string { func (*ComponentErrorsConfiguration) ProtoMessage() {} func (x *ComponentErrorsConfiguration) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3557,7 +3753,7 @@ func (x *ComponentErrorsConfiguration) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentErrorsConfiguration.ProtoReflect.Descriptor instead. func (*ComponentErrorsConfiguration) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{46} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{47} } func (x *ComponentErrorsConfiguration) GetRetry() []*ComponentRetryPolicy { @@ -3587,7 +3783,7 @@ type ComponentRetryPolicy struct { func (x *ComponentRetryPolicy) Reset() { *x = ComponentRetryPolicy{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3599,7 +3795,7 @@ func (x *ComponentRetryPolicy) String() string { func (*ComponentRetryPolicy) ProtoMessage() {} func (x *ComponentRetryPolicy) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3612,7 +3808,7 @@ func (x *ComponentRetryPolicy) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentRetryPolicy.ProtoReflect.Descriptor instead. func (*ComponentRetryPolicy) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{47} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{48} } func (x *ComponentRetryPolicy) GetName() string { @@ -3657,7 +3853,7 @@ type ComponentIgnorePolicy struct { func (x *ComponentIgnorePolicy) Reset() { *x = ComponentIgnorePolicy{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3669,7 +3865,7 @@ func (x *ComponentIgnorePolicy) String() string { func (*ComponentIgnorePolicy) ProtoMessage() {} func (x *ComponentIgnorePolicy) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3682,7 +3878,7 @@ func (x *ComponentIgnorePolicy) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentIgnorePolicy.ProtoReflect.Descriptor instead. func (*ComponentIgnorePolicy) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{48} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{49} } func (x *ComponentIgnorePolicy) GetName() string { @@ -3713,10 +3909,13 @@ func (x *ComponentIgnorePolicy) GetSignals() map[string]*ComponentValue { return nil } -// ComponentExclude mirrors the Terragrunt exclude block. Reserved; not implemented. +// ComponentExclude mirrors the Terragrunt exclude block for the operation being prepared. It does not +// carry no_run: the plugin applies no_run itself. The plugin sets the PrepareComponentResponse.exclude +// field only when the host must not run the command, and then actions equals that command. A response +// without the field means run the command. exclude_dependencies is informational for the host's graph. type ComponentExclude struct { state protoimpl.MessageState `protogen:"open.v1"` - // Evaluated "if" condition. + // Evaluated "if" condition. The host skips the operation when it is true and the field is set. Condition bool `protobuf:"varint,1,opt,name=condition,proto3" json:"condition,omitempty"` // Commands the exclusion applies to; "all" and "all_except_output" are plugin vocabulary. Actions []string `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"` @@ -3727,7 +3926,7 @@ type ComponentExclude struct { func (x *ComponentExclude) Reset() { *x = ComponentExclude{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3739,7 +3938,7 @@ func (x *ComponentExclude) String() string { func (*ComponentExclude) ProtoMessage() {} func (x *ComponentExclude) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3752,7 +3951,7 @@ func (x *ComponentExclude) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExclude.ProtoReflect.Descriptor instead. func (*ComponentExclude) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{49} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{50} } func (x *ComponentExclude) GetCondition() bool { @@ -3776,7 +3975,8 @@ func (x *ComponentExclude) GetExcludeDependencies() bool { return false } -// ComponentIam mirrors the Terragrunt IAM settings. Reserved; not implemented. +// ComponentIam mirrors the Terragrunt IAM settings. The host assumes the role for the unit's commands, on +// top of the credentials of the invocation, unless an Atmos identity is selected explicitly. // The web identity token is a secret and must be carried as a sensitive value. type ComponentIam struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -3790,7 +3990,7 @@ type ComponentIam struct { func (x *ComponentIam) Reset() { *x = ComponentIam{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3802,7 +4002,7 @@ func (x *ComponentIam) String() string { func (*ComponentIam) ProtoMessage() {} func (x *ComponentIam) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3815,7 +4015,7 @@ func (x *ComponentIam) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentIam.ProtoReflect.Descriptor instead. func (*ComponentIam) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{50} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{51} } func (x *ComponentIam) GetRole() string { @@ -3847,17 +4047,19 @@ func (x *ComponentIam) GetWebIdentityToken() *ComponentValue { } type ResolveComponentStateResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - State *ComponentStateIdentity `protobuf:"bytes,1,opt,name=state,proto3" json:"state,omitempty"` - Sources []*ComponentSource `protobuf:"bytes,2,rep,name=sources,proto3" json:"sources,omitempty"` - Diagnostics []*Diagnostic `protobuf:"bytes,3,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + State *ComponentStateIdentity `protobuf:"bytes,1,opt,name=state,proto3" json:"state,omitempty"` + Sources []*ComponentSource `protobuf:"bytes,2,rep,name=sources,proto3" json:"sources,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,3,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + // Engine log events produced while resolving. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,4,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ResolveComponentStateResponse) Reset() { *x = ResolveComponentStateResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[52] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3869,7 +4071,7 @@ func (x *ResolveComponentStateResponse) String() string { func (*ResolveComponentStateResponse) ProtoMessage() {} func (x *ResolveComponentStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[52] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3882,7 +4084,7 @@ func (x *ResolveComponentStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ResolveComponentStateResponse.ProtoReflect.Descriptor instead. func (*ResolveComponentStateResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{51} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{52} } func (x *ResolveComponentStateResponse) GetState() *ComponentStateIdentity { @@ -3906,11 +4108,18 @@ func (x *ResolveComponentStateResponse) GetDiagnostics() []*Diagnostic { return nil } +func (x *ResolveComponentStateResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + var File_atmos_plugin_v1_plugin_proto protoreflect.FileDescriptor const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\n" + - "\x1catmos/plugin/v1/plugin.proto\x12\x0fatmos.plugin.v1\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xa8\x03\n" + + "\x1catmos/plugin/v1/plugin.proto\x12\x0fatmos.plugin.v1\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xc5\x03\n" + "\n" + "Invocation\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x18\n" + @@ -3921,7 +4130,9 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x05stack\x18\x06 \x01(\tR\x05stack\x12\x1c\n" + "\tcomponent\x18\a \x01(\tR\tcomponent\x12%\n" + "\x0ecomponent_type\x18\b \x01(\tR\rcomponentType\x12 \n" + - "\vinteractive\x18\t \x01(\bR\vinteractive\x1a>\n" + + "\vinteractive\x18\t \x01(\bR\vinteractive\x12\x1b\n" + + "\tlog_level\x18\n" + + " \x01(\tR\blogLevel\x1a>\n" + "\x10EnvironmentEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\xb0\x01\n" + @@ -3993,7 +4204,16 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x0eSourceLocation\x12\x12\n" + "\x04file\x18\x01 \x01(\tR\x04file\x12\x12\n" + "\x04line\x18\x02 \x01(\rR\x04line\x12\x16\n" + - "\x06column\x18\x03 \x01(\rR\x06column\"\xe1\x02\n" + + "\x06column\x18\x03 \x01(\rR\x06column\"\x93\x02\n" + + "\bLogEntry\x12/\n" + + "\x05level\x18\x01 \x01(\x0e2\x19.atmos.plugin.v1.LogLevelR\x05level\x12\x18\n" + + "\amessage\x18\x02 \x01(\tR\amessage\x12=\n" + + "\x06fields\x18\x03 \x03(\v2%.atmos.plugin.v1.LogEntry.FieldsEntryR\x06fields\x12.\n" + + "\x04time\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\x04time\x12\x12\n" + + "\x04unit\x18\x05 \x01(\tR\x04unit\x1a9\n" + + "\vFieldsEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x90\x03\n" + "\vErrorDetail\x12\x12\n" + "\x04code\x18\x01 \x01(\tR\x04code\x12\x18\n" + "\asummary\x18\x02 \x01(\tR\asummary\x12\x16\n" + @@ -4007,7 +4227,8 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\tuser_safe\x18\t \x01(\bR\buserSafe\x12\x1c\n" + "\toperation\x18\n" + " \x01(\tR\toperation\x125\n" + - "\bseverity\x18\v \x01(\x0e2\x19.atmos.plugin.v1.SeverityR\bseverity\"r\n" + + "\bseverity\x18\v \x01(\x0e2\x19.atmos.plugin.v1.SeverityR\bseverity\x12-\n" + + "\x04logs\x18\f \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\"r\n" + "\n" + "Diagnostic\x12\x14\n" + "\x05field\x18\x01 \x01(\tR\x05field\x12\x18\n" + @@ -4134,12 +4355,13 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\toperation\x18\b \x01(\v2#.atmos.plugin.v1.ComponentOperationR\toperation\x12;\n" + "\aeffects\x18\t \x01(\v2!.atmos.plugin.v1.ComponentEffectsR\aeffects\x12V\n" + "\x16provider_configuration\x18\n" + - " \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x15providerConfiguration\"\xa1\x01\n" + + " \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x15providerConfiguration\"\xd0\x01\n" + "\x1aDiscoverComponentsResponse\x12D\n" + "\n" + "components\x18\x01 \x03(\v2$.atmos.plugin.v1.DiscoveredComponentR\n" + "components\x12=\n" + - "\vdiagnostics\x18\x02 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\"\x86\x04\n" + + "\vdiagnostics\x18\x02 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\x12-\n" + + "\x04logs\x18\x03 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\"\x86\x04\n" + "\x10ComponentRequest\x12;\n" + "\n" + "invocation\x18\x01 \x01(\v2\x1b.atmos.plugin.v1.InvocationR\n" + @@ -4186,7 +4408,7 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\frun_on_error\x18\x05 \x01(\bR\n" + "runOnError\x12'\n" + "\x0fsuppress_stdout\x18\x06 \x01(\bR\x0esuppressStdout\x12\x1b\n" + - "\ton_errors\x18\a \x03(\tR\bonErrors\"\x85\n" + + "\ton_errors\x18\a \x03(\tR\bonErrors\"\xb4\n" + "\n" + "\x18PrepareComponentResponse\x12\x16\n" + "\x06engine\x18\x01 \x01(\tR\x06engine\x12+\n" + @@ -4209,7 +4431,8 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\n" + "encryption\x18\x11 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\n" + "encryption\x12`\n" + - "\rfeature_flags\x18\x12 \x03(\v2;.atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntryR\ffeatureFlags\x1a`\n" + + "\rfeature_flags\x18\x12 \x03(\v2;.atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntryR\ffeatureFlags\x12-\n" + + "\x04logs\x18\x13 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\x1a`\n" + "\x11InputOriginsEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x125\n" + "\x05value\x18\x02 \x01(\v2\x1f.atmos.plugin.v1.SourceLocationR\x05value:\x028\x01\x1a?\n" + @@ -4240,11 +4463,19 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x04role\x18\x01 \x01(\tR\x04role\x12!\n" + "\fsession_name\x18\x02 \x01(\tR\vsessionName\x12)\n" + "\x10duration_seconds\x18\x03 \x01(\rR\x0fdurationSeconds\x12M\n" + - "\x12web_identity_token\x18\x04 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x10webIdentityToken\"\xd9\x01\n" + + "\x12web_identity_token\x18\x04 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x10webIdentityToken\"\x88\x02\n" + "\x1dResolveComponentStateResponse\x12=\n" + "\x05state\x18\x01 \x01(\v2'.atmos.plugin.v1.ComponentStateIdentityR\x05state\x12:\n" + "\asources\x18\x02 \x03(\v2 .atmos.plugin.v1.ComponentSourceR\asources\x12=\n" + - "\vdiagnostics\x18\x03 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics*N\n" + + "\vdiagnostics\x18\x03 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\x12-\n" + + "\x04logs\x18\x04 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs*\x8c\x01\n" + + "\bLogLevel\x12\x19\n" + + "\x15LOG_LEVEL_UNSPECIFIED\x10\x00\x12\x13\n" + + "\x0fLOG_LEVEL_TRACE\x10\x01\x12\x13\n" + + "\x0fLOG_LEVEL_DEBUG\x10\x02\x12\x12\n" + + "\x0eLOG_LEVEL_INFO\x10\x03\x12\x12\n" + + "\x0eLOG_LEVEL_WARN\x10\x04\x12\x13\n" + + "\x0fLOG_LEVEL_ERROR\x10\x05*N\n" + "\bSeverity\x12\x18\n" + "\x14SEVERITY_UNSPECIFIED\x10\x00\x12\x12\n" + "\x0eSEVERITY_ERROR\x10\x01\x12\x14\n" + @@ -4291,216 +4522,226 @@ func file_atmos_plugin_v1_plugin_proto_rawDescGZIP() []byte { } var ( - file_atmos_plugin_v1_plugin_proto_enumTypes = make([]protoimpl.EnumInfo, 3) - file_atmos_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 63) + file_atmos_plugin_v1_plugin_proto_enumTypes = make([]protoimpl.EnumInfo, 4) + file_atmos_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 65) file_atmos_plugin_v1_plugin_proto_goTypes = []any{ - Severity(0), // 0: atmos.plugin.v1.Severity - ComponentSource_Kind(0), // 1: atmos.plugin.v1.ComponentSource.Kind - ComponentDependency_Kind(0), // 2: atmos.plugin.v1.ComponentDependency.Kind - (*Invocation)(nil), // 3: atmos.plugin.v1.Invocation - (*Credentials)(nil), // 4: atmos.plugin.v1.Credentials - (*ServiceVersionRange)(nil), // 5: atmos.plugin.v1.ServiceVersionRange - (*Export)(nil), // 6: atmos.plugin.v1.Export - (*DescribeRequest)(nil), // 7: atmos.plugin.v1.DescribeRequest - (*DescribeResponse)(nil), // 8: atmos.plugin.v1.DescribeResponse - (*ConfigureRequest)(nil), // 9: atmos.plugin.v1.ConfigureRequest - (*ProviderRequest)(nil), // 10: atmos.plugin.v1.ProviderRequest - (*IdentityRequest)(nil), // 11: atmos.plugin.v1.IdentityRequest - (*Progress)(nil), // 12: atmos.plugin.v1.Progress - (*Interaction)(nil), // 13: atmos.plugin.v1.Interaction - (*AuthenticateEvent)(nil), // 14: atmos.plugin.v1.AuthenticateEvent - (*SourceLocation)(nil), // 15: atmos.plugin.v1.SourceLocation - (*ErrorDetail)(nil), // 16: atmos.plugin.v1.ErrorDetail - (*Diagnostic)(nil), // 17: atmos.plugin.v1.Diagnostic - (*ValidateResponse)(nil), // 18: atmos.plugin.v1.ValidateResponse - (*Unsupported)(nil), // 19: atmos.plugin.v1.Unsupported - (*RefreshRequest)(nil), // 20: atmos.plugin.v1.RefreshRequest - (*RefreshResponse)(nil), // 21: atmos.plugin.v1.RefreshResponse - (*EnvironmentResponse)(nil), // 22: atmos.plugin.v1.EnvironmentResponse - (*PrepareEnvironmentRequest)(nil), // 23: atmos.plugin.v1.PrepareEnvironmentRequest - (*CredentialPath)(nil), // 24: atmos.plugin.v1.CredentialPath - (*PathsResponse)(nil), // 25: atmos.plugin.v1.PathsResponse - (*IdentityAuthenticateRequest)(nil), // 26: atmos.plugin.v1.IdentityAuthenticateRequest - (*IdentityPrepareRequest)(nil), // 27: atmos.plugin.v1.IdentityPrepareRequest - (*CommandRequest)(nil), // 28: atmos.plugin.v1.CommandRequest - (*CommandExit)(nil), // 29: atmos.plugin.v1.CommandExit - (*CommandEvent)(nil), // 30: atmos.plugin.v1.CommandEvent - (*ComponentValue)(nil), // 31: atmos.plugin.v1.ComponentValue - (*ComponentValuePath)(nil), // 32: atmos.plugin.v1.ComponentValuePath - (*ComponentValueStep)(nil), // 33: atmos.plugin.v1.ComponentValueStep - (*ComponentAddress)(nil), // 34: atmos.plugin.v1.ComponentAddress - (*ComponentSource)(nil), // 35: atmos.plugin.v1.ComponentSource - (*ComponentDependency)(nil), // 36: atmos.plugin.v1.ComponentDependency - (*DiscoveredComponent)(nil), // 37: atmos.plugin.v1.DiscoveredComponent - (*ComponentEffects)(nil), // 38: atmos.plugin.v1.ComponentEffects - (*ComponentOperation)(nil), // 39: atmos.plugin.v1.ComponentOperation - (*DiscoverComponentsRequest)(nil), // 40: atmos.plugin.v1.DiscoverComponentsRequest - (*DiscoverComponentsResponse)(nil), // 41: atmos.plugin.v1.DiscoverComponentsResponse - (*ComponentRequest)(nil), // 42: atmos.plugin.v1.ComponentRequest - (*ComponentStateIdentity)(nil), // 43: atmos.plugin.v1.ComponentStateIdentity - (*ComponentGeneratedFile)(nil), // 44: atmos.plugin.v1.ComponentGeneratedFile - (*ComponentExecutionConfiguration)(nil), // 45: atmos.plugin.v1.ComponentExecutionConfiguration - (*ComponentExtraArguments)(nil), // 46: atmos.plugin.v1.ComponentExtraArguments - (*ComponentHook)(nil), // 47: atmos.plugin.v1.ComponentHook - (*PrepareComponentResponse)(nil), // 48: atmos.plugin.v1.PrepareComponentResponse - (*ComponentErrorsConfiguration)(nil), // 49: atmos.plugin.v1.ComponentErrorsConfiguration - (*ComponentRetryPolicy)(nil), // 50: atmos.plugin.v1.ComponentRetryPolicy - (*ComponentIgnorePolicy)(nil), // 51: atmos.plugin.v1.ComponentIgnorePolicy - (*ComponentExclude)(nil), // 52: atmos.plugin.v1.ComponentExclude - (*ComponentIam)(nil), // 53: atmos.plugin.v1.ComponentIam - (*ResolveComponentStateResponse)(nil), // 54: atmos.plugin.v1.ResolveComponentStateResponse - nil, // 55: atmos.plugin.v1.Invocation.EnvironmentEntry - nil, // 56: atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry - nil, // 57: atmos.plugin.v1.Interaction.FieldsEntry - nil, // 58: atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry - nil, // 59: atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry - nil, // 60: atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry - nil, // 61: atmos.plugin.v1.ComponentOperation.OptionsEntry - nil, // 62: atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry - nil, // 63: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry - nil, // 64: atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry - nil, // 65: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry - (*timestamppb.Timestamp)(nil), // 66: google.protobuf.Timestamp - (*structpb.Struct)(nil), // 67: google.protobuf.Struct - (*emptypb.Empty)(nil), // 68: google.protobuf.Empty + LogLevel(0), // 0: atmos.plugin.v1.LogLevel + Severity(0), // 1: atmos.plugin.v1.Severity + ComponentSource_Kind(0), // 2: atmos.plugin.v1.ComponentSource.Kind + ComponentDependency_Kind(0), // 3: atmos.plugin.v1.ComponentDependency.Kind + (*Invocation)(nil), // 4: atmos.plugin.v1.Invocation + (*Credentials)(nil), // 5: atmos.plugin.v1.Credentials + (*ServiceVersionRange)(nil), // 6: atmos.plugin.v1.ServiceVersionRange + (*Export)(nil), // 7: atmos.plugin.v1.Export + (*DescribeRequest)(nil), // 8: atmos.plugin.v1.DescribeRequest + (*DescribeResponse)(nil), // 9: atmos.plugin.v1.DescribeResponse + (*ConfigureRequest)(nil), // 10: atmos.plugin.v1.ConfigureRequest + (*ProviderRequest)(nil), // 11: atmos.plugin.v1.ProviderRequest + (*IdentityRequest)(nil), // 12: atmos.plugin.v1.IdentityRequest + (*Progress)(nil), // 13: atmos.plugin.v1.Progress + (*Interaction)(nil), // 14: atmos.plugin.v1.Interaction + (*AuthenticateEvent)(nil), // 15: atmos.plugin.v1.AuthenticateEvent + (*SourceLocation)(nil), // 16: atmos.plugin.v1.SourceLocation + (*LogEntry)(nil), // 17: atmos.plugin.v1.LogEntry + (*ErrorDetail)(nil), // 18: atmos.plugin.v1.ErrorDetail + (*Diagnostic)(nil), // 19: atmos.plugin.v1.Diagnostic + (*ValidateResponse)(nil), // 20: atmos.plugin.v1.ValidateResponse + (*Unsupported)(nil), // 21: atmos.plugin.v1.Unsupported + (*RefreshRequest)(nil), // 22: atmos.plugin.v1.RefreshRequest + (*RefreshResponse)(nil), // 23: atmos.plugin.v1.RefreshResponse + (*EnvironmentResponse)(nil), // 24: atmos.plugin.v1.EnvironmentResponse + (*PrepareEnvironmentRequest)(nil), // 25: atmos.plugin.v1.PrepareEnvironmentRequest + (*CredentialPath)(nil), // 26: atmos.plugin.v1.CredentialPath + (*PathsResponse)(nil), // 27: atmos.plugin.v1.PathsResponse + (*IdentityAuthenticateRequest)(nil), // 28: atmos.plugin.v1.IdentityAuthenticateRequest + (*IdentityPrepareRequest)(nil), // 29: atmos.plugin.v1.IdentityPrepareRequest + (*CommandRequest)(nil), // 30: atmos.plugin.v1.CommandRequest + (*CommandExit)(nil), // 31: atmos.plugin.v1.CommandExit + (*CommandEvent)(nil), // 32: atmos.plugin.v1.CommandEvent + (*ComponentValue)(nil), // 33: atmos.plugin.v1.ComponentValue + (*ComponentValuePath)(nil), // 34: atmos.plugin.v1.ComponentValuePath + (*ComponentValueStep)(nil), // 35: atmos.plugin.v1.ComponentValueStep + (*ComponentAddress)(nil), // 36: atmos.plugin.v1.ComponentAddress + (*ComponentSource)(nil), // 37: atmos.plugin.v1.ComponentSource + (*ComponentDependency)(nil), // 38: atmos.plugin.v1.ComponentDependency + (*DiscoveredComponent)(nil), // 39: atmos.plugin.v1.DiscoveredComponent + (*ComponentEffects)(nil), // 40: atmos.plugin.v1.ComponentEffects + (*ComponentOperation)(nil), // 41: atmos.plugin.v1.ComponentOperation + (*DiscoverComponentsRequest)(nil), // 42: atmos.plugin.v1.DiscoverComponentsRequest + (*DiscoverComponentsResponse)(nil), // 43: atmos.plugin.v1.DiscoverComponentsResponse + (*ComponentRequest)(nil), // 44: atmos.plugin.v1.ComponentRequest + (*ComponentStateIdentity)(nil), // 45: atmos.plugin.v1.ComponentStateIdentity + (*ComponentGeneratedFile)(nil), // 46: atmos.plugin.v1.ComponentGeneratedFile + (*ComponentExecutionConfiguration)(nil), // 47: atmos.plugin.v1.ComponentExecutionConfiguration + (*ComponentExtraArguments)(nil), // 48: atmos.plugin.v1.ComponentExtraArguments + (*ComponentHook)(nil), // 49: atmos.plugin.v1.ComponentHook + (*PrepareComponentResponse)(nil), // 50: atmos.plugin.v1.PrepareComponentResponse + (*ComponentErrorsConfiguration)(nil), // 51: atmos.plugin.v1.ComponentErrorsConfiguration + (*ComponentRetryPolicy)(nil), // 52: atmos.plugin.v1.ComponentRetryPolicy + (*ComponentIgnorePolicy)(nil), // 53: atmos.plugin.v1.ComponentIgnorePolicy + (*ComponentExclude)(nil), // 54: atmos.plugin.v1.ComponentExclude + (*ComponentIam)(nil), // 55: atmos.plugin.v1.ComponentIam + (*ResolveComponentStateResponse)(nil), // 56: atmos.plugin.v1.ResolveComponentStateResponse + nil, // 57: atmos.plugin.v1.Invocation.EnvironmentEntry + nil, // 58: atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry + nil, // 59: atmos.plugin.v1.Interaction.FieldsEntry + nil, // 60: atmos.plugin.v1.LogEntry.FieldsEntry + nil, // 61: atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry + nil, // 62: atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry + nil, // 63: atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry + nil, // 64: atmos.plugin.v1.ComponentOperation.OptionsEntry + nil, // 65: atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry + nil, // 66: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry + nil, // 67: atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry + nil, // 68: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry + (*timestamppb.Timestamp)(nil), // 69: google.protobuf.Timestamp + (*structpb.Struct)(nil), // 70: google.protobuf.Struct + (*emptypb.Empty)(nil), // 71: google.protobuf.Empty } ) var file_atmos_plugin_v1_plugin_proto_depIdxs = []int32{ - 66, // 0: atmos.plugin.v1.Invocation.deadline:type_name -> google.protobuf.Timestamp - 55, // 1: atmos.plugin.v1.Invocation.environment:type_name -> atmos.plugin.v1.Invocation.EnvironmentEntry - 66, // 2: atmos.plugin.v1.Credentials.expires_at:type_name -> google.protobuf.Timestamp - 67, // 3: atmos.plugin.v1.Credentials.data:type_name -> google.protobuf.Struct - 5, // 4: atmos.plugin.v1.DescribeRequest.host_supported:type_name -> atmos.plugin.v1.ServiceVersionRange - 5, // 5: atmos.plugin.v1.DescribeResponse.services:type_name -> atmos.plugin.v1.ServiceVersionRange - 6, // 6: atmos.plugin.v1.DescribeResponse.exports:type_name -> atmos.plugin.v1.Export - 56, // 7: atmos.plugin.v1.ConfigureRequest.broker_ids:type_name -> atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry - 67, // 8: atmos.plugin.v1.ConfigureRequest.settings:type_name -> google.protobuf.Struct - 3, // 9: atmos.plugin.v1.ProviderRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 10: atmos.plugin.v1.ProviderRequest.spec:type_name -> google.protobuf.Struct - 3, // 11: atmos.plugin.v1.IdentityRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 12: atmos.plugin.v1.IdentityRequest.spec:type_name -> google.protobuf.Struct - 67, // 13: atmos.plugin.v1.IdentityRequest.principal:type_name -> google.protobuf.Struct - 57, // 14: atmos.plugin.v1.Interaction.fields:type_name -> atmos.plugin.v1.Interaction.FieldsEntry - 12, // 15: atmos.plugin.v1.AuthenticateEvent.progress:type_name -> atmos.plugin.v1.Progress - 13, // 16: atmos.plugin.v1.AuthenticateEvent.interaction:type_name -> atmos.plugin.v1.Interaction - 4, // 17: atmos.plugin.v1.AuthenticateEvent.result:type_name -> atmos.plugin.v1.Credentials - 15, // 18: atmos.plugin.v1.ErrorDetail.location:type_name -> atmos.plugin.v1.SourceLocation - 0, // 19: atmos.plugin.v1.ErrorDetail.severity:type_name -> atmos.plugin.v1.Severity - 16, // 20: atmos.plugin.v1.Diagnostic.detail:type_name -> atmos.plugin.v1.ErrorDetail - 17, // 21: atmos.plugin.v1.ValidateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 10, // 22: atmos.plugin.v1.RefreshRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest - 4, // 23: atmos.plugin.v1.RefreshRequest.current:type_name -> atmos.plugin.v1.Credentials - 4, // 24: atmos.plugin.v1.RefreshResponse.credentials:type_name -> atmos.plugin.v1.Credentials - 19, // 25: atmos.plugin.v1.RefreshResponse.unsupported:type_name -> atmos.plugin.v1.Unsupported - 58, // 26: atmos.plugin.v1.EnvironmentResponse.environment:type_name -> atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry - 10, // 27: atmos.plugin.v1.PrepareEnvironmentRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest - 59, // 28: atmos.plugin.v1.PrepareEnvironmentRequest.environment:type_name -> atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry - 24, // 29: atmos.plugin.v1.PathsResponse.paths:type_name -> atmos.plugin.v1.CredentialPath - 11, // 30: atmos.plugin.v1.IdentityAuthenticateRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest - 4, // 31: atmos.plugin.v1.IdentityAuthenticateRequest.upstream:type_name -> atmos.plugin.v1.Credentials - 11, // 32: atmos.plugin.v1.IdentityPrepareRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest - 60, // 33: atmos.plugin.v1.IdentityPrepareRequest.environment:type_name -> atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry - 3, // 34: atmos.plugin.v1.CommandRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 35: atmos.plugin.v1.CommandRequest.settings:type_name -> google.protobuf.Struct - 29, // 36: atmos.plugin.v1.CommandEvent.exit:type_name -> atmos.plugin.v1.CommandExit - 32, // 37: atmos.plugin.v1.ComponentValue.sensitive_paths:type_name -> atmos.plugin.v1.ComponentValuePath - 33, // 38: atmos.plugin.v1.ComponentValuePath.steps:type_name -> atmos.plugin.v1.ComponentValueStep - 31, // 39: atmos.plugin.v1.ComponentValueStep.index:type_name -> atmos.plugin.v1.ComponentValue - 1, // 40: atmos.plugin.v1.ComponentSource.kind:type_name -> atmos.plugin.v1.ComponentSource.Kind - 34, // 41: atmos.plugin.v1.ComponentDependency.target:type_name -> atmos.plugin.v1.ComponentAddress - 2, // 42: atmos.plugin.v1.ComponentDependency.kind:type_name -> atmos.plugin.v1.ComponentDependency.Kind - 34, // 43: atmos.plugin.v1.DiscoveredComponent.address:type_name -> atmos.plugin.v1.ComponentAddress - 31, // 44: atmos.plugin.v1.DiscoveredComponent.configuration:type_name -> atmos.plugin.v1.ComponentValue - 35, // 45: atmos.plugin.v1.DiscoveredComponent.sources:type_name -> atmos.plugin.v1.ComponentSource - 36, // 46: atmos.plugin.v1.DiscoveredComponent.dependencies:type_name -> atmos.plugin.v1.ComponentDependency - 61, // 47: atmos.plugin.v1.ComponentOperation.options:type_name -> atmos.plugin.v1.ComponentOperation.OptionsEntry - 3, // 48: atmos.plugin.v1.DiscoverComponentsRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 39, // 49: atmos.plugin.v1.DiscoverComponentsRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation - 38, // 50: atmos.plugin.v1.DiscoverComponentsRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects - 31, // 51: atmos.plugin.v1.DiscoverComponentsRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue - 37, // 52: atmos.plugin.v1.DiscoverComponentsResponse.components:type_name -> atmos.plugin.v1.DiscoveredComponent - 17, // 53: atmos.plugin.v1.DiscoverComponentsResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 3, // 54: atmos.plugin.v1.ComponentRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 34, // 55: atmos.plugin.v1.ComponentRequest.address:type_name -> atmos.plugin.v1.ComponentAddress - 39, // 56: atmos.plugin.v1.ComponentRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation - 38, // 57: atmos.plugin.v1.ComponentRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects - 31, // 58: atmos.plugin.v1.ComponentRequest.configuration:type_name -> atmos.plugin.v1.ComponentValue - 31, // 59: atmos.plugin.v1.ComponentRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue - 31, // 60: atmos.plugin.v1.ComponentStateIdentity.backend:type_name -> atmos.plugin.v1.ComponentValue - 46, // 61: atmos.plugin.v1.ComponentExecutionConfiguration.extra_arguments:type_name -> atmos.plugin.v1.ComponentExtraArguments - 47, // 62: atmos.plugin.v1.ComponentExecutionConfiguration.before_hooks:type_name -> atmos.plugin.v1.ComponentHook - 47, // 63: atmos.plugin.v1.ComponentExecutionConfiguration.after_hooks:type_name -> atmos.plugin.v1.ComponentHook - 47, // 64: atmos.plugin.v1.ComponentExecutionConfiguration.error_hooks:type_name -> atmos.plugin.v1.ComponentHook - 62, // 65: atmos.plugin.v1.ComponentExtraArguments.environment:type_name -> atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry - 31, // 66: atmos.plugin.v1.PrepareComponentResponse.inputs:type_name -> atmos.plugin.v1.ComponentValue - 43, // 67: atmos.plugin.v1.PrepareComponentResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity - 44, // 68: atmos.plugin.v1.PrepareComponentResponse.files:type_name -> atmos.plugin.v1.ComponentGeneratedFile - 36, // 69: atmos.plugin.v1.PrepareComponentResponse.dependencies:type_name -> atmos.plugin.v1.ComponentDependency - 35, // 70: atmos.plugin.v1.PrepareComponentResponse.sources:type_name -> atmos.plugin.v1.ComponentSource - 17, // 71: atmos.plugin.v1.PrepareComponentResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 45, // 72: atmos.plugin.v1.PrepareComponentResponse.execution:type_name -> atmos.plugin.v1.ComponentExecutionConfiguration - 63, // 73: atmos.plugin.v1.PrepareComponentResponse.input_origins:type_name -> atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry - 49, // 74: atmos.plugin.v1.PrepareComponentResponse.errors:type_name -> atmos.plugin.v1.ComponentErrorsConfiguration - 52, // 75: atmos.plugin.v1.PrepareComponentResponse.exclude:type_name -> atmos.plugin.v1.ComponentExclude - 53, // 76: atmos.plugin.v1.PrepareComponentResponse.iam:type_name -> atmos.plugin.v1.ComponentIam - 31, // 77: atmos.plugin.v1.PrepareComponentResponse.encryption:type_name -> atmos.plugin.v1.ComponentValue - 64, // 78: atmos.plugin.v1.PrepareComponentResponse.feature_flags:type_name -> atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry - 50, // 79: atmos.plugin.v1.ComponentErrorsConfiguration.retry:type_name -> atmos.plugin.v1.ComponentRetryPolicy - 51, // 80: atmos.plugin.v1.ComponentErrorsConfiguration.ignore:type_name -> atmos.plugin.v1.ComponentIgnorePolicy - 65, // 81: atmos.plugin.v1.ComponentIgnorePolicy.signals:type_name -> atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry - 31, // 82: atmos.plugin.v1.ComponentIam.web_identity_token:type_name -> atmos.plugin.v1.ComponentValue - 43, // 83: atmos.plugin.v1.ResolveComponentStateResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity - 35, // 84: atmos.plugin.v1.ResolveComponentStateResponse.sources:type_name -> atmos.plugin.v1.ComponentSource - 17, // 85: atmos.plugin.v1.ResolveComponentStateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 31, // 86: atmos.plugin.v1.ComponentOperation.OptionsEntry.value:type_name -> atmos.plugin.v1.ComponentValue - 15, // 87: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry.value:type_name -> atmos.plugin.v1.SourceLocation - 31, // 88: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry.value:type_name -> atmos.plugin.v1.ComponentValue - 7, // 89: atmos.plugin.v1.Info.Describe:input_type -> atmos.plugin.v1.DescribeRequest - 9, // 90: atmos.plugin.v1.Info.Configure:input_type -> atmos.plugin.v1.ConfigureRequest - 10, // 91: atmos.plugin.v1.AuthProvider.Validate:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 92: atmos.plugin.v1.AuthProvider.Authenticate:input_type -> atmos.plugin.v1.ProviderRequest - 20, // 93: atmos.plugin.v1.AuthProvider.Refresh:input_type -> atmos.plugin.v1.RefreshRequest - 10, // 94: atmos.plugin.v1.AuthProvider.Logout:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 95: atmos.plugin.v1.AuthProvider.Environment:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 96: atmos.plugin.v1.AuthProvider.Paths:input_type -> atmos.plugin.v1.ProviderRequest - 23, // 97: atmos.plugin.v1.AuthProvider.PrepareEnvironment:input_type -> atmos.plugin.v1.PrepareEnvironmentRequest - 11, // 98: atmos.plugin.v1.AuthIdentity.Validate:input_type -> atmos.plugin.v1.IdentityRequest - 26, // 99: atmos.plugin.v1.AuthIdentity.Authenticate:input_type -> atmos.plugin.v1.IdentityAuthenticateRequest - 11, // 100: atmos.plugin.v1.AuthIdentity.Logout:input_type -> atmos.plugin.v1.IdentityRequest - 11, // 101: atmos.plugin.v1.AuthIdentity.Environment:input_type -> atmos.plugin.v1.IdentityRequest - 11, // 102: atmos.plugin.v1.AuthIdentity.Paths:input_type -> atmos.plugin.v1.IdentityRequest - 27, // 103: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:input_type -> atmos.plugin.v1.IdentityPrepareRequest - 28, // 104: atmos.plugin.v1.Commands.Run:input_type -> atmos.plugin.v1.CommandRequest - 40, // 105: atmos.plugin.v1.ComponentDiscovery.Discover:input_type -> atmos.plugin.v1.DiscoverComponentsRequest - 42, // 106: atmos.plugin.v1.ComponentValidation.Validate:input_type -> atmos.plugin.v1.ComponentRequest - 42, // 107: atmos.plugin.v1.ComponentPreparation.Prepare:input_type -> atmos.plugin.v1.ComponentRequest - 42, // 108: atmos.plugin.v1.ComponentState.Resolve:input_type -> atmos.plugin.v1.ComponentRequest - 8, // 109: atmos.plugin.v1.Info.Describe:output_type -> atmos.plugin.v1.DescribeResponse - 68, // 110: atmos.plugin.v1.Info.Configure:output_type -> google.protobuf.Empty - 18, // 111: atmos.plugin.v1.AuthProvider.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 14, // 112: atmos.plugin.v1.AuthProvider.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent - 21, // 113: atmos.plugin.v1.AuthProvider.Refresh:output_type -> atmos.plugin.v1.RefreshResponse - 68, // 114: atmos.plugin.v1.AuthProvider.Logout:output_type -> google.protobuf.Empty - 22, // 115: atmos.plugin.v1.AuthProvider.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse - 25, // 116: atmos.plugin.v1.AuthProvider.Paths:output_type -> atmos.plugin.v1.PathsResponse - 22, // 117: atmos.plugin.v1.AuthProvider.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse - 18, // 118: atmos.plugin.v1.AuthIdentity.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 14, // 119: atmos.plugin.v1.AuthIdentity.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent - 68, // 120: atmos.plugin.v1.AuthIdentity.Logout:output_type -> google.protobuf.Empty - 22, // 121: atmos.plugin.v1.AuthIdentity.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse - 25, // 122: atmos.plugin.v1.AuthIdentity.Paths:output_type -> atmos.plugin.v1.PathsResponse - 22, // 123: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse - 30, // 124: atmos.plugin.v1.Commands.Run:output_type -> atmos.plugin.v1.CommandEvent - 41, // 125: atmos.plugin.v1.ComponentDiscovery.Discover:output_type -> atmos.plugin.v1.DiscoverComponentsResponse - 18, // 126: atmos.plugin.v1.ComponentValidation.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 48, // 127: atmos.plugin.v1.ComponentPreparation.Prepare:output_type -> atmos.plugin.v1.PrepareComponentResponse - 54, // 128: atmos.plugin.v1.ComponentState.Resolve:output_type -> atmos.plugin.v1.ResolveComponentStateResponse - 109, // [109:129] is the sub-list for method output_type - 89, // [89:109] is the sub-list for method input_type - 89, // [89:89] is the sub-list for extension type_name - 89, // [89:89] is the sub-list for extension extendee - 0, // [0:89] is the sub-list for field type_name + 69, // 0: atmos.plugin.v1.Invocation.deadline:type_name -> google.protobuf.Timestamp + 57, // 1: atmos.plugin.v1.Invocation.environment:type_name -> atmos.plugin.v1.Invocation.EnvironmentEntry + 69, // 2: atmos.plugin.v1.Credentials.expires_at:type_name -> google.protobuf.Timestamp + 70, // 3: atmos.plugin.v1.Credentials.data:type_name -> google.protobuf.Struct + 6, // 4: atmos.plugin.v1.DescribeRequest.host_supported:type_name -> atmos.plugin.v1.ServiceVersionRange + 6, // 5: atmos.plugin.v1.DescribeResponse.services:type_name -> atmos.plugin.v1.ServiceVersionRange + 7, // 6: atmos.plugin.v1.DescribeResponse.exports:type_name -> atmos.plugin.v1.Export + 58, // 7: atmos.plugin.v1.ConfigureRequest.broker_ids:type_name -> atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry + 70, // 8: atmos.plugin.v1.ConfigureRequest.settings:type_name -> google.protobuf.Struct + 4, // 9: atmos.plugin.v1.ProviderRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 10: atmos.plugin.v1.ProviderRequest.spec:type_name -> google.protobuf.Struct + 4, // 11: atmos.plugin.v1.IdentityRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 12: atmos.plugin.v1.IdentityRequest.spec:type_name -> google.protobuf.Struct + 70, // 13: atmos.plugin.v1.IdentityRequest.principal:type_name -> google.protobuf.Struct + 59, // 14: atmos.plugin.v1.Interaction.fields:type_name -> atmos.plugin.v1.Interaction.FieldsEntry + 13, // 15: atmos.plugin.v1.AuthenticateEvent.progress:type_name -> atmos.plugin.v1.Progress + 14, // 16: atmos.plugin.v1.AuthenticateEvent.interaction:type_name -> atmos.plugin.v1.Interaction + 5, // 17: atmos.plugin.v1.AuthenticateEvent.result:type_name -> atmos.plugin.v1.Credentials + 0, // 18: atmos.plugin.v1.LogEntry.level:type_name -> atmos.plugin.v1.LogLevel + 60, // 19: atmos.plugin.v1.LogEntry.fields:type_name -> atmos.plugin.v1.LogEntry.FieldsEntry + 69, // 20: atmos.plugin.v1.LogEntry.time:type_name -> google.protobuf.Timestamp + 16, // 21: atmos.plugin.v1.ErrorDetail.location:type_name -> atmos.plugin.v1.SourceLocation + 1, // 22: atmos.plugin.v1.ErrorDetail.severity:type_name -> atmos.plugin.v1.Severity + 17, // 23: atmos.plugin.v1.ErrorDetail.logs:type_name -> atmos.plugin.v1.LogEntry + 18, // 24: atmos.plugin.v1.Diagnostic.detail:type_name -> atmos.plugin.v1.ErrorDetail + 19, // 25: atmos.plugin.v1.ValidateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 11, // 26: atmos.plugin.v1.RefreshRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest + 5, // 27: atmos.plugin.v1.RefreshRequest.current:type_name -> atmos.plugin.v1.Credentials + 5, // 28: atmos.plugin.v1.RefreshResponse.credentials:type_name -> atmos.plugin.v1.Credentials + 21, // 29: atmos.plugin.v1.RefreshResponse.unsupported:type_name -> atmos.plugin.v1.Unsupported + 61, // 30: atmos.plugin.v1.EnvironmentResponse.environment:type_name -> atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry + 11, // 31: atmos.plugin.v1.PrepareEnvironmentRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest + 62, // 32: atmos.plugin.v1.PrepareEnvironmentRequest.environment:type_name -> atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry + 26, // 33: atmos.plugin.v1.PathsResponse.paths:type_name -> atmos.plugin.v1.CredentialPath + 12, // 34: atmos.plugin.v1.IdentityAuthenticateRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest + 5, // 35: atmos.plugin.v1.IdentityAuthenticateRequest.upstream:type_name -> atmos.plugin.v1.Credentials + 12, // 36: atmos.plugin.v1.IdentityPrepareRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest + 63, // 37: atmos.plugin.v1.IdentityPrepareRequest.environment:type_name -> atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry + 4, // 38: atmos.plugin.v1.CommandRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 39: atmos.plugin.v1.CommandRequest.settings:type_name -> google.protobuf.Struct + 31, // 40: atmos.plugin.v1.CommandEvent.exit:type_name -> atmos.plugin.v1.CommandExit + 34, // 41: atmos.plugin.v1.ComponentValue.sensitive_paths:type_name -> atmos.plugin.v1.ComponentValuePath + 35, // 42: atmos.plugin.v1.ComponentValuePath.steps:type_name -> atmos.plugin.v1.ComponentValueStep + 33, // 43: atmos.plugin.v1.ComponentValueStep.index:type_name -> atmos.plugin.v1.ComponentValue + 2, // 44: atmos.plugin.v1.ComponentSource.kind:type_name -> atmos.plugin.v1.ComponentSource.Kind + 36, // 45: atmos.plugin.v1.ComponentDependency.target:type_name -> atmos.plugin.v1.ComponentAddress + 3, // 46: atmos.plugin.v1.ComponentDependency.kind:type_name -> atmos.plugin.v1.ComponentDependency.Kind + 36, // 47: atmos.plugin.v1.DiscoveredComponent.address:type_name -> atmos.plugin.v1.ComponentAddress + 33, // 48: atmos.plugin.v1.DiscoveredComponent.configuration:type_name -> atmos.plugin.v1.ComponentValue + 37, // 49: atmos.plugin.v1.DiscoveredComponent.sources:type_name -> atmos.plugin.v1.ComponentSource + 38, // 50: atmos.plugin.v1.DiscoveredComponent.dependencies:type_name -> atmos.plugin.v1.ComponentDependency + 64, // 51: atmos.plugin.v1.ComponentOperation.options:type_name -> atmos.plugin.v1.ComponentOperation.OptionsEntry + 4, // 52: atmos.plugin.v1.DiscoverComponentsRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 41, // 53: atmos.plugin.v1.DiscoverComponentsRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation + 40, // 54: atmos.plugin.v1.DiscoverComponentsRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects + 33, // 55: atmos.plugin.v1.DiscoverComponentsRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue + 39, // 56: atmos.plugin.v1.DiscoverComponentsResponse.components:type_name -> atmos.plugin.v1.DiscoveredComponent + 19, // 57: atmos.plugin.v1.DiscoverComponentsResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 17, // 58: atmos.plugin.v1.DiscoverComponentsResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 4, // 59: atmos.plugin.v1.ComponentRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 36, // 60: atmos.plugin.v1.ComponentRequest.address:type_name -> atmos.plugin.v1.ComponentAddress + 41, // 61: atmos.plugin.v1.ComponentRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation + 40, // 62: atmos.plugin.v1.ComponentRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects + 33, // 63: atmos.plugin.v1.ComponentRequest.configuration:type_name -> atmos.plugin.v1.ComponentValue + 33, // 64: atmos.plugin.v1.ComponentRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue + 33, // 65: atmos.plugin.v1.ComponentStateIdentity.backend:type_name -> atmos.plugin.v1.ComponentValue + 48, // 66: atmos.plugin.v1.ComponentExecutionConfiguration.extra_arguments:type_name -> atmos.plugin.v1.ComponentExtraArguments + 49, // 67: atmos.plugin.v1.ComponentExecutionConfiguration.before_hooks:type_name -> atmos.plugin.v1.ComponentHook + 49, // 68: atmos.plugin.v1.ComponentExecutionConfiguration.after_hooks:type_name -> atmos.plugin.v1.ComponentHook + 49, // 69: atmos.plugin.v1.ComponentExecutionConfiguration.error_hooks:type_name -> atmos.plugin.v1.ComponentHook + 65, // 70: atmos.plugin.v1.ComponentExtraArguments.environment:type_name -> atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry + 33, // 71: atmos.plugin.v1.PrepareComponentResponse.inputs:type_name -> atmos.plugin.v1.ComponentValue + 45, // 72: atmos.plugin.v1.PrepareComponentResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity + 46, // 73: atmos.plugin.v1.PrepareComponentResponse.files:type_name -> atmos.plugin.v1.ComponentGeneratedFile + 38, // 74: atmos.plugin.v1.PrepareComponentResponse.dependencies:type_name -> atmos.plugin.v1.ComponentDependency + 37, // 75: atmos.plugin.v1.PrepareComponentResponse.sources:type_name -> atmos.plugin.v1.ComponentSource + 19, // 76: atmos.plugin.v1.PrepareComponentResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 47, // 77: atmos.plugin.v1.PrepareComponentResponse.execution:type_name -> atmos.plugin.v1.ComponentExecutionConfiguration + 66, // 78: atmos.plugin.v1.PrepareComponentResponse.input_origins:type_name -> atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry + 51, // 79: atmos.plugin.v1.PrepareComponentResponse.errors:type_name -> atmos.plugin.v1.ComponentErrorsConfiguration + 54, // 80: atmos.plugin.v1.PrepareComponentResponse.exclude:type_name -> atmos.plugin.v1.ComponentExclude + 55, // 81: atmos.plugin.v1.PrepareComponentResponse.iam:type_name -> atmos.plugin.v1.ComponentIam + 33, // 82: atmos.plugin.v1.PrepareComponentResponse.encryption:type_name -> atmos.plugin.v1.ComponentValue + 67, // 83: atmos.plugin.v1.PrepareComponentResponse.feature_flags:type_name -> atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry + 17, // 84: atmos.plugin.v1.PrepareComponentResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 52, // 85: atmos.plugin.v1.ComponentErrorsConfiguration.retry:type_name -> atmos.plugin.v1.ComponentRetryPolicy + 53, // 86: atmos.plugin.v1.ComponentErrorsConfiguration.ignore:type_name -> atmos.plugin.v1.ComponentIgnorePolicy + 68, // 87: atmos.plugin.v1.ComponentIgnorePolicy.signals:type_name -> atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry + 33, // 88: atmos.plugin.v1.ComponentIam.web_identity_token:type_name -> atmos.plugin.v1.ComponentValue + 45, // 89: atmos.plugin.v1.ResolveComponentStateResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity + 37, // 90: atmos.plugin.v1.ResolveComponentStateResponse.sources:type_name -> atmos.plugin.v1.ComponentSource + 19, // 91: atmos.plugin.v1.ResolveComponentStateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 17, // 92: atmos.plugin.v1.ResolveComponentStateResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 33, // 93: atmos.plugin.v1.ComponentOperation.OptionsEntry.value:type_name -> atmos.plugin.v1.ComponentValue + 16, // 94: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry.value:type_name -> atmos.plugin.v1.SourceLocation + 33, // 95: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry.value:type_name -> atmos.plugin.v1.ComponentValue + 8, // 96: atmos.plugin.v1.Info.Describe:input_type -> atmos.plugin.v1.DescribeRequest + 10, // 97: atmos.plugin.v1.Info.Configure:input_type -> atmos.plugin.v1.ConfigureRequest + 11, // 98: atmos.plugin.v1.AuthProvider.Validate:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 99: atmos.plugin.v1.AuthProvider.Authenticate:input_type -> atmos.plugin.v1.ProviderRequest + 22, // 100: atmos.plugin.v1.AuthProvider.Refresh:input_type -> atmos.plugin.v1.RefreshRequest + 11, // 101: atmos.plugin.v1.AuthProvider.Logout:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 102: atmos.plugin.v1.AuthProvider.Environment:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 103: atmos.plugin.v1.AuthProvider.Paths:input_type -> atmos.plugin.v1.ProviderRequest + 25, // 104: atmos.plugin.v1.AuthProvider.PrepareEnvironment:input_type -> atmos.plugin.v1.PrepareEnvironmentRequest + 12, // 105: atmos.plugin.v1.AuthIdentity.Validate:input_type -> atmos.plugin.v1.IdentityRequest + 28, // 106: atmos.plugin.v1.AuthIdentity.Authenticate:input_type -> atmos.plugin.v1.IdentityAuthenticateRequest + 12, // 107: atmos.plugin.v1.AuthIdentity.Logout:input_type -> atmos.plugin.v1.IdentityRequest + 12, // 108: atmos.plugin.v1.AuthIdentity.Environment:input_type -> atmos.plugin.v1.IdentityRequest + 12, // 109: atmos.plugin.v1.AuthIdentity.Paths:input_type -> atmos.plugin.v1.IdentityRequest + 29, // 110: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:input_type -> atmos.plugin.v1.IdentityPrepareRequest + 30, // 111: atmos.plugin.v1.Commands.Run:input_type -> atmos.plugin.v1.CommandRequest + 42, // 112: atmos.plugin.v1.ComponentDiscovery.Discover:input_type -> atmos.plugin.v1.DiscoverComponentsRequest + 44, // 113: atmos.plugin.v1.ComponentValidation.Validate:input_type -> atmos.plugin.v1.ComponentRequest + 44, // 114: atmos.plugin.v1.ComponentPreparation.Prepare:input_type -> atmos.plugin.v1.ComponentRequest + 44, // 115: atmos.plugin.v1.ComponentState.Resolve:input_type -> atmos.plugin.v1.ComponentRequest + 9, // 116: atmos.plugin.v1.Info.Describe:output_type -> atmos.plugin.v1.DescribeResponse + 71, // 117: atmos.plugin.v1.Info.Configure:output_type -> google.protobuf.Empty + 20, // 118: atmos.plugin.v1.AuthProvider.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 15, // 119: atmos.plugin.v1.AuthProvider.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent + 23, // 120: atmos.plugin.v1.AuthProvider.Refresh:output_type -> atmos.plugin.v1.RefreshResponse + 71, // 121: atmos.plugin.v1.AuthProvider.Logout:output_type -> google.protobuf.Empty + 24, // 122: atmos.plugin.v1.AuthProvider.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse + 27, // 123: atmos.plugin.v1.AuthProvider.Paths:output_type -> atmos.plugin.v1.PathsResponse + 24, // 124: atmos.plugin.v1.AuthProvider.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse + 20, // 125: atmos.plugin.v1.AuthIdentity.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 15, // 126: atmos.plugin.v1.AuthIdentity.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent + 71, // 127: atmos.plugin.v1.AuthIdentity.Logout:output_type -> google.protobuf.Empty + 24, // 128: atmos.plugin.v1.AuthIdentity.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse + 27, // 129: atmos.plugin.v1.AuthIdentity.Paths:output_type -> atmos.plugin.v1.PathsResponse + 24, // 130: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse + 32, // 131: atmos.plugin.v1.Commands.Run:output_type -> atmos.plugin.v1.CommandEvent + 43, // 132: atmos.plugin.v1.ComponentDiscovery.Discover:output_type -> atmos.plugin.v1.DiscoverComponentsResponse + 20, // 133: atmos.plugin.v1.ComponentValidation.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 50, // 134: atmos.plugin.v1.ComponentPreparation.Prepare:output_type -> atmos.plugin.v1.PrepareComponentResponse + 56, // 135: atmos.plugin.v1.ComponentState.Resolve:output_type -> atmos.plugin.v1.ResolveComponentStateResponse + 116, // [116:136] is the sub-list for method output_type + 96, // [96:116] is the sub-list for method input_type + 96, // [96:96] is the sub-list for extension type_name + 96, // [96:96] is the sub-list for extension extendee + 0, // [0:96] is the sub-list for field type_name } func init() { file_atmos_plugin_v1_plugin_proto_init() } @@ -4513,16 +4754,16 @@ func file_atmos_plugin_v1_plugin_proto_init() { (*AuthenticateEvent_Interaction)(nil), (*AuthenticateEvent_Result)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[18].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[19].OneofWrappers = []any{ (*RefreshResponse_Credentials)(nil), (*RefreshResponse_Unsupported)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[27].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[28].OneofWrappers = []any{ (*CommandEvent_Stdout)(nil), (*CommandEvent_Stderr)(nil), (*CommandEvent_Exit)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[30].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[31].OneofWrappers = []any{ (*ComponentValueStep_Attribute)(nil), (*ComponentValueStep_Index)(nil), } @@ -4531,8 +4772,8 @@ func file_atmos_plugin_v1_plugin_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_atmos_plugin_v1_plugin_proto_rawDesc), len(file_atmos_plugin_v1_plugin_proto_rawDesc)), - NumEnums: 3, - NumMessages: 63, + NumEnums: 4, + NumMessages: 65, NumExtensions: 0, NumServices: 8, }, diff --git a/pkg/schema/component_configuration.go b/pkg/schema/component_configuration.go index 87e08db18fc..88fbf95d236 100644 --- a/pkg/schema/component_configuration.go +++ b/pkg/schema/component_configuration.go @@ -30,6 +30,14 @@ type ComponentDiscoveryConfig struct { ExcludedPaths []string `yaml:"excluded_paths,omitempty" json:"excluded_paths,omitempty" mapstructure:"excluded_paths"` } +// ComponentProviderOption is a provider option the user set explicitly on the command line or in the +// environment. Options the user did not set are absent, so a provider can tell them from false, zero, and empty. +type ComponentProviderOption struct { + Value any + // Sensitive values are masked and never logged. + Sensitive bool +} + // ComponentConfigurationRuntime is an invocation-owned host service. It is not a wire contract. type ComponentConfigurationRuntime interface { Discover(context.Context) (map[string]map[string]any, error) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 13009f2f634..13fc0e177b2 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -114,6 +114,8 @@ type ConfigMetadata struct { type AtmosConfiguration struct { // ComponentConfigurations belongs to this invocation and is never serialized. ComponentConfigurations ComponentConfigurationRuntime `yaml:"-" json:"-" mapstructure:"-"` + // ComponentProviderOptions are the provider options the user set for this invocation, by provider section. + ComponentProviderOptions map[string]map[string]ComponentProviderOption `yaml:"-" json:"-" mapstructure:"-"` Scaffold *ScaffoldConfiguration `yaml:"scaffold,omitempty" json:"scaffold,omitempty" mapstructure:"scaffold"` // ScaffoldConfigLoaded distinguishes an empty effective catalog from a @@ -2297,11 +2299,14 @@ type ConfigAndStacksInfo struct { Identity string // RequestedIdentity preserves the CLI/environment choice before authentication // stores an auto-selected identity. Nil means Identity has not been rewritten. - RequestedIdentity *string - ClusterName string // EKS cluster name from --cluster-name flag. - NeedsPathResolution bool // True if ComponentFromArg is a path that needs resolution. - UIEnabled bool // Enable streaming UI mode for terraform commands. - UIFlagExplicitlySet bool // Whether --ui flag was explicitly set (vs. config/default). + RequestedIdentity *string + // ComponentProviderOptions are the configuration provider options set on the command line or in + // the environment, by provider section. Unset options are absent. + ComponentProviderOptions map[string]map[string]ComponentProviderOption + ClusterName string // EKS cluster name from --cluster-name flag. + NeedsPathResolution bool // True if ComponentFromArg is a path that needs resolution. + UIEnabled bool // Enable streaming UI mode for terraform commands. + UIFlagExplicitlySet bool // Whether --ui flag was explicitly set (vs. config/default). // NodeHooks fires lifecycle hooks around each component in bulk Terraform // and single-component Helmfile runs. Single-component Terraform commands diff --git a/plugins/README.md b/plugins/README.md index 20737ae291e..6a8352ac3f7 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -24,7 +24,9 @@ The release job holds its global lock throughout publication and catalog reconci ## Required public GHCR setup -**Both `atmos/plugins/auth-secrets` and `atmos/plugins/catalog` must be public for successful official distribution.** GitHub creates new GHCR packages private by default, even in a public repository. Source repository labels and publishing through GitHub Actions establish repository association and permissions, but do not inherit public visibility. GitHub currently has no documented, supported REST or GraphQL API to change package visibility. +**The `atmos/plugins/auth-secrets`, `atmos/plugins/catalog`, and `atmos/plugins/terragrunt` packages (`oci://ghcr.io/cloudposse/atmos/plugins/`) must be public for successful official distribution.** Public visibility is required only for these official Cloud Posse packages, which anyone must be able to install without credentials. It is the publisher's choice everywhere else: a company that distributes an internal plugin through a private registry, or a private GHCR package, publishes with `atmos plugin publish` or `atmos plugin release` to that registry and never has to make anything public. The `--verify-public` flag stays opt-in and is what the official release workflow passes; leave it off for private packages. + +GitHub creates new GHCR packages private by default, even in a public repository. Source repository labels and publishing through GitHub Actions establish repository association and permissions, but do not inherit public visibility. GitHub currently has no documented, supported REST or GraphQL API to change package visibility. The workflow uses `--verify-public`: it uploads first, then anonymously downloads and verifies the published digest and every referenced payload before reporting success. A first upload creates the package and fails verification while it is private. The error confirms that content was published and provides recovery instructions; uploaded content is not deleted. @@ -36,6 +38,8 @@ Do this once for each plugin package and separately for the catalog. A run stops See [GitHub's visibility instructions](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#configuring-visibility-of-packages-for-an-organization) and [Packages API reference](https://docs.github.com/en/rest/packages/packages). Private publishers should omit `--verify-public`; Atmos preserves registry access settings by default. +Each published release carries an `org.opencontainers.image.source` annotation, which is how GHCR links a package to its repository (and inherits that repository's access and Actions permissions). The annotation comes from `metadata.repository` in `plugin.yaml` when it is an `https` URL, or from `--source ` on `atmos plugin pack` and `atmos plugin release`; `--source=github-actions` derives it from `GITHUB_SERVER_URL` and `GITHUB_REPOSITORY`. Nothing is derived from the environment unless you ask, and a URL with credentials, a query string, or a fragment is rejected. The release also records the package title, description, and version as `org.opencontainers.image.title`, `.description`, and `.version`. + Configure the `plugin-release` environment to allow trusted `main` releases and any required organization approval policy. Ensure its `GITHUB_TOKEN` can read and write the packages, and that keyless signing has `id-token: write`. Restrict catalog writes to this workflow. Manual dispatch of the **Tests** workflow on `main` reruns the full validation and publication pipeline; it is not a bypass. Public visibility is necessary for distribution, but does not grant trust. Consumers may additionally require signatures and an explicit trusted publisher policy. diff --git a/plugins/terragrunt/README.md b/plugins/terragrunt/README.md index 0089e841b5c..f731835441c 100644 --- a/plugins/terragrunt/README.md +++ b/plugins/terragrunt/README.md @@ -84,14 +84,23 @@ A unit without a stable `remote_state` path keeps local state under `.terragrunt `dependencies.tools` is read from stack manifests and component sections, not from `atmos.yaml`. Units have no stack manifest, so a unit takes its tool pins from `.tool-versions`. -Unsupported semantics fail before any infrastructure command and never switch executors. Currently rejected: inline modules without `terraform.source`; output dependencies with a non-default workspace during discovery; stack-level overrides of a unit's backend, `metadata.component`, or `source.uri`; and an invalid `on_errors` expression. Not implemented: Terragrunt's built-in default retry list, `--no-auto-retry`, and `errors` handling around `read-config` hooks. Executable mode, typed provider flags and help, exact cty types and sensitivity, scoped Terragrunt logging, migration and setup generation, and Atmos Pro integration remain in the PRDs. +Unsupported semantics fail before any infrastructure command and never switch executors. Currently rejected: inline modules without `terraform.source`; output dependencies with a non-default workspace during discovery; stack-level overrides of a unit's backend, `metadata.component`, or `source.uri`; and an invalid `on_errors` expression. Not implemented: Terragrunt's built-in default retry list, `--no-auto-retry`, and `errors` handling around `read-config` hooks. Migration and setup generation (`atmos migrate terragrunt`) remains in the PRD. -`terraform_binary` is published as the unit's `command`, so precedence is stack `command`, then the unit's `terraform_binary`, then `components.terraform.command`; the host errors if Prepare returns a different binary. `errors` policies wrap each Terraform subprocess phase and the source fetch in the host (`pkg/component/execution/recovery.go`). `exclude` is read from `settings.terragrunt.exclude` by the scheduler (`pkg/scheduler/adapters/terraform_exclude.go`); `no_run` is applied by the plugin for the current operation because the protocol carries no `no_run` field. A built-in `tflint` hook expands into `tflint --init` and a `tflint` run. IAM roles are assumed in the host through a transient `aws/assume-role` identity (`pkg/auth/identities/aws/inline_role.go`). AWS SDK calls evaluated inside the plugin read only the plugin's process environment and static keys from the invocation, so file-based Atmos identities are not yet visible to `get_aws_account_id()` and similar functions. `tfr://` sources resolve through the upstream registry client (`bridge/registry.go`). +`terraform_binary` is published as the unit's `command`, so precedence is stack `command`, then the unit's `terraform_binary`, then `components.terraform.command`; the host errors if Prepare returns a different binary. `errors` policies wrap each Terraform subprocess phase and the source fetch in the host (`pkg/component/execution/recovery.go`). `exclude` is read from `settings.terragrunt.exclude` by the scheduler (`pkg/scheduler/adapters/terraform_exclude.go`); `no_run` is applied by the plugin for the current operation because the protocol carries no `no_run` field. A built-in `tflint` hook expands into `tflint --init` and a `tflint` run. IAM roles are assumed in the host through a transient `aws/assume-role` identity (`pkg/auth/identities/aws/inline_role.go`). AWS SDK calls evaluated inside the plugin resolve credentials from the invocation environment (`bridge/aws.go`) without reading or changing the plugin's process environment. `tfr://` sources resolve through the upstream registry client (`bridge/registry.go`). Unsupported settings fail with an error that names the unit, the file, and the setting, plus the line and column when the evaluator reports a position (settings rejected after decoding, such as `terraform_binary`, name only the file). A broken unit does not affect other units or YAML components: it stays listed, and only commands that target it fail. `apply`, `plan`, and `destroy` with `--all` validate every selected unit first and fail with "no infrastructure command was run". Evaluation errors can contain secrets, so Atmos shows the file, line, unit, and a hint but not the evaluator's text; run with `ATMOS_LOGS_LEVEL=Debug` to log the full message with secrets masked. Plugin settings are validated when first used, not when `atmos.yaml` loads, so `atmos config set` can always repair them. Unknown keys under `components.terraform.terragrunt` and invalid `mode` values fail with the key name. With `discovery.enabled: true` and no `included_paths`, discovery covers every unit under the project root. Only enabled/mode/provider/discovery settings are accepted by this package. Additional plugin settings and typed CLI option handling remain planned. Discovery that needs command execution, decryption, network access, or identity-dependent effects fails. The native plugin is trusted code, not an OS sandbox. +## Options, modes, values, logs, and Pro + +- **Options.** `plugin.yaml` declares the provider options (`modes`, `options`) so `pkg/component/provideroptions` can register flags on `atmos terraform` commands and render help without starting the plugin. Only options the user set are sent in `ComponentOperation.options`, and they are part of the saved-plan identity. +- **Executable mode.** The plugin discovers units and reports engine `terragrunt`; `pkg/component/terragruntexec` runs `terragrunt --working-dir run [flags] -- ` per unit and refuses native preparation. Terragrunt 1.2.1 was verified against the real binary; the minimum supported version, 1.0.0, is unverified. +- **Values.** Inputs cross the boundary as exact cty values. Upstream discards marks, so sensitivity is detected from the unit's HCL (`sensitive(...)` directly or through locals, object literals, `merge()`, and conditionals); a value that becomes sensitive through another function is not tracked. +- **Logs.** Terragrunt log events return with each response (`LogEntry`) and are rendered through the Atmos logger at Debug or Trace. They are delivered when the call ends, not live. +- **Pro.** Units are ordinary Terraform components in uploads. The plan record travels in the planfile bundle as `plan.tfplan.atmos.json`, and apply re-provisions the working directory and verifies it against the recorded rebuild digest. `deploy` against a stored plan on a fresh runner is not supported; use `planfile download` and `apply --from-plan`. +- **Release.** Published plugin manifests carry `org.opencontainers.image.source`, set from `metadata.repository` or `--source`. Install with `atmos plugin install`; `ATMOS_PROFILE=dev` supplies a local path for development only. + ## Maintained upstream facade The package pins Terragrunt v1.2.1. Some required upstream facilities are in `internal` packages. The local `bridge/` module uses the import path `github.com/gruntwork-io/terragrunt/pkg/atmosbridge`, which satisfies Go's internal-package import rule. This is an Atmos-maintained facade, not a public upstream Go API or an upstream-published module. A checked-in relative module replacement resolves it to this package's source. diff --git a/plugins/terragrunt/bridge/aws.go b/plugins/terragrunt/bridge/aws.go new file mode 100644 index 00000000000..7436777c8f1 --- /dev/null +++ b/plugins/terragrunt/bridge/aws.go @@ -0,0 +1,345 @@ +package atmosbridge + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "errors" + "fmt" + "maps" + "net/http" + "net/url" + "os" + "slices" + "strconv" + "strings" + "sync" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/credentials/stscreds" + "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" + "github.com/aws/aws-sdk-go-v2/service/sts" + "github.com/gruntwork-io/terragrunt/internal/awshelper" + "github.com/gruntwork-io/terragrunt/internal/iam" + "github.com/gruntwork-io/terragrunt/internal/venv" + "github.com/gruntwork-io/terragrunt/internal/vhttp" +) + +// Upstream builds every AWS configuration with config.LoadDefaultConfig, which reads the plugin PROCESS +// environment. The invocation environment, which holds the selected Atmos identity (AWS_PROFILE and +// the shared credentials and config files), is invisible to it. The plugin serves concurrent +// invocations, so it must never copy the invocation into its own environment. Upstream does read three +// things from the venv it is handed: static keys in the venv environment, the region, and the HTTP +// client. AWS uses exactly those seams: it resolves the invocation's credentials with explicit SDK +// options, hands them to upstream as static keys, and routes endpoint overrides through the client. + +const ( + awsDefaultRegion = "us-east-1" + awsResolveTimeout = 30 * time.Second + // Placeholder for credentials that could not be resolved. Upstream then pins static + // credentials and signs with them, and the transport answers every AWS request with the real reason. + awsUnresolvedKey = "ATMOS_UNRESOLVED_AWS_CREDENTIALS" + // Margin before expiry at which cached credentials are refreshed. + awsExpiryMargin = time.Minute + decimalBase = 10 + int64Bits = 64 + envAccessKeyID = "AWS_ACCESS_KEY_ID" + envSecretKey = "AWS_SECRET_ACCESS_KEY" + envSessionToken = "AWS_SESSION_TOKEN" + envEndpointURL = "AWS_ENDPOINT_URL" +) + +// awsSelectors name the invocation variables that choose where credentials come from. +var awsSelectors = []string{"AWS_PROFILE", "AWS_DEFAULT_PROFILE", "AWS_SHARED_CREDENTIALS_FILE", "AWS_CONFIG_FILE", "AWS_WEB_IDENTITY_TOKEN_FILE"} + +// awsCache holds credentials resolved for an invocation selection until they expire. The key covers +// every selector and the shared files' size and time, so re-authentication invalidates it. +var awsCache = struct { + sync.Mutex + entries map[string]aws.Credentials +}{entries: map[string]aws.Credentials{}} + +// AWS adapts v so that the AWS calls Terragrunt makes while evaluating a unit (get_aws_account_id, +// get_aws_caller_identity_arn, get_aws_caller_identity_user_id, S3 dependency state reads, and role +// assumption) use the invocation environment in v: the selected profile, shared credentials and config +// files, web identity token file, static keys, TG_IAM_ASSUME_ROLE, and AWS_ENDPOINT_URL[_]. +// The plugin process environment is not read or changed. Use it only for phases that may use the +// network; read-only discovery must not call it. +// +// Credentials that cannot be resolved never fail evaluation by themselves: a unit that does not call +// AWS is unaffected. A unit that does gets an error that names the cause instead of a misleading +// fallback to whatever credentials the plugin process happens to hold. +// +//nolint:lintroller // The bridge is a separate module and cannot import the host performance tracker. +func AWS(ctx context.Context, v *venv.Venv) *venv.Venv { + env := maps.Clone(v.Env) + if env == nil { + env = map[string]string{} + } + transport := &awsTransport{next: v.HTTP.Transport, endpoints: awsEndpoints(env)} + if !hasStaticAWSKeys(env) && selectsAWSCredentials(env) { + credentials, err := cachedCredentials(awsCacheKey(env), func() (aws.Credentials, error) { return resolveAWSCredentials(ctx, env, transport) }) + transport.apply(env, &credentials, err) + } + if role := roleOptions(env); role.RoleARN != "" && transport.failure == nil { + key := awsCacheKey(env) + "|" + role.RoleARN + "|" + role.AssumeRoleSessionName + "|" + env[envAccessKeyID] + credentials, err := cachedCredentials(key, func() (aws.Credentials, error) { return assumeInvocationRole(ctx, v.WithEnv(env), transport, role) }) + transport.apply(env, &credentials, err) + } + if !transport.active() { + return v.WithEnv(env) + } + return v.WithHTTP(vhttp.WithTransport(v.HTTP, transport)).WithEnv(env) +} + +// hasStaticAWSKeys reports whether upstream already pins credentials from the environment. +func hasStaticAWSKeys(env map[string]string) bool { + return env[envAccessKeyID] != "" && env[envSecretKey] != "" +} + +func selectsAWSCredentials(env map[string]string) bool { + return slices.ContainsFunc(awsSelectors, func(name string) bool { return env[name] != "" }) +} + +// roleOptions reads the CLI-level IAM role settings, which upstream applies to its own AWS calls. +func roleOptions(env map[string]string) iam.RoleOptions { + pick := func(names ...string) string { + for _, name := range names { + if env[name] != "" { + return env[name] + } + } + return "" + } + duration, _ := strconv.ParseInt(pick("TG_IAM_ASSUME_ROLE_DURATION", "TERRAGRUNT_IAM_ASSUME_ROLE_DURATION"), decimalBase, int64Bits) + return iam.RoleOptions{ + RoleARN: pick("TG_IAM_ASSUME_ROLE", "TERRAGRUNT_IAM_ROLE"), + AssumeRoleSessionName: pick("TG_IAM_ASSUME_ROLE_SESSION_NAME", "TERRAGRUNT_IAM_ASSUME_ROLE_SESSION_NAME"), + WebIdentityToken: pick("TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN", "TERRAGRUNT_IAM_WEB_IDENTITY_TOKEN", "TERRAGRUNT_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN"), + AssumeRoleDuration: duration, + } +} + +// assumeInvocationRole assumes the CLI-level role with the credentials already in v. +func assumeInvocationRole(ctx context.Context, v *venv.Venv, transport *awsTransport, role iam.RoleOptions) (aws.Credentials, error) { + ctx, cancel := context.WithTimeout(ctx, awsResolveTimeout) + defer cancel() + // AssumeIamRole reads the HTTP client of the venv, so it must see the endpoint overrides. + assumed, err := awshelper.AssumeIamRole(ctx, v.WithHTTP(vhttp.WithTransport(v.HTTP, transport)), role, "") + if err != nil { + return aws.Credentials{}, fmt.Errorf("assuming the IAM role %s from the invocation environment: %w", role.RoleARN, err) + } + return aws.Credentials{ + AccessKeyID: aws.ToString(assumed.AccessKeyId), SecretAccessKey: aws.ToString(assumed.SecretAccessKey), + SessionToken: aws.ToString(assumed.SessionToken), CanExpire: assumed.Expiration != nil, Expires: aws.ToTime(assumed.Expiration), + }, nil +} + +// apply installs credentials in env as static keys, or records why they are unavailable. +func (t *awsTransport) apply(env map[string]string, credentials *aws.Credentials, err error) { + if err != nil { + t.failure = err + env[envAccessKeyID], env[envSecretKey], env[envSessionToken] = awsUnresolvedKey, awsUnresolvedKey, "" + return + } + env[envAccessKeyID], env[envSecretKey], env[envSessionToken] = credentials.AccessKeyID, credentials.SecretAccessKey, credentials.SessionToken +} + +// cachedCredentials loads credentials once per key, until they expire. +func cachedCredentials(key string, load func() (aws.Credentials, error)) (aws.Credentials, error) { + awsCache.Lock() + cached, found := awsCache.entries[key] + awsCache.Unlock() + if found && (!cached.CanExpire || time.Until(cached.Expires) > awsExpiryMargin) { + return cached, nil + } + credentials, err := load() + if err != nil { + return aws.Credentials{}, err + } + awsCache.Lock() + awsCache.entries[key] = credentials + awsCache.Unlock() + return credentials, nil +} + +func awsCacheKey(env map[string]string) string { + hash := sha256.New() + names := append(slices.Clone(awsSelectors), "AWS_ROLE_ARN", "AWS_ROLE_SESSION_NAME", "AWS_REGION", "AWS_DEFAULT_REGION") + for name := range maps.Keys(env) { + if strings.HasPrefix(name, envEndpointURL) { + names = append(names, name) + } + } + slices.Sort(names) + for _, name := range names { + fmt.Fprintf(hash, "%s=%s\n", name, env[name]) + if strings.HasSuffix(name, "_FILE") && env[name] != "" { + if info, err := os.Stat(env[name]); err == nil { + fmt.Fprintf(hash, "stat=%d:%d\n", info.Size(), info.ModTime().UnixNano()) + } + } + } + return hex.EncodeToString(hash.Sum(nil)) +} + +// resolveAWSCredentials loads the invocation's selection with explicit SDK options. An explicit profile +// outranks the static keys of the plugin process, which the SDK would otherwise prefer. +func resolveAWSCredentials(ctx context.Context, env map[string]string, transport *awsTransport) (aws.Credentials, error) { + ctx, cancel := context.WithTimeout(ctx, awsResolveTimeout) + defer cancel() + cfg, err := config.LoadDefaultConfig(ctx, loadOptions(env, transport)...) + if err != nil { + return aws.Credentials{}, fmt.Errorf("loading the AWS configuration selected by the invocation environment: %w", err) + } + if env["AWS_PROFILE"] == "" && env["AWS_DEFAULT_PROFILE"] == "" && env["AWS_WEB_IDENTITY_TOKEN_FILE"] != "" && env["AWS_ROLE_ARN"] != "" { + provider := stscreds.NewWebIdentityRoleProvider(sts.NewFromConfig(cfg), env["AWS_ROLE_ARN"], stscreds.IdentityTokenFile(env["AWS_WEB_IDENTITY_TOKEN_FILE"]), func(o *stscreds.WebIdentityRoleOptions) { + o.RoleSessionName = env["AWS_ROLE_SESSION_NAME"] + }) + cfg.Credentials = aws.NewCredentialsCache(provider) + } + credentials, err := cfg.Credentials.Retrieve(ctx) + if err != nil { + return aws.Credentials{}, fmt.Errorf("resolving AWS credentials from the invocation environment (profile %q): %w", profileName(env), err) + } + return credentials, nil +} + +func profileName(env map[string]string) string { + if name := env["AWS_PROFILE"]; name != "" { + return name + } + if name := env["AWS_DEFAULT_PROFILE"]; name != "" { + return name + } + return "default" +} + +func loadOptions(env map[string]string, transport *awsTransport) []func(*config.LoadOptions) error { + region := env["AWS_REGION"] + if region == "" { + region = env["AWS_DEFAULT_REGION"] + } + if region == "" { + region = awsDefaultRegion + } + // The transport carries the endpoint overrides for the STS calls that role and web identity profiles make. + options := []func(*config.LoadOptions) error{ + config.WithRegion(region), + config.WithHTTPClient(&http.Client{Transport: transport, Timeout: awsResolveTimeout}), + } + if profile := cmpFirst(env["AWS_PROFILE"], env["AWS_DEFAULT_PROFILE"]); profile != "" { + options = append(options, config.WithSharedConfigProfile(profile)) + } + if file := env["AWS_SHARED_CREDENTIALS_FILE"]; file != "" { + options = append(options, config.WithSharedCredentialsFiles([]string{file})) + } + if file := env["AWS_CONFIG_FILE"]; file != "" { + options = append(options, config.WithSharedConfigFiles([]string{file})) + } + if strings.EqualFold(env["AWS_EC2_METADATA_DISABLED"], "true") { + options = append(options, config.WithEC2IMDSClientEnableState(imds.ClientDisabled)) + } + return options +} + +func cmpFirst(values ...string) string { + for _, value := range values { + if value != "" { + return value + } + } + return "" +} + +// awsTransport sends AWS-bound requests to the endpoints the invocation overrides, and answers them with +// the resolution failure when the invocation's credentials could not be resolved. Requests to other +// hosts pass through untouched. The request keeps its original Host header and path, so the SigV4 +// signature the SDK computed for the AWS endpoint stays valid at an endpoint that checks it. +type awsTransport struct { + next http.RoundTripper + endpoints map[string]*url.URL + failure error +} + +// active reports whether the transport has anything to do. +func (t *awsTransport) active() bool { return t.failure != nil || len(t.endpoints) > 0 } + +// ErrAWSCredentials marks a request that could not be signed with the invocation's credentials. +var ErrAWSCredentials = errors.New("the AWS credentials of the invocation environment could not be resolved") + +// unresolvedError is the answer to an AWS request that has no usable credentials. The SDK must not retry it. +type unresolvedError struct{ cause error } + +//nolint:lintroller // The bridge is a separate module and cannot import the host performance tracker. +func (e unresolvedError) Error() string { return ErrAWSCredentials.Error() + ": " + e.cause.Error() } + +//nolint:lintroller // The bridge is a separate module and cannot import the host performance tracker. +func (e unresolvedError) Unwrap() []error { return []error{ErrAWSCredentials, e.cause} } + +//nolint:lintroller // The bridge is a separate module and cannot import the host performance tracker. +func (e unresolvedError) RetryableError() bool { return false } + +//nolint:lintroller // The bridge is a separate module and cannot import the host performance tracker. +func (t *awsTransport) RoundTrip(req *http.Request) (*http.Response, error) { + next := t.next + if next == nil { + next = http.DefaultTransport + } + if !isAWSHost(req.URL.Hostname()) { + return next.RoundTrip(req) + } + if t.failure != nil { + return nil, unresolvedError{cause: t.failure} + } + target := t.endpointFor(req.URL.Hostname()) + if target == nil { + return next.RoundTrip(req) + } + clone := req.Clone(req.Context()) + clone.Host = req.URL.Host + clone.URL.Scheme, clone.URL.Host = target.Scheme, target.Host + return next.RoundTrip(clone) +} + +func isAWSHost(host string) bool { + return strings.HasSuffix(host, ".amazonaws.com") || strings.HasSuffix(host, ".amazonaws.com.cn") +} + +// endpointFor picks the service-specific override for host, falling back to the global one. +func (t *awsTransport) endpointFor(host string) *url.URL { + labels := strings.Split(host, ".") + candidates := []string{labels[0]} + if slices.ContainsFunc(labels, func(label string) bool { return label == "s3" || strings.HasPrefix(label, "s3-") }) { + candidates = []string{"s3"} + } + for _, service := range candidates { + if target := t.endpoints[service]; target != nil { + return target + } + } + return t.endpoints[""] +} + +// awsEndpoints reads AWS_ENDPOINT_URL and AWS_ENDPOINT_URL_. The global entry has the empty key. +// A service key is lower case without separators, matching the first label of the service's host name. +func awsEndpoints(env map[string]string) map[string]*url.URL { + endpoints := map[string]*url.URL{} + for name, value := range env { + if value == "" || !strings.HasPrefix(name, envEndpointURL) { + continue + } + service := strings.TrimPrefix(strings.TrimPrefix(name, envEndpointURL), "_") + if name != envEndpointURL && service == "" { + continue + } + target, err := url.Parse(value) + if err != nil || target.Host == "" || (target.Scheme != "http" && target.Scheme != "https") { + continue + } + endpoints[strings.ToLower(strings.NewReplacer("_", "", "-", "").Replace(service))] = target + } + return endpoints +} diff --git a/plugins/terragrunt/bridge/aws_test.go b/plugins/terragrunt/bridge/aws_test.go new file mode 100644 index 00000000000..88a341ff0c5 --- /dev/null +++ b/plugins/terragrunt/bridge/aws_test.go @@ -0,0 +1,320 @@ +package atmosbridge + +import ( + "errors" + "fmt" + "io" + "maps" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "regexp" + "slices" + "strings" + "sync" + "testing" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/gruntwork-io/terragrunt/internal/awshelper" + "github.com/gruntwork-io/terragrunt/internal/venv" + "github.com/gruntwork-io/terragrunt/pkg/log" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const testAccount = "123456789012" + +// stsServer answers the two STS actions Terragrunt issues and records who signed each request. +type stsServer struct { + *httptest.Server + mu sync.Mutex + signers []string + actions []string + hosts []string +} + +var credentialPattern = regexp.MustCompile(`Credential=([^/]+)/`) + +func newSTSServer(t *testing.T) *stsServer { + t.Helper() + server := &stsServer{} + server.Server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, _ := io.ReadAll(r.Body) + signer := "" + if match := credentialPattern.FindStringSubmatch(r.Header.Get("Authorization")); match != nil { + signer = match[1] + } + action := "GetCallerIdentity" + if strings.Contains(string(body), "Action=AssumeRole") { + action = "AssumeRole" + } + server.mu.Lock() + server.signers, server.actions, server.hosts = append(server.signers, signer), append(server.actions, action), append(server.hosts, r.Host) + server.mu.Unlock() + w.Header().Set("Content-Type", "text/xml") + if action == "AssumeRole" { + expires := time.Now().Add(time.Hour).UTC().Format(time.RFC3339) + fmt.Fprintf(w, `ASIAASSUMEDassumed-secretassumed-token%s`, expires) + return + } + fmt.Fprintf(w, `arn:aws:iam::%s:user/atmosAIDATEST%s`, testAccount, testAccount) + })) + t.Cleanup(server.Close) + return server +} + +func (s *stsServer) seen() (signers, actions []string) { + s.mu.Lock() + defer s.mu.Unlock() + return slices.Clone(s.signers), slices.Clone(s.actions) +} + +// writeProfile creates a shared credentials file with one profile and an empty config file. +func writeProfile(t *testing.T, profile, key string) (credentialsFile, configFile string) { + t.Helper() + dir := t.TempDir() + credentialsFile, configFile = filepath.Join(dir, "credentials"), filepath.Join(dir, "config") + content := fmt.Sprintf("[%s]\naws_access_key_id = %s\naws_secret_access_key = secret-%s\naws_session_token = token-%s\n", profile, key, key, key) + require.NoError(t, os.WriteFile(credentialsFile, []byte(content), 0o600)) + require.NoError(t, os.WriteFile(configFile, nil, 0o600)) + return credentialsFile, configFile +} + +// accountID asks upstream for the caller identity exactly as get_aws_account_id() does. +func accountID(t *testing.T, scoped *venv.Venv) (string, error) { + t.Helper() + logger := log.New(log.WithOutput(io.Discard)) + cfg, err := awshelper.NewAWSConfigBuilder().Build(t.Context(), logger, scoped) + require.NoError(t, err) + return awshelper.GetAWSAccountID(t.Context(), &cfg) +} + +func TestAWSHonorsProfileFilesAndEndpointFromInvocationOnly(t *testing.T) { + server := newSTSServer(t) + credentials, configFile := writeProfile(t, "atmos-identity", "AKIAINVOCATION") + before := os.Environ() + env := map[string]string{ + "AWS_PROFILE": "atmos-identity", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile, + "AWS_ENDPOINT_URL_STS": server.URL, "AWS_REGION": "eu-west-1", "AWS_EC2_METADATA_DISABLED": "true", + } + + account, err := accountID(t, AWS(t.Context(), Environment(env, io.Discard, io.Discard))) + + require.NoError(t, err) + assert.Equal(t, testAccount, account) + signers, actions := server.seen() + assert.Equal(t, []string{"AKIAINVOCATION"}, signers, "the profile of the invocation signs the call") + assert.Equal(t, []string{"GetCallerIdentity"}, actions) + assert.Equal(t, before, os.Environ(), "the plugin process environment is unchanged") + assert.Empty(t, os.Getenv("AWS_PROFILE")) + assert.NotContains(t, env, "AWS_ACCESS_KEY_ID", "the caller's map is never mutated") +} + +func TestAWSIgnoresProcessProfileWhenInvocationSelectsAnother(t *testing.T) { + server := newSTSServer(t) + processCredentials, processConfig := writeProfile(t, "process-profile", "AKIAPROCESS") + t.Setenv("AWS_PROFILE", "process-profile") + t.Setenv("AWS_SHARED_CREDENTIALS_FILE", processCredentials) + t.Setenv("AWS_CONFIG_FILE", processConfig) + t.Setenv("AWS_ACCESS_KEY_ID", "AKIAAMBIENT") + t.Setenv("AWS_SECRET_ACCESS_KEY", "ambient") + credentials, configFile := writeProfile(t, "selected", "AKIASELECTED") + env := map[string]string{ + "AWS_PROFILE": "selected", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile, + "AWS_ENDPOINT_URL": server.URL, "AWS_EC2_METADATA_DISABLED": "true", + } + + _, err := accountID(t, AWS(t.Context(), Environment(env, io.Discard, io.Discard))) + + require.NoError(t, err) + signers, _ := server.seen() + assert.Equal(t, []string{"AKIASELECTED"}, signers, "ambient process credentials never outrank the selected identity") + assert.Equal(t, "process-profile", os.Getenv("AWS_PROFILE")) +} + +func TestAWSKeepsStaticKeysAndRoutesEndpointOnly(t *testing.T) { + server := newSTSServer(t) + env := map[string]string{"AWS_ACCESS_KEY_ID": "AKIASTATIC", "AWS_SECRET_ACCESS_KEY": "secret", "AWS_ENDPOINT_URL_STS": server.URL, "AWS_PROFILE": "ignored"} + + _, err := accountID(t, AWS(t.Context(), Environment(env, io.Discard, io.Discard))) + + require.NoError(t, err) + signers, _ := server.seen() + assert.Equal(t, []string{"AKIASTATIC"}, signers) +} + +func TestAWSAssumesCommandLevelRoleOnTopOfProfile(t *testing.T) { + server := newSTSServer(t) + credentials, configFile := writeProfile(t, "base", "AKIABASE") + env := map[string]string{ + "AWS_PROFILE": "base", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile, + "AWS_ENDPOINT_URL_STS": server.URL, "AWS_EC2_METADATA_DISABLED": "true", + "TG_IAM_ASSUME_ROLE": "arn:aws:iam::123456789012:role/deploy", "TG_IAM_ASSUME_ROLE_SESSION_NAME": "atmos", + } + + _, err := accountID(t, AWS(t.Context(), Environment(env, io.Discard, io.Discard))) + + require.NoError(t, err) + signers, actions := server.seen() + assert.Equal(t, []string{"AssumeRole", "GetCallerIdentity"}, actions) + assert.Equal(t, []string{"AKIABASE", "ASIAASSUMED"}, signers, "the role is assumed with the profile, and the assumed session answers the identity call") +} + +func TestAWSNamesTheCauseWhenCredentialsCannotBeResolved(t *testing.T) { + server := newSTSServer(t) + credentials, configFile := writeProfile(t, "present", "AKIAPRESENT") + env := map[string]string{ + "AWS_PROFILE": "missing", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile, + "AWS_ENDPOINT_URL_STS": server.URL, "AWS_EC2_METADATA_DISABLED": "true", + } + + _, err := accountID(t, AWS(t.Context(), Environment(env, io.Discard, io.Discard))) + + require.Error(t, err) + require.ErrorIs(t, err, ErrAWSCredentials) + assert.Contains(t, err.Error(), "missing") + signers, _ := server.seen() + assert.Empty(t, signers, "no request leaves with substitute credentials") +} + +func TestAWSLeavesEnvironmentWithoutSelectorsAlone(t *testing.T) { + base := Environment(map[string]string{"PATH": "/bin"}, io.Discard, io.Discard) + + scoped := AWS(t.Context(), base) + + assert.Equal(t, base.Env, scoped.Env) + assert.Same(t, base.HTTP, scoped.HTTP, "the HTTP client is replaced only when an override or failure needs it") +} + +func TestAWSTransportRoutesByService(t *testing.T) { + var mu sync.Mutex + hits := map[string][]string{} + handler := func(name string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + hits[name] = append(hits[name], r.Host+r.URL.Path) + mu.Unlock() + }) + } + global, sts, s3 := httptest.NewServer(handler("global")), httptest.NewServer(handler("sts")), httptest.NewServer(handler("s3")) + t.Cleanup(global.Close) + t.Cleanup(sts.Close) + t.Cleanup(s3.Close) + other := httptest.NewServer(handler("other")) + t.Cleanup(other.Close) + transport := &awsTransport{endpoints: awsEndpoints(map[string]string{ + "AWS_ENDPOINT_URL": global.URL, "AWS_ENDPOINT_URL_STS": sts.URL, "AWS_ENDPOINT_URL_S3": s3.URL, "AWS_ENDPOINT_URL_BAD": "not a url", + })} + client := &http.Client{Transport: transport} + + for _, target := range []string{ + "https://sts.us-east-1.amazonaws.com/", "https://bucket.s3.us-west-2.amazonaws.com/key", "https://dynamodb.us-east-1.amazonaws.com/", other.URL + "/untouched", + } { + response, err := client.Get(target) + require.NoError(t, err) + _ = response.Body.Close() + } + + mu.Lock() + defer mu.Unlock() + assert.Equal(t, []string{"sts.us-east-1.amazonaws.com/"}, hits["sts"], "the original host name and path are kept for signature validation") + assert.Equal(t, []string{"bucket.s3.us-west-2.amazonaws.com/key"}, hits["s3"]) + assert.Equal(t, []string{"dynamodb.us-east-1.amazonaws.com/"}, hits["global"]) + assert.Len(t, hits["other"], 1, "hosts outside AWS are never rewritten") + assert.Contains(t, hits["other"][0], "/untouched") +} + +func TestAWSTransportFailureOnlyAffectsAWSHosts(t *testing.T) { + cause := errors.New("boom") + transport := &awsTransport{failure: cause} + client := &http.Client{Transport: transport} + local := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + t.Cleanup(local.Close) + + failed, err := client.Get("https://sts.us-east-1.amazonaws.com/") + if failed != nil { + _ = failed.Body.Close() + } + require.ErrorIs(t, err, ErrAWSCredentials) + require.ErrorIs(t, err, cause) + response, err := client.Get(local.URL) + require.NoError(t, err) + _ = response.Body.Close() +} + +func TestAWSEndpointsNormalizeServiceNames(t *testing.T) { + endpoints := awsEndpoints(map[string]string{ + "AWS_ENDPOINT_URL_SECRETS_MANAGER": "http://127.0.0.1:1", "AWS_ENDPOINT_URL_": "http://127.0.0.1:2", "AWS_ENDPOINT_URL_STS": "", + "AWS_ENDPOINT_URL_KMS": "ftp://127.0.0.1:3", "OTHER": "http://127.0.0.1:4", + }) + + assert.Len(t, endpoints, 1) + assert.Equal(t, "127.0.0.1:1", endpoints["secretsmanager"].Host) +} + +func TestAWSCredentialCacheReusesUnexpiredEntriesOnly(t *testing.T) { + loads := 0 + loader := func(expires time.Time) func() (aws.Credentials, error) { + return func() (aws.Credentials, error) { + loads++ + return aws.Credentials{AccessKeyID: fmt.Sprintf("AKIA%d", loads), CanExpire: !expires.IsZero(), Expires: expires}, nil + } + } + + first, err := cachedCredentials(t.Name()+"/static", loader(time.Time{})) + require.NoError(t, err) + second, err := cachedCredentials(t.Name()+"/static", loader(time.Time{})) + require.NoError(t, err) + assert.Equal(t, first, second, "credentials without an expiry are loaded once") + assert.Equal(t, 1, loads) + + _, err = cachedCredentials(t.Name()+"/expiring", loader(time.Now().Add(time.Second))) + require.NoError(t, err) + refreshed, err := cachedCredentials(t.Name()+"/expiring", loader(time.Now().Add(time.Hour))) + require.NoError(t, err) + assert.Equal(t, "AKIA3", refreshed.AccessKeyID, "credentials inside the expiry margin are reloaded") + + _, err = cachedCredentials(t.Name()+"/failing", func() (aws.Credentials, error) { return aws.Credentials{}, errors.New("denied") }) + require.Error(t, err) + _, found := awsCache.entries[t.Name()+"/failing"] + assert.False(t, found, "a failure is never cached") +} + +func TestAWSCacheKeyTracksSelectionAndFileChanges(t *testing.T) { + credentials, configFile := writeProfile(t, "cached", "AKIACACHED") + env := map[string]string{"AWS_PROFILE": "cached", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile} + key := awsCacheKey(env) + + assert.Equal(t, key, awsCacheKey(maps.Clone(env))) + other := maps.Clone(env) + other["AWS_PROFILE"] = "another" + assert.NotEqual(t, key, awsCacheKey(other)) + require.NoError(t, os.WriteFile(credentials, []byte("[cached]\naws_access_key_id = AKIAROTATED\naws_secret_access_key = rotated-secret\n"), 0o600)) + assert.NotEqual(t, key, awsCacheKey(env), "rewriting the credentials file invalidates the cache entry") +} + +func TestAWSWebIdentityRoleFromInvocationTokenFile(t *testing.T) { + var gotAction string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, _ := io.ReadAll(r.Body) + gotAction = string(body) + w.Header().Set("Content-Type", "text/xml") + fmt.Fprintf(w, `ASIAWEBwebweb-token%s`, time.Now().Add(time.Hour).UTC().Format(time.RFC3339)) + })) + t.Cleanup(server.Close) + token := filepath.Join(t.TempDir(), "token") + require.NoError(t, os.WriteFile(token, []byte("jwt"), 0o600)) + env := map[string]string{ + "AWS_WEB_IDENTITY_TOKEN_FILE": token, "AWS_ROLE_ARN": "arn:aws:iam::123456789012:role/web", "AWS_ROLE_SESSION_NAME": "atmos-web", + "AWS_ENDPOINT_URL_STS": server.URL, "AWS_EC2_METADATA_DISABLED": "true", + } + + scoped := AWS(t.Context(), Environment(env, io.Discard, io.Discard)) + + assert.Equal(t, "ASIAWEB", scoped.Env["AWS_ACCESS_KEY_ID"]) + assert.Equal(t, "web-token", scoped.Env["AWS_SESSION_TOKEN"]) + assert.Contains(t, gotAction, "AssumeRoleWithWebIdentity") + assert.Contains(t, gotAction, "RoleSessionName=atmos-web") +} diff --git a/plugins/terragrunt/bridge/go.mod b/plugins/terragrunt/bridge/go.mod index d8f0da01c41..d5037cfef81 100644 --- a/plugins/terragrunt/bridge/go.mod +++ b/plugins/terragrunt/bridge/go.mod @@ -3,6 +3,11 @@ module github.com/gruntwork-io/terragrunt/pkg/atmosbridge go 1.27.3 require ( + github.com/aws/aws-sdk-go-v2 v1.47.4 + github.com/aws/aws-sdk-go-v2/config v1.33.10 + github.com/aws/aws-sdk-go-v2/credentials v1.20.10 + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.20.4 + github.com/aws/aws-sdk-go-v2/service/sts v1.51.5 github.com/gruntwork-io/terragrunt v1.2.1 github.com/spf13/afero v1.15.0 github.com/stretchr/testify v1.12.1 @@ -46,11 +51,7 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/apparentlymart/go-textseg/v17 v17.0.1 // indirect github.com/apparentlymart/go-versions v1.0.3 // indirect - github.com/aws/aws-sdk-go-v2 v1.47.4 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.24 // indirect - github.com/aws/aws-sdk-go-v2/config v1.33.10 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.20.10 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.20.4 // indirect github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.22.34 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.7 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.7 // indirect @@ -67,7 +68,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/signin v1.10.5 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.38.5 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.43.5 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.51.5 // indirect github.com/aws/smithy-go v1.28.6 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect diff --git a/plugins/terragrunt/fixtures/toolprobe/main.go b/plugins/terragrunt/fixtures/toolprobe/main.go index feb5b5756df..ae7405e423b 100644 --- a/plugins/terragrunt/fixtures/toolprobe/main.go +++ b/plugins/terragrunt/fixtures/toolprobe/main.go @@ -1,9 +1,16 @@ // Command toolprobe stands in for a version-pinned OpenTofu in acceptance tests. It records // its arguments in invocations.log beside itself and then runs the real executable named in // real-tool.txt, so a test can prove which commands used the pinned copy. +// +// Installed under the name terragrunt it stands in for the Terragrunt executable instead. It +// answers --version, records the working directory, the arguments, and the TG_* environment of every +// command in terragrunt.log, and runs the engine command that follows `--` in the directory named by +// --working-dir. No real Terragrunt runs, so a test proves how Atmos invokes the executable, not how +// Terragrunt behaves. package main import ( + "encoding/json" "errors" "fmt" "os" @@ -31,11 +38,20 @@ func run() int { if err != nil { return fail(err) } + if strings.TrimSuffix(filepath.Base(self), ".exe") == "terragrunt" { + return terragrunt(directory, strings.TrimSpace(string(real)), os.Args[1:]) + } if err := record(filepath.Join(directory, "invocations.log"), os.Args[1:]); err != nil { return fail(err) } + return execute(strings.TrimSpace(string(real)), "", os.Args[1:]) +} + +// execute runs the real tool with the process streams. +func execute(tool, directory string, arguments []string) int { // The target is the path a test wrote beside this fixture, never external input. - command := exec.Command(strings.TrimSpace(string(real)), os.Args[1:]...) //nolint:gosec // Test fixture runs the tool it was told to wrap. + command := exec.Command(tool, arguments...) //nolint:gosec // Test fixture runs the tool it was told to wrap. + command.Dir = directory command.Stdin, command.Stdout, command.Stderr = os.Stdin, os.Stdout, os.Stderr if err := command.Run(); err != nil { var exit *exec.ExitError @@ -47,6 +63,66 @@ func run() int { return 0 } +// terragrunt answers like the executable: a version, or an engine command inside a unit. +func terragrunt(directory, tool string, arguments []string) int { + if len(arguments) == 1 && arguments[0] == "--version" { + version, err := os.ReadFile(filepath.Join(directory, "version.txt")) + if err != nil { + version = []byte("v9.9.9") + } + _, _ = os.Stdout.WriteString("terragrunt version " + strings.TrimSpace(string(version)) + "\n") + return 0 + } + working, engine := split(arguments) + if err := recordTerragrunt(filepath.Join(directory, "terragrunt.log"), working, arguments); err != nil { + return fail(err) + } + if _, err := os.Stat(filepath.Join(working, ".terraform")); err != nil && len(engine) > 0 && engine[0] != "init" { //nolint:gosec // The directory comes from the test that launched this fixture. + if code := execute(tool, working, []string{"init", "-input=false", "-no-color"}); code != 0 { + return code + } + } + return execute(tool, working, engine) +} + +// split returns the --working-dir value and the engine command that follows `--`. +func split(arguments []string) (working string, engine []string) { + engine = arguments + for index, argument := range arguments { + if argument == "--working-dir" && index+1 < len(arguments) { + working = arguments[index+1] + } + if argument == "--" { + return working, arguments[index+1:] + } + } + return working, engine +} + +func recordTerragrunt(path, working string, arguments []string) error { + environment := map[string]string{} + for _, entry := range os.Environ() { + if name, value, found := strings.Cut(entry, "="); found && strings.HasPrefix(name, "TG_") { + environment[name] = value + } + } + line, err := json.Marshal(map[string]any{"args": arguments, "dir": working, "env": environment}) + if err != nil { + return err + } + return appendLine(path, string(line)) +} + +func appendLine(path, line string) error { + file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, logMode) + if err != nil { + return err + } + defer file.Close() + _, err = fmt.Fprintln(file, line) + return err +} + func record(path string, arguments []string) error { file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, logMode) if err != nil { diff --git a/plugins/terragrunt/go.mod b/plugins/terragrunt/go.mod index 72620d64596..02fc9c716a6 100644 --- a/plugins/terragrunt/go.mod +++ b/plugins/terragrunt/go.mod @@ -9,10 +9,12 @@ require ( github.com/gruntwork-io/terragrunt/pkg/atmosbridge v0.0.0-00010101000000-000000000000 github.com/hashicorp/go-version v1.9.0 github.com/hashicorp/hcl/v2 v2.25.0 + github.com/sirupsen/logrus v1.10.2 github.com/spf13/afero v1.15.0 github.com/stretchr/testify v1.12.1 github.com/zclconf/go-cty v1.19.0 google.golang.org/grpc v1.84.0 + google.golang.org/protobuf v1.36.12 gopkg.in/yaml.v3 v3.0.1 ) @@ -175,7 +177,6 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect - github.com/sirupsen/logrus v1.10.2 // indirect github.com/spiffe/go-spiffe/v2 v2.8.1 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect github.com/ulikunitz/xz v0.5.16 // indirect @@ -231,7 +232,6 @@ require ( google.golang.org/genproto v0.0.0-20260720171339-e059f2f05d78 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20261019180522-ce908d29299b // indirect - google.golang.org/protobuf v1.36.12 // indirect gopkg.in/ini.v1 v1.67.3 // indirect oras.land/oras-go/v2 v2.7.0 // indirect ) diff --git a/plugins/terragrunt/internal/engine/logs.go b/plugins/terragrunt/internal/engine/logs.go new file mode 100644 index 00000000000..6338021484a --- /dev/null +++ b/plugins/terragrunt/internal/engine/logs.go @@ -0,0 +1,167 @@ +package engine + +import ( + "context" + "fmt" + "maps" + "path/filepath" + "slices" + "strings" + "sync" + + "github.com/gruntwork-io/terragrunt/pkg/log" + "github.com/sirupsen/logrus" + + "github.com/cloudposse/atmos/plugins/terragrunt/internal/model" +) + +const ( + // Bound on the events one call returns, so a chatty trace log cannot exceed the RPC size limit. + maxLogEntries = 500 + // Bound on the length of one message or field value. + maxLogMessage = 2048 + // Bound on the text of all events one call returns, well under the default 4 MiB RPC message limit. + maxLogBytes = 1 << 20 + // Field that Terragrunt uses for the directory of the unit an event is about. + unitField = "prefix" +) + +type logSinkKey struct{} + +// LogSink collects the events of the Terragrunt logger during one call, at or above a level. It is safe +// for concurrent use because Terragrunt may evaluate units in parallel. +type LogSink struct { + root string + entries []model.LogEntry + level log.Level + dropped int + size int + mu sync.Mutex + off bool +} + +// NewLogSink returns a sink for the events of a call at the host's log level. Terragrunt's logger reports +// engine chatter, such as how it located files, which is a diagnostic aid and not a message for the user: +// anything the user must act on reaches the host as a diagnostic or an error. So events are collected only +// when the host asks for debug or trace output, and the Atmos default of Warn collects nothing. At debug +// the sink keeps events at debug and above; at trace it keeps everything. The root argument makes the unit +// field project relative. +// +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func NewLogSink(level, root string) *LogSink { + sink := &LogSink{root: root, off: true} + switch strings.ToLower(level) { + case "debug": + sink.level, sink.off = log.DebugLevel, false + case "trace": + sink.level, sink.off = log.TraceLevel, false + } + return sink +} + +// TerragruntLevel returns the Terragrunt logger level that produces every event the sink keeps. +// +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func (s *LogSink) TerragruntLevel() string { + if s.off { + return log.ErrorLevel.String() + } + return s.level.String() +} + +// WithLogSink makes evaluations started with the returned context report their log events to sink. +// +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func WithLogSink(ctx context.Context, sink *LogSink) context.Context { + return context.WithValue(ctx, logSinkKey{}, sink) +} + +func logSinkFrom(ctx context.Context) *LogSink { + sink, _ := ctx.Value(logSinkKey{}).(*LogSink) + return sink +} + +// Entries returns the collected events in order. When events were dropped, the last entry says how many. +// +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func (s *LogSink) Entries() []model.LogEntry { + s.mu.Lock() + defer s.mu.Unlock() + entries := slices.Clone(s.entries) + if s.dropped > 0 { + entries = append(entries, model.LogEntry{Level: log.WarnLevel.String(), Message: fmt.Sprintf("%d further Terragrunt log events were omitted", s.dropped)}) + } + return entries +} + +// Adapts the sink to the Terragrunt logger. +func (s *LogSink) hook() logrus.Hook { return sinkHook{sink: s} } + +type sinkHook struct{ sink *LogSink } + +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func (sinkHook) Levels() []logrus.Level { + levels := make([]logrus.Level, 0, len(log.AllLevels)) + for _, level := range log.AllLevels { + levels = append(levels, level.ToLogrusLevel()) + } + return levels +} + +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func (h sinkHook) Fire(entry *logrus.Entry) error { + // Terragrunt shifts the numeric levels of Logrus, so entry.Level.String() would mislabel them. + level := log.FromLogrusLevel(entry.Level) + // Command output is not logging: the host streams it separately. + if level == log.StdoutLevel || level == log.StderrLevel { + return nil + } + h.sink.add(level, entry) + return nil +} + +func (s *LogSink) add(level log.Level, entry *logrus.Entry) { + if s.off || level > s.level { + return + } + s.mu.Lock() + defer s.mu.Unlock() + if len(s.entries) >= maxLogEntries || s.size >= maxLogBytes { + s.dropped++ + return + } + fields := make(map[string]string, len(entry.Data)) + unit := "" + for _, key := range slices.Sorted(maps.Keys(entry.Data)) { + value := truncate(fmt.Sprint(entry.Data[key])) + if key == unitField { + unit = s.relative(value) + continue + } + fields[key] = value + } + message := truncate(entry.Message) + s.size += len(message) + len(unit) + for key, value := range fields { + s.size += len(key) + len(value) + } + s.entries = append(s.entries, model.LogEntry{Time: entry.Time, Level: level.String(), Message: message, Fields: fields, Unit: unit}) +} + +// relative makes a unit directory project relative, leaving a path outside the project unchanged. +func (s *LogSink) relative(directory string) string { + if s.root == "" || !filepath.IsAbs(directory) { + return directory + } + if rel, err := filepath.Rel(s.root, directory); err == nil && filepath.IsLocal(rel) { + return filepath.ToSlash(rel) + } + return directory +} + +func truncate(text string) string { + if len(text) <= maxLogMessage { + return text + } + return text[:maxLogMessage] + "..." +} diff --git a/plugins/terragrunt/internal/engine/logs_test.go b/plugins/terragrunt/internal/engine/logs_test.go new file mode 100644 index 00000000000..0c03bedd4c0 --- /dev/null +++ b/plugins/terragrunt/internal/engine/logs_test.go @@ -0,0 +1,142 @@ +package engine + +import ( + "fmt" + "io" + "path/filepath" + "strings" + "sync" + "testing" + + "github.com/gruntwork-io/terragrunt/pkg/log" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// logger returns a Terragrunt logger that reports to the sink, at the level the sink asks for. +func logger(t *testing.T, sink *LogSink) log.Logger { + t.Helper() + l := log.New(log.WithOutput(io.Discard), log.WithHooks(sink.hook())) + require.NoError(t, l.SetLevel(sink.TerragruntLevel())) + return l +} + +func TestLogSinkKeepsEventsAtOrAboveTheLevel(t *testing.T) { + for _, test := range []struct { + level string + want []string + }{ + {"", nil}, + {"warn", nil}, + {"warning", nil}, + {"error", nil}, + {"info", nil}, + {"unknown", nil}, + {"off", nil}, + {"debug", []string{"debug", "info", "warn", "error"}}, + {"DEBUG", []string{"debug", "info", "warn", "error"}}, + {"trace", []string{"trace", "debug", "info", "warn", "error"}}, + } { + t.Run(test.level, func(t *testing.T) { + sink := NewLogSink(test.level, "") + l := logger(t, sink) + l.Trace("trace") + l.Debug("debug") + l.Info("info") + l.Warn("warn") + l.Error("error") + + var got []string + for _, entry := range sink.Entries() { + assert.Equal(t, entry.Level, entry.Message) + got = append(got, entry.Level) + } + assert.Equal(t, test.want, got) + }) + } +} + +func TestLogSinkReportsFieldsUnitAndTimeWithoutCommandOutput(t *testing.T) { + root := t.TempDir() + sink := NewLogSink("debug", root) + l := logger(t, sink) + + l.WithField("prefix", filepath.Join(root, "live", "dev", "app")).WithField("attempt", 3).WithField("failure", fmt.Errorf("boom")).Debug("evaluating") + l.WithField("prefix", "/elsewhere/unit").Warn("outside") + l.Logf(log.StdoutLevel, "command output") + l.Logf(log.StderrLevel, "command error") + + entries := sink.Entries() + require.Len(t, entries, 2, "command output is not logging") + assert.Equal(t, "live/dev/app", entries[0].Unit) + assert.Equal(t, map[string]string{"attempt": "3", "failure": "boom"}, entries[0].Fields) + assert.NotContains(t, entries[0].Fields, "prefix") + assert.False(t, entries[0].Time.IsZero()) + assert.Equal(t, "/elsewhere/unit", entries[1].Unit, "a unit outside the project keeps its path") +} + +func TestLogSinkBoundsVolumeAndSaysSo(t *testing.T) { + sink := NewLogSink("debug", "") + l := logger(t, sink) + for range maxLogEntries + 5 { + l.Debug("event") + } + + entries := sink.Entries() + + require.Len(t, entries, maxLogEntries+1) + last := entries[len(entries)-1] + assert.Equal(t, "warn", last.Level) + assert.Equal(t, "5 further Terragrunt log events were omitted", last.Message) + + long := NewLogSink("debug", "") + l = logger(t, long) + wide := strings.Repeat("y", maxLogMessage+10) + for range maxLogEntries { + l.WithField("a", wide).WithField("b", wide).Debug(strings.Repeat("x", maxLogMessage+10)) + } + entries = long.Entries() + assert.Len(t, entries[0].Message, maxLogMessage+len("..."), "one message is truncated") + assert.Len(t, entries[0].Fields["a"], maxLogMessage+len("..."), "one field value is truncated") + assert.Less(t, len(entries), maxLogEntries, "the byte budget stops collection before the entry limit") + assert.Contains(t, entries[len(entries)-1].Message, "further Terragrunt log events were omitted") +} + +func TestLogSinkIsSafeForConcurrentUnits(t *testing.T) { + sink := NewLogSink("debug", "") + l := logger(t, sink) + var wg sync.WaitGroup + for unit := range 8 { + wg.Go(func() { + for range 50 { + l.WithField("unit", unit).Info("working") + } + }) + } + wg.Wait() + assert.Len(t, sink.Entries(), 400) +} + +// The evaluator reports the Terragrunt logger's events through the sink in the context, and only there. +func TestResolveReportsLoggerEventsToTheContextSink(t *testing.T) { + request := nativeUnit(t, "inputs = { name = \"value\" }\n") + sink := NewLogSink("trace", request.BasePath) + + _, err := Resolve(WithLogSink(t.Context(), sink), request) + + require.NoError(t, err) + entries := sink.Entries() + require.NotEmpty(t, entries, "a trace-level evaluation logs") + for _, entry := range entries { + assert.NotEmpty(t, entry.Message) + assert.NotContains(t, entry.Message, "must-not-execute") + } + + quiet := NewLogSink("warn", request.BasePath) + _, err = Resolve(WithLogSink(t.Context(), quiet), request) + require.NoError(t, err) + assert.Empty(t, quiet.Entries(), "engine chatter is hidden at the Atmos default level") + + _, err = Resolve(t.Context(), request) + require.NoError(t, err, "evaluation without a sink still works") +} diff --git a/plugins/terragrunt/internal/engine/resolve.go b/plugins/terragrunt/internal/engine/resolve.go index 7b34d7a4105..358fab2959f 100644 --- a/plugins/terragrunt/internal/engine/resolve.go +++ b/plugins/terragrunt/internal/engine/resolve.go @@ -58,9 +58,15 @@ func resolveUnit(ctx context.Context, request model.Request, filesystem afero.Fs ctx = config.WithCaches(ctx) formatter := format.NewFormatter(format.NewKeyValueFormatPlaceholders()) formatter.SetDisabledColors(true) - logger := log.New(log.WithOutput(io.Discard), log.WithFormatter(formatter)) - if request.LogLevel != "" { - if err := logger.SetLevel(request.LogLevel); err != nil { + loggerOptions := []log.Option{log.WithOutput(io.Discard), log.WithFormatter(formatter)} + level := request.LogLevel + // Terragrunt's own log events go to the host as structured entries, never to a stream. + if sink := logSinkFrom(ctx); sink != nil { + loggerOptions, level = append(loggerOptions, log.WithHooks(sink.hook())), sink.TerragruntLevel() + } + logger := log.New(loggerOptions...) + if level != "" { + if err := logger.SetLevel(level); err != nil { return nil, err } } @@ -77,6 +83,10 @@ func resolveUnit(ctx context.Context, request model.Request, filesystem afero.Fs discover := request.Phase == "discover" || request.Command == "discover" if discover || request.Phase == "backend" || request.Command == "generate" { environment = atmosbridge.Discovery(environment, request.Command == "generate") + } else { + // Evaluation may call AWS (get_aws_account_id, S3 dependency state). Those calls must use the + // identity of the invocation, not whatever the plugin process happens to hold. + environment = atmosbridge.AWS(ctx, environment) } command := request.Command if command == "" || command == "discover" || command == "generate" { @@ -259,6 +269,7 @@ func resolveUnit(ctx context.Context, request model.Request, filesystem afero.Fs } result := &model.Resolution{Execution: execution, Path: path, Inputs: cfg.Inputs, Source: *cfg.Terraform.Source, Generated: map[string]string{}, Files: append(pctx.FilesRead.Paths(), path)} if request.Phase != "backend" { + result.SensitiveInputs = SensitiveInputs(environment.FS, result.Files, cfg.Inputs) if err := applyUnitSettings(ctx, cfg, request, path, result); err != nil { return nil, err } diff --git a/plugins/terragrunt/internal/engine/resolve_test.go b/plugins/terragrunt/internal/engine/resolve_test.go index 03cdb7a2a3c..2d0cb15b485 100644 --- a/plugins/terragrunt/internal/engine/resolve_test.go +++ b/plugins/terragrunt/internal/engine/resolve_test.go @@ -2,10 +2,15 @@ package engine import ( "encoding/json" + "fmt" + "net/http" + "net/http/httptest" "os" "path/filepath" + "sync/atomic" "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/require" "github.com/cloudposse/atmos/plugins/terragrunt/internal/model" @@ -151,3 +156,129 @@ generate "disabled" { require.Error(t, err) } } + +// A unit that calls get_aws_account_id() sees the identity of the invocation, selected only through the +// invocation environment: the plugin process never holds the profile or the endpoint. +func TestNativeAWSFunctionsUseInvocationIdentity(t *testing.T) { + var signer atomic.Value + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + signer.Store(r.Header.Get("Authorization")) + w.Header().Set("Content-Type", "text/xml") + fmt.Fprint(w, `arn:aws:iam::210987654321:user/atmosAIDAATMOS210987654321`) + })) + t.Cleanup(server.Close) + dir := t.TempDir() + credentials, configFile := filepath.Join(dir, "credentials"), filepath.Join(dir, "config") + require.NoError(t, os.WriteFile(credentials, []byte("[atmos-identity]\naws_access_key_id = AKIAENGINE\naws_secret_access_key = secret\n"), 0o600)) + require.NoError(t, os.WriteFile(configFile, nil, 0o600)) + request := nativeUnit(t, "inputs = { account = get_aws_account_id(), arn = get_aws_caller_identity_arn(), user = get_aws_caller_identity_user_id() }\n") + request.Environment = map[string]string{ + "AWS_PROFILE": "atmos-identity", "AWS_SHARED_CREDENTIALS_FILE": credentials, "AWS_CONFIG_FILE": configFile, + "AWS_ENDPOINT_URL_STS": server.URL, "AWS_REGION": "us-east-1", "AWS_EC2_METADATA_DISABLED": "true", + } + + result, err := Resolve(t.Context(), request) + + require.NoError(t, err) + require.Equal(t, "210987654321", result.Inputs["account"]) + require.Equal(t, "arn:aws:iam::210987654321:user/atmos", result.Inputs["arn"]) + require.Equal(t, "AIDAATMOS", result.Inputs["user"]) + require.Contains(t, signer.Load(), "Credential=AKIAENGINE/") + require.Empty(t, os.Getenv("AWS_PROFILE")) +} + +// Read-only discovery stays offline even when the invocation names credentials and an endpoint. +func TestDiscoveryNeverCallsAWS(t *testing.T) { + var calls atomic.Int32 + server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { calls.Add(1) })) + t.Cleanup(server.Close) + request := nativeUnit(t, "inputs = { account = get_aws_account_id() }\n") + request.Phase = "discover" + request.Environment = map[string]string{"AWS_ACCESS_KEY_ID": "AKIAX", "AWS_SECRET_ACCESS_KEY": "x", "AWS_ENDPOINT_URL_STS": server.URL} + + // Discovery may succeed or fail on the function, depending on how much of the unit it evaluates. + // Either way it must not reach the endpoint. + _, _ = Resolve(t.Context(), request) + + require.Zero(t, calls.Load()) +} + +// Terragrunt discards the marks of the evaluated inputs, so the unit's own HCL decides which are sensitive. +func TestResolveReportsSensitiveInputs(t *testing.T) { + request := nativeUnit(t, `locals { + database = sensitive({ password = "pw", host = "db" }) + token = sensitive("t0ken") +} +inputs = { + direct = sensitive("direct-secret") + password = local.database.password + token = local.token + host = local.database.host + plain = "visible" + nested = { key = sensitive("nested-secret"), open = 1 } + merged = merge({ a = sensitive("m") }, { b = 2 }) + chosen = true ? sensitive("c") : "d" + wrapped = "${sensitive("w")}" + large = 9007199254740993 +} +`) + + result, err := Resolve(t.Context(), request) + + require.NoError(t, err) + // A sensitive object makes every key of it sensitive, so host is sensitive as well. + require.Equal(t, [][]string{{"chosen"}, {"direct"}, {"host"}, {"merged", "a"}, {"nested", "key"}, {"password"}, {"token"}, {"wrapped"}}, result.SensitiveInputs) + require.Equal(t, json.Number("9007199254740993"), result.Inputs["large"]) + require.Equal(t, "visible", result.Inputs["plain"]) +} + +func TestSensitiveInputsFollowIncludesAndSkipWhatItCannotSee(t *testing.T) { + fsys := afero.NewMemMapFs() + write := func(path, content string) { require.NoError(t, afero.WriteFile(fsys, path, []byte(content), 0o644)) } + write("/root.hcl", `inputs = { shared = sensitive("s"), open = "o" }`) + write("/unit/terragrunt.hcl", `locals { cycle = local.cycle } +inputs = { + own = sensitive(1) + looped = local.cycle + missing = local.absent + indexed = local.cycle["k"] + dynamic = { for k, v in { a = 1 } : k => sensitive(v) } +}`) + write("/broken.hcl", `inputs = {`) + write("/data.json", `{"inputs": {"json": "x"}}`) + write("/whole.hcl", `inputs = sensitive({ everything = 1 })`) + inputs := map[string]any{"shared": "s", "open": "o", "own": json.Number("1"), "looped": "x", "dynamic": map[string]any{"a": json.Number("1")}, "json": "x", "everything": json.Number("1")} + + files := []string{"/unit/terragrunt.hcl", "/root.hcl", "/broken.hcl", "/data.json", "/missing.hcl"} + require.Equal(t, [][]string{{"own"}, {"shared"}}, SensitiveInputs(fsys, files, inputs)) + + require.Equal(t, [][]string{nil}, SensitiveInputs(fsys, []string{"/whole.hcl"}, inputs), "sensitive(...) around the whole inputs marks every input") + require.Empty(t, SensitiveInputs(fsys, files, map[string]any{"open": "o"}), "a path that is not among the evaluated inputs is dropped") + require.Empty(t, SensitiveInputs(fsys, nil, inputs)) +} + +func TestSensitiveInputsFollowNestedLocalReferences(t *testing.T) { + fsys := afero.NewMemMapFs() + require.NoError(t, afero.WriteFile(fsys, "/unit.hcl", []byte(`locals { + config = { token = sensitive("t"), open = "o", deeper = { key = sensitive("k") } } + whole = sensitive({ key = "v" }) + paren = (sensitive({ inner = 1 })) +} +inputs = { + token = local.config.token + open = local.config.open + key = local.config.deeper.key + wholekey = local.whole.key + inner = local.paren.inner + indexed = local.config["token"] + missing = local.config.nothing.deeper + scalar = local.config.open.length + external = var.other + call = tostring(sensitive("c")) + cond = true ? local.config.token : "x" +} +`), 0o644)) + inputs := map[string]any{"token": "t", "open": "o", "key": "k", "wholekey": "v", "inner": 1, "indexed": "t", "missing": 1, "scalar": 1, "external": 1, "call": "c", "cond": "t"} + + require.Equal(t, [][]string{{"cond"}, {"inner"}, {"key"}, {"token"}, {"wholekey"}}, SensitiveInputs(fsys, []string{"/unit.hcl"}, inputs)) +} diff --git a/plugins/terragrunt/internal/engine/sensitivity.go b/plugins/terragrunt/internal/engine/sensitivity.go new file mode 100644 index 00000000000..7b31fae91a5 --- /dev/null +++ b/plugins/terragrunt/internal/engine/sensitivity.go @@ -0,0 +1,207 @@ +package engine + +import ( + "path/filepath" + "slices" + "strings" + + "github.com/hashicorp/hcl/v2" + "github.com/hashicorp/hcl/v2/hclsyntax" + "github.com/spf13/afero" + "github.com/zclconf/go-cty/cty" +) + +const ( + // Bound on how many local.* references the scan follows, which also stops cycles. + maxLocalDepth = 8 + inputsName = "inputs" + localName = "local" +) + +// SensitiveInputs returns the paths of the unit's inputs that the unit declares sensitive. A path is a list +// of object keys from the top of the inputs; an empty path means every input. +// +// Terragrunt converts the evaluated inputs to plain values and drops their marks, so the evaluated result +// cannot tell which inputs were sensitive. The unit's own HCL does: this reads the `inputs` attribute of the +// unit and of every file it includes, and marks the paths whose value is written as sensitive(...), including +// through object literals, merge(...), conditionals, and local.* references. Values that become sensitive in +// other ways, such as the output of a function applied to a sensitive local, are not tracked. Only paths that +// exist in the evaluated inputs are returned. +// +//nolint:lintroller // Plugin evaluator code cannot import the host performance tracker. +func SensitiveInputs(fsys afero.Fs, files []string, inputs map[string]any) [][]string { + var found [][]string + for _, file := range files { + if filepath.Ext(file) != ".hcl" { + continue + } + content, err := afero.ReadFile(fsys, file) + if err != nil { + continue + } + parsed, diags := hclsyntax.ParseConfig(content, file, hcl.InitialPos) + if diags.HasErrors() { + continue + } + body, ok := parsed.Body.(*hclsyntax.Body) + if !ok { + continue + } + found = append(found, scanFile(body)...) + } + return existingPaths(uniquePaths(found), inputs) +} + +// scanFile finds the sensitive paths declared by one file's inputs attribute. +func scanFile(body *hclsyntax.Body) [][]string { + attribute := body.Attributes[inputsName] + if attribute == nil { + return nil + } + scanner := &sensitivityScanner{locals: localExpressions(body)} + scanner.walk(attribute.Expr, nil, 0) + return scanner.paths +} + +// localExpressions indexes the attributes of the file's locals blocks by name. +func localExpressions(body *hclsyntax.Body) map[string]hclsyntax.Expression { + locals := map[string]hclsyntax.Expression{} + for _, block := range body.Blocks { + if block.Type != "locals" { + continue + } + for name, attribute := range block.Body.Attributes { + locals[name] = attribute.Expr + } + } + return locals +} + +type sensitivityScanner struct { + locals map[string]hclsyntax.Expression + paths [][]string +} + +// walk records the paths below prefix that expression marks sensitive. +func (s *sensitivityScanner) walk(expression hclsyntax.Expression, prefix []string, depth int) { + switch node := expression.(type) { + case *hclsyntax.ParenthesesExpr: + s.walk(node.Expression, prefix, depth) + case *hclsyntax.TemplateWrapExpr: + s.walk(node.Wrapped, prefix, depth) + case *hclsyntax.FunctionCallExpr: + s.walkCall(node, prefix, depth) + case *hclsyntax.ObjectConsExpr: + s.walkObject(node, prefix, depth) + case *hclsyntax.ConditionalExpr: + s.walk(node.TrueResult, prefix, depth) + s.walk(node.FalseResult, prefix, depth) + case *hclsyntax.ScopeTraversalExpr: + s.walkLocal(node, prefix, depth) + } +} + +// walkObject records the sensitive paths below each key of an object literal. +func (s *sensitivityScanner) walkObject(object *hclsyntax.ObjectConsExpr, prefix []string, depth int) { + for _, item := range object.Items { + if key, ok := staticKey(item.KeyExpr); ok { + s.walk(item.ValueExpr, append(slices.Clone(prefix), key), depth) + } + } +} + +// staticKey returns the key of an object literal item when it is a known string. +func staticKey(expression hclsyntax.Expression) (string, bool) { + key, diags := expression.Value(nil) + if diags.HasErrors() || !key.IsKnown() || key.IsNull() || !key.Type().Equals(cty.String) { + return "", false + } + return key.AsString(), true +} + +func (s *sensitivityScanner) walkCall(call *hclsyntax.FunctionCallExpr, prefix []string, depth int) { + switch call.Name { + case "sensitive": + s.paths = append(s.paths, slices.Clone(prefix)) + case "merge": + for _, argument := range call.Args { + s.walk(argument, prefix, depth) + } + } +} + +// walkLocal follows local.name and local.name.key.key to the expression that defines it. +func (s *sensitivityScanner) walkLocal(traversal *hclsyntax.ScopeTraversalExpr, prefix []string, depth int) { + if depth >= maxLocalDepth || traversal.Traversal.RootName() != localName || len(traversal.Traversal) < 2 { + return + } + first, ok := traversal.Traversal[1].(hcl.TraverseAttr) + if !ok { + return + } + current, found := s.locals[first.Name] + if !found { + return + } + for _, step := range traversal.Traversal[2:] { + attribute, ok := step.(hcl.TraverseAttr) + if !ok { + return + } + var sensitive bool + if current, sensitive = descend(current, attribute.Name); sensitive { + s.paths = append(s.paths, slices.Clone(prefix)) + return + } + if current == nil { + return + } + } + s.walk(current, prefix, depth+1) +} + +// Descend returns the expression of one key of an object literal. A sensitive wrapper call makes every key +// sensitive, which it reports instead of an expression. +func descend(expression hclsyntax.Expression, key string) (child hclsyntax.Expression, sensitive bool) { + switch node := expression.(type) { + case *hclsyntax.ParenthesesExpr: + return descend(node.Expression, key) + case *hclsyntax.FunctionCallExpr: + return nil, node.Name == "sensitive" + case *hclsyntax.ObjectConsExpr: + for _, item := range node.Items { + if name, ok := staticKey(item.KeyExpr); ok && name == key { + return item.ValueExpr, false + } + } + } + return nil, false +} + +func uniquePaths(paths [][]string) [][]string { + slices.SortFunc(paths, func(a, b []string) int { return strings.Compare(strings.Join(a, "\x00"), strings.Join(b, "\x00")) }) + return slices.CompactFunc(paths, slices.Equal[[]string]) +} + +// existingPaths keeps the paths that lead to a value in inputs. The empty path always exists. +func existingPaths(paths [][]string, inputs map[string]any) [][]string { + var kept [][]string + for _, path := range paths { + if pathExists(any(inputs), path) { + kept = append(kept, path) + } + } + return kept +} + +func pathExists(value any, path []string) bool { + if len(path) == 0 { + return true + } + object, ok := value.(map[string]any) + if !ok { + return false + } + child, found := object[path[0]] + return found && pathExists(child, path[1:]) +} diff --git a/plugins/terragrunt/internal/model/model.go b/plugins/terragrunt/internal/model/model.go index 76a00c4fe90..6fef64c4ace 100644 --- a/plugins/terragrunt/internal/model/model.go +++ b/plugins/terragrunt/internal/model/model.go @@ -1,6 +1,8 @@ // Package model contains evaluator data, independent of the plugin transport. package model +import "time" + type Request struct { IncludedPaths []string `json:"included_paths,omitempty"` ExcludedPaths []string `json:"excluded_paths,omitempty"` @@ -34,14 +36,16 @@ type Resolution struct { UnitConfigs map[string]string `json:"unit_configs,omitempty"` StackConfigs map[string]string `json:"stack_configs,omitempty"` Inputs map[string]any `json:"inputs"` - Source string `json:"source"` - BackendGenerated bool `json:"backend_generated,omitempty"` - BackendType string `json:"backend_type"` - Backend map[string]any `json:"backend"` - Generated map[string]string `json:"generated"` - GeneratedPolicies map[string]string `json:"generated_policies,omitempty"` - Units map[string]string `json:"units,omitempty"` - Stacks map[string]string `json:"stacks,omitempty"` + // SensitiveInputs are the paths (object keys from the top) of the inputs the unit declares sensitive. + SensitiveInputs [][]string `json:"sensitive_inputs,omitempty"` + Source string `json:"source"` + BackendGenerated bool `json:"backend_generated,omitempty"` + BackendType string `json:"backend_type"` + Backend map[string]any `json:"backend"` + Generated map[string]string `json:"generated"` + GeneratedPolicies map[string]string `json:"generated_policies,omitempty"` + Units map[string]string `json:"units,omitempty"` + Stacks map[string]string `json:"stacks,omitempty"` // Failures are units that could not be evaluated. A failing unit never hides healthy ones. Failures []UnitFailure `json:"failures,omitempty"` // Warnings are non-fatal facts about the scan that the user should see. @@ -171,3 +175,14 @@ type Hook struct { SuppressStdout bool `json:"suppress_stdout,omitempty"` OnErrors []string `json:"on_errors,omitempty"` } + +// LogEntry is one event of the Terragrunt logger, kept for the host to render. The message and fields +// never carry evaluated values by design; the host masks them as well. +type LogEntry struct { + Time time.Time + Fields map[string]string + Level string + Message string + // Unit is the unit the event is about, relative to the project root, when the logger reports one. + Unit string +} diff --git a/plugins/terragrunt/internal/provider/discovery.go b/plugins/terragrunt/internal/provider/discovery.go index 9383f03f34a..8ab4f4d8621 100644 --- a/plugins/terragrunt/internal/provider/discovery.go +++ b/plugins/terragrunt/internal/provider/discovery.go @@ -13,21 +13,40 @@ import ( // Discover expands local stacks in an isolated overlay without preparing units. func (p *Provider) Discover(ctx context.Context, request *pluginv1.DiscoverComponentsRequest) (*pluginv1.DiscoverComponentsResponse, error) { + ctx, sink := withLogs(ctx, request.GetInvocation(), request.GetRootDirectory()) + response, err := p.discover(ctx, request) + if response != nil { + response.Logs = logEntries(sink) + } + return response, withFailureLogs(err, sink) +} + +// discoveryRequest validates a discovery request and turns it into an inventory evaluation. +func discoveryRequest(request *pluginv1.DiscoverComponentsRequest) (model.Request, error) { req, err := operation(request.GetRootDirectory(), request.GetProvider(), request.GetOperation(), request.GetInvocation()) if err != nil { - return nil, rpcError(err) + return req, rpcError(err) } if err := settings(request.GetProviderConfiguration()); err != nil { - return nil, rpcError(err) + return req, rpcError(err) } if err := withFeatures(&req, request.GetProviderConfiguration()); err != nil { - return nil, rpcError(err) + return req, rpcError(err) } paths, err := importPaths(request) if err != nil { - return nil, rpcError(err) + return req, rpcError(err) } req.Phase, req.IncludedPaths, req.ExcludedPaths = "inventory", paths, request.ExcludePaths + return req, nil +} + +func (p *Provider) discover(ctx context.Context, request *pluginv1.DiscoverComponentsRequest) (*pluginv1.DiscoverComponentsResponse, error) { + req, err := discoveryRequest(request) + if err != nil { + return nil, err + } + executable := request.GetOperation().GetMode() == ModeExecutable result, err := p.evaluate(ctx, req) if err != nil { return nil, rpcError(err) @@ -42,6 +61,10 @@ func (p *Provider) Discover(ctx context.Context, request *pluginv1.DiscoverCompo } for _, unit := range result.Inventory { discovered, err := discoveredUnit(req, unit, addresses) + if err == nil && executable { + // The host lists the unit with the engine that runs it. + discovered.Engine = "terragrunt" + } if err != nil { // One unit that cannot be described must not hide the others. response.Diagnostics = append(response.Diagnostics, unitDiagnostic(req.BasePath, model.UnitFailure{Stack: unit.Stack, Name: unit.Name, Err: problemFor(err, unit.Config.Path)})) diff --git a/plugins/terragrunt/internal/provider/logs.go b/plugins/terragrunt/internal/provider/logs.go new file mode 100644 index 00000000000..97b1c77c29f --- /dev/null +++ b/plugins/terragrunt/internal/provider/logs.go @@ -0,0 +1,66 @@ +package provider + +import ( + "context" + "errors" + "strings" + + "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/cloudposse/atmos/plugins/terragrunt/internal/engine" + pluginv1 "github.com/cloudposse/atmos/sdk/proto/atmos/plugin/v1" +) + +// withLogs makes the evaluation of one call report the Terragrunt logger's events at the level the host asked +// for. The events return in the response, or in the failure when the call fails, so the host can show them +// through the Atmos logger. Nothing is written to a stream and no event changes the outcome of the call. +func withLogs(ctx context.Context, invocation *pluginv1.Invocation, root string) (context.Context, *engine.LogSink) { + sink := engine.NewLogSink(invocation.GetLogLevel(), root) + return engine.WithLogSink(ctx, sink), sink +} + +// logEntries converts the collected events to their wire form. +func logEntries(sink *engine.LogSink) []*pluginv1.LogEntry { + collected := sink.Entries() + if len(collected) == 0 { + return nil + } + entries := make([]*pluginv1.LogEntry, 0, len(collected)) + for i := range collected { + entry := &collected[i] + converted := &pluginv1.LogEntry{Level: logLevel(entry.Level), Message: entry.Message, Fields: entry.Fields, Unit: entry.Unit} + if !entry.Time.IsZero() { + converted.Time = timestamppb.New(entry.Time) + } + entries = append(entries, converted) + } + return entries +} + +func logLevel(level string) pluginv1.LogLevel { + switch strings.ToLower(level) { + case "trace": + return pluginv1.LogLevel_LOG_LEVEL_TRACE + case "debug": + return pluginv1.LogLevel_LOG_LEVEL_DEBUG + case "info": + return pluginv1.LogLevel_LOG_LEVEL_INFO + case "warn": + return pluginv1.LogLevel_LOG_LEVEL_WARN + case "error": + return pluginv1.LogLevel_LOG_LEVEL_ERROR + } + return pluginv1.LogLevel_LOG_LEVEL_UNSPECIFIED +} + +// withFailureLogs attaches the events collected before a failure to the failure the host renders. +func withFailureLogs(err error, sink *engine.LogSink) error { + var failure *rpcFailure + if !errors.As(err, &failure) { + return err + } + if entries := logEntries(sink); len(entries) > 0 { + failure.failure.Logs(entries) + } + return err +} diff --git a/plugins/terragrunt/internal/provider/preparation.go b/plugins/terragrunt/internal/provider/preparation.go index 93fbf8cf405..23a4263373c 100644 --- a/plugins/terragrunt/internal/provider/preparation.go +++ b/plugins/terragrunt/internal/provider/preparation.go @@ -56,11 +56,23 @@ func (p *Provider) componentRequest(ctx context.Context, request *pluginv1.Compo // Prepare resolves current inputs after dependencies and returns literal files. // Terraform execution remains owned by Atmos. func (p *Provider) Prepare(ctx context.Context, request *pluginv1.ComponentRequest) (*pluginv1.PrepareComponentResponse, error) { + ctx, sink := withLogs(ctx, request.GetInvocation(), request.GetRootDirectory()) response, err := p.prepare(ctx, request) - return response, scoped(err, "prepare", request.GetRootDirectory(), request.GetAddress()) + err = scoped(err, "prepare", request.GetRootDirectory(), request.GetAddress()) + if response != nil { + response.Logs = logEntries(sink) + } + return response, withFailureLogs(err, sink) } func (p *Provider) prepare(ctx context.Context, request *pluginv1.ComponentRequest) (*pluginv1.PrepareComponentResponse, error) { + // Executable mode runs units with the terragrunt executable; native preparation must never mix in. + if request.GetOperation().GetMode() == ModeExecutable { + return nil, rpcError(&model.Problem{ + Code: model.CodeUnsupportedSetting, Summary: "Units in executable mode are not prepared natively", Safe: true, Err: ErrUnsupported, + Hints: []string{"Executable mode runs each unit with the terragrunt executable. Set `components.terraform.terragrunt.mode` to `native` to adapt units to Atmos instead."}, + }) + } req, err := p.componentRequest(ctx, request) if err != nil { return nil, rpcError(err) @@ -84,7 +96,7 @@ func (p *Provider) prepare(ctx context.Context, request *pluginv1.ComponentReque if values == nil { values = map[string]any{} } - inputs, err := encode(values) + inputs, err := encodeSensitive(values, result.SensitiveInputs) if err != nil { return nil, rpcError(err) } @@ -136,8 +148,13 @@ func stateIdentity(req model.Request, result *model.Resolution) (*pluginv1.Compo // Resolve reads backend identity in an overlay, independently of dependency outputs. func (p *Provider) Resolve(ctx context.Context, request *pluginv1.ComponentRequest) (*pluginv1.ResolveComponentStateResponse, error) { + ctx, sink := withLogs(ctx, request.GetInvocation(), request.GetRootDirectory()) response, err := p.resolveState(ctx, request) - return response, scoped(err, "resolve state", request.GetRootDirectory(), request.GetAddress()) + err = scoped(err, "resolve state", request.GetRootDirectory(), request.GetAddress()) + if response != nil { + response.Logs = logEntries(sink) + } + return response, withFailureLogs(err, sink) } func (p *Provider) resolveState(ctx context.Context, request *pluginv1.ComponentRequest) (*pluginv1.ResolveComponentStateResponse, error) { @@ -272,6 +289,13 @@ func withFeatures(req *model.Request, configuration *pluginv1.ComponentValue) er } maps.Copy(features, fromEnvironment) } + // Options of the command line rank above the environment and the configuration, per name. + if len(req.Features) > 0 { + if features == nil { + features = map[string]string{} + } + maps.Copy(features, req.Features) + } req.Features = features return nil } diff --git a/plugins/terragrunt/internal/provider/provider.go b/plugins/terragrunt/internal/provider/provider.go index 24d1d6ddf98..d7aead60b70 100644 --- a/plugins/terragrunt/internal/provider/provider.go +++ b/plugins/terragrunt/internal/provider/provider.go @@ -11,6 +11,7 @@ import ( "slices" "strings" + "github.com/zclconf/go-cty/cty" ctyjson "github.com/zclconf/go-cty/cty/json" "github.com/cloudposse/atmos/plugins/terragrunt/internal/engine" @@ -42,6 +43,13 @@ func New(evaluate Evaluator) *Provider { } func encode(value any) (*pluginv1.ComponentValue, error) { + return encodeSensitive(value, nil) +} + +// encodeSensitive encodes value with the given paths marked sensitive. A path is a list of object keys; the +// empty path marks the whole value. Numbers keep their exact decimal digits because the JSON form is +// read with cty's arbitrary-precision numbers, and null stays null. +func encodeSensitive(value any, sensitive [][]string) (*pluginv1.ComponentValue, error) { data, err := json.Marshal(value) if err != nil { return nil, component.ErrInvalidValue @@ -54,7 +62,30 @@ func encode(value any) (*pluginv1.ComponentValue, error) { if err != nil { return nil, component.ErrInvalidValue } - return component.Encode(v) + return component.Encode(markSensitive(v, sensitive)) +} + +// markSensitive marks the values at the given object-key paths sensitive. A path that does not lead to a +// value is skipped: the scan that produced it may be conservative. +func markSensitive(value cty.Value, paths [][]string) cty.Value { + var marks []cty.PathValueMarks + for _, steps := range paths { + if len(steps) == 0 { + return value.Mark(component.Sensitive) + } + path := cty.Path{} + for _, step := range steps { + path = path.GetAttr(step) + } + if _, err := path.Apply(value); err != nil { + continue + } + marks = append(marks, cty.PathValueMarks{Path: path, Marks: cty.NewValueMarks(component.Sensitive)}) + } + if len(marks) == 0 { + return value + } + return value.MarkWithPaths(marks) } func decode(encoded *pluginv1.ComponentValue, target any) error { @@ -87,25 +118,80 @@ func settings(value *pluginv1.ComponentValue) error { return settingProblem(key, fmt.Sprintf("Unknown setting `components.terraform.terragrunt.%s`", key), "Valid keys are `enabled`, `provider`, `mode`, `discovery`, and `features`. Check the spelling.") } } - if mode, _ := config["mode"].(string); mode != "" && mode != "native" { - return settingProblem("mode", "Unsupported value for `components.terraform.terragrunt.mode`", "The only supported mode is `native`. Remove `mode` or set `mode: native`.") + if mode, _ := config["mode"].(string); mode != "" && mode != ModeNative && mode != ModeExecutable { + return settingProblem("mode", "Unsupported value for `components.terraform.terragrunt.mode`", "The supported modes are `native` and `executable`. Remove `mode` or set one of them.") } return nil } +// Modes a section can run in. Native adapts units to Atmos; executable runs them with the terragrunt +// executable, so the plugin only describes units and never prepares them. +const ( + ModeNative = "native" + ModeExecutable = "executable" +) + +// toolEnvironment maps the options that Terragrunt reads from the environment to their variables. +// An option replaces the variable, so it ranks above the environment and the unit, which is the +// order of Terragrunt's own flags. +var toolEnvironment = map[string]string{ + "iam_assume_role": "TG_IAM_ASSUME_ROLE", + "iam_assume_role_duration": "TG_IAM_ASSUME_ROLE_DURATION", + "iam_assume_role_session_name": "TG_IAM_ASSUME_ROLE_SESSION_NAME", + "iam_assume_role_web_identity_token": "TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN", + "download_dir": "TG_DOWNLOAD_DIR", +} + +// applyOptions validates the typed provider options of the operation, overrides the environment they +// replace, and returns the feature overrides. An unknown option is rejected rather than ignored, so a +// host and a plugin that disagree about the declared options fail loudly. +func applyOptions(env map[string]string, options map[string]*pluginv1.ComponentValue) (map[string]string, error) { + var features map[string]string + for _, name := range slices.Sorted(maps.Keys(options)) { + if name == "feature" { + if err := decode(options[name], &features); err != nil { + return nil, optionProblem(name, "Use name=value pairs such as `--terragrunt-feature alpha=true`.") + } + continue + } + variable, known := toolEnvironment[name] + if !known { + return nil, optionProblem(name, "Check the option name against the package's declared options.") + } + var value any + if err := decode(options[name], &value); err != nil { + return nil, optionProblem(name, "The value has an unexpected type.") + } + text := fmt.Sprint(value) + if number, isNumber := value.(json.Number); isNumber { + text = number.String() + } + env[variable] = text + } + return features, nil +} + +func optionProblem(name, hint string) *model.Problem { + return &model.Problem{Code: model.CodeUnsupportedSetting, Summary: fmt.Sprintf("Invalid provider option `%s`", name), Hints: []string{hint}, Key: "options." + name, Safe: true, Err: ErrUnsupported} +} + func operation(root, name string, op *pluginv1.ComponentOperation, invocation *pluginv1.Invocation) (model.Request, error) { - if name != "terragrunt" || !filepath.IsAbs(root) || op == nil || op.Mode != "native" || len(op.Options) != 0 { + if name != "terragrunt" || !filepath.IsAbs(root) || op == nil || (op.Mode != ModeNative && op.Mode != ModeExecutable) { return model.Request{}, ErrUnsupported } env := maps.Clone(invocation.GetEnvironment()) if env == nil { env = map[string]string{} } + features, err := applyOptions(env, op.Options) + if err != nil { + return model.Request{}, err + } binary := env["ATMOS_TERRAFORM_BINARY"] if binary == "" { binary = "terraform" } - return model.Request{BasePath: root, Mode: "native", Command: op.Command, Arguments: slices.Clone(op.TerraformArguments), Tofu: binary, Environment: env}, nil + return model.Request{BasePath: root, Mode: ModeNative, Command: op.Command, Arguments: slices.Clone(op.TerraformArguments), Tofu: binary, Environment: env, Features: features}, nil } func engineName(binary string) string { diff --git a/plugins/terragrunt/internal/provider/provider_test.go b/plugins/terragrunt/internal/provider/provider_test.go index e295bbf2623..4311a0388b4 100644 --- a/plugins/terragrunt/internal/provider/provider_test.go +++ b/plugins/terragrunt/internal/provider/provider_test.go @@ -2,13 +2,18 @@ package provider import ( "context" + "encoding/json" "errors" + "fmt" + "os" "path/filepath" "testing" "github.com/stretchr/testify/require" + "github.com/zclconf/go-cty/cty" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "gopkg.in/yaml.v3" "github.com/cloudposse/atmos/plugins/terragrunt/internal/engine" "github.com/cloudposse/atmos/plugins/terragrunt/internal/model" @@ -333,3 +338,247 @@ func TestDiscoveryPublishesCommandAndExclude(t *testing.T) { require.Equal(t, "terraform", unitEngine(model.Request{Tofu: "terraform"}, &model.Resolution{})) require.Equal(t, "opentofu", unitEngine(model.Request{Tofu: "tofu"}, nil)) } + +func TestPrepareReturnsExactInputsWithSensitivePaths(t *testing.T) { + request := componentRequest(t) + p := New(func(context.Context, model.Request) (*model.Resolution, error) { + return &model.Resolution{ + Source: filepath.Join(request.RootDirectory, "module"), WorkingDir: filepath.Join(request.RootDirectory, "cache"), BackendType: "local", + Inputs: map[string]any{ + "large": json.Number("9007199254740993"), "ratio": json.Number("0.1"), "list": []any{"a", json.Number("2"), nil}, "nothing": nil, + "password": "hunter2", "nested": map[string]any{"token": "t", "open": true}, "empty": map[string]any{}, + }, + SensitiveInputs: [][]string{{"password"}, {"nested", "token"}, {"missing"}}, + }, nil + }) + + result, err := p.Prepare(t.Context(), request) + + require.NoError(t, err) + value, err := component.Decode(result.Inputs) + require.NoError(t, err) + plain, marks := value.UnmarkDeepWithPaths() + paths := []string{} + for _, mark := range marks { + paths = append(paths, fmt.Sprintf("%#v", mark.Path)) + } + require.ElementsMatch(t, []string{ + fmt.Sprintf("%#v", cty.GetAttrPath("password")), + fmt.Sprintf("%#v", cty.GetAttrPath("nested").GetAttr("token")), + }, paths, "only paths that exist are marked") + require.Equal(t, "9007199254740993", plain.GetAttr("large").AsBigFloat().Text('f', -1)) + require.Equal(t, "0.1", plain.GetAttr("ratio").AsBigFloat().Text('f', -1)) + require.True(t, plain.GetAttr("nothing").IsNull()) + require.True(t, plain.GetAttr("list").Type().IsTupleType()) + require.True(t, plain.GetAttr("list").Index(cty.NumberIntVal(2)).IsNull()) + require.True(t, plain.GetAttr("empty").Type().IsObjectType()) + require.True(t, plain.IsWhollyKnown()) + + whole, err := encodeSensitive(map[string]any{"a": "b"}, [][]string{nil}) + require.NoError(t, err) + require.Len(t, whole.SensitivePaths, 1) + require.Empty(t, whole.SensitivePaths[0].Steps, "the empty path marks the whole value") +} + +func TestPrepareReturnsEngineLogsOnlyAtTheInvocationLevel(t *testing.T) { + root := fixture(t, "explicit-stack") + opts, err := encode(map[string]any{"enabled": true, "mode": "native", "discovery": map[string]any{"enabled": true, "included_paths": []string{"live/**"}}}) + require.NoError(t, err) + provider := New(nil) + discover := func(level string) *pluginv1.DiscoverComponentsResponse { + response, err := provider.Discover(t.Context(), &pluginv1.DiscoverComponentsRequest{RootDirectory: root, Provider: "terragrunt", ProviderConfiguration: opts, IncludePaths: []string{"live/**"}, Operation: &pluginv1.ComponentOperation{Mode: "native", Command: "plan"}, Invocation: &pluginv1.Invocation{LogLevel: level, Environment: map[string]string{"ATMOS_TERRAFORM_BINARY": "must-not-execute"}}}) + require.NoError(t, err) + return response + } + prepare := func(component *pluginv1.DiscoveredComponent, level string) *pluginv1.PrepareComponentResponse { + request := &pluginv1.ComponentRequest{RootDirectory: root, Provider: "terragrunt", ProviderConfiguration: opts, Address: component.Address, Source: component.Source, Configuration: component.Configuration, Operation: &pluginv1.ComponentOperation{Mode: "native", Command: "plan"}, Invocation: &pluginv1.Invocation{LogLevel: level, Environment: map[string]string{"ATMOS_TERRAFORM_BINARY": "must-not-execute"}}} + request.Effects = &pluginv1.ComponentEffects{Commands: true, Network: true, Secrets: true, Writes: true, StateReads: true} + response, err := provider.Prepare(t.Context(), request) + require.NoError(t, err) + return response + } + + quiet := discover("") + require.Empty(t, quiet.Logs, "engine chatter is hidden at the Atmos default level, even when Terragrunt warns") + require.Empty(t, discover("off").Logs) + noisy := discover("trace") + require.NotEmpty(t, noisy.Logs) + require.Empty(t, prepare(noisy.Components[1], "warn").Logs) + logs := prepare(noisy.Components[1], "debug").Logs + require.NotEmpty(t, logs) + for _, entry := range logs { + require.NotEqual(t, pluginv1.LogLevel_LOG_LEVEL_UNSPECIFIED, entry.Level) + require.NotEqual(t, pluginv1.LogLevel_LOG_LEVEL_TRACE, entry.Level, "trace events are below the requested level") + require.NotEmpty(t, entry.Message) + require.NotNil(t, entry.Time) + } +} + +func TestFailureCarriesTheLogsThatPrecededIt(t *testing.T) { + root := t.TempDir() + root, err := filepath.EvalSymlinks(root) + require.NoError(t, err) + require.NoError(t, os.MkdirAll(filepath.Join(root, "module"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(root, "terragrunt.hcl"), []byte("terraform { source = \"./module\" }\ninputs = { broken = local.absent }\n"), 0o644)) + request := componentRequest(t) + request.RootDirectory, request.Source = root, "terragrunt.hcl" + request.Configuration, err = encode(map[string]any{}) + require.NoError(t, err) + request.Invocation.LogLevel = "trace" + + _, err = New(nil).Prepare(t.Context(), request) + + require.Error(t, err) + detail, ok := component.FailureDetail(err) + require.True(t, ok) + require.NotEmpty(t, detail.Logs, "the events before the failure explain it") + request.Invocation.LogLevel = "off" + _, err = New(nil).Prepare(t.Context(), request) + detail, ok = component.FailureDetail(err) + require.True(t, ok) + require.Empty(t, detail.Logs) +} + +func TestLogLevelsMapOntoTheProtocol(t *testing.T) { + for name, want := range map[string]pluginv1.LogLevel{ + "trace": pluginv1.LogLevel_LOG_LEVEL_TRACE, "DEBUG": pluginv1.LogLevel_LOG_LEVEL_DEBUG, "info": pluginv1.LogLevel_LOG_LEVEL_INFO, + "warn": pluginv1.LogLevel_LOG_LEVEL_WARN, "error": pluginv1.LogLevel_LOG_LEVEL_ERROR, "other": pluginv1.LogLevel_LOG_LEVEL_UNSPECIFIED, + } { + require.Equal(t, want, logLevel(name), name) + } +} + +func encodedOption(t *testing.T, value any) *pluginv1.ComponentValue { + t.Helper() + encoded, err := encode(value) + require.NoError(t, err) + return encoded +} + +func TestOptionsOverrideTheEnvironmentAndTheUnit(t *testing.T) { + env := map[string]string{"TG_IAM_ASSUME_ROLE": "arn:aws:iam::1:role/environment", "TG_DOWNLOAD_DIR": "/env-cache", "UNRELATED": "kept"} + features, err := applyOptions(env, map[string]*pluginv1.ComponentValue{ + "feature": encodedOption(t, map[string]any{"alpha": "true", "tier": "gold"}), + "iam_assume_role": encodedOption(t, "arn:aws:iam::1:role/option"), + "iam_assume_role_duration": encodedOption(t, 900), + "iam_assume_role_session_name": encodedOption(t, "ci"), + "iam_assume_role_web_identity_token": encodedOption(t, "token"), + "download_dir": encodedOption(t, "/option-cache"), + }) + require.NoError(t, err) + require.Equal(t, map[string]string{"alpha": "true", "tier": "gold"}, features) + require.Equal(t, "arn:aws:iam::1:role/option", env["TG_IAM_ASSUME_ROLE"]) + require.Equal(t, "900", env["TG_IAM_ASSUME_ROLE_DURATION"]) + require.Equal(t, "ci", env["TG_IAM_ASSUME_ROLE_SESSION_NAME"]) + require.Equal(t, "token", env["TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN"]) + require.Equal(t, "/option-cache", env["TG_DOWNLOAD_DIR"]) + require.Equal(t, "kept", env["UNRELATED"]) + + untouched := map[string]string{"A": "1"} + none, err := applyOptions(untouched, nil) + require.NoError(t, err) + require.Nil(t, none) + require.Equal(t, map[string]string{"A": "1"}, untouched, "absent options change nothing") +} + +func TestOptionsRejectUnknownNamesAndWrongTypes(t *testing.T) { + _, err := applyOptions(map[string]string{}, map[string]*pluginv1.ComponentValue{"parallelism": encodedOption(t, 4)}) + require.ErrorIs(t, err, ErrUnsupported) + _, err = applyOptions(map[string]string{}, map[string]*pluginv1.ComponentValue{"feature": encodedOption(t, "not-a-map")}) + require.ErrorIs(t, err, ErrUnsupported) + _, err = applyOptions(map[string]string{}, map[string]*pluginv1.ComponentValue{"download_dir": {}}) + require.ErrorIs(t, err, ErrUnsupported) +} + +func TestFeatureOptionsRankAboveEnvironmentAndConfiguration(t *testing.T) { + config, err := encode(map[string]any{"enabled": true, "features": map[string]any{"tier": "config", "size": 3}}) + require.NoError(t, err) + req := model.Request{Environment: map[string]string{"TG_FEATURE": "tier=environment,wide=true"}, Features: map[string]string{"tier": "option"}} + require.NoError(t, withFeatures(&req, config)) + require.Equal(t, map[string]string{"tier": "option", "size": "3", "wide": "true"}, req.Features) +} + +func TestOperationAcceptsBothModesAndDeclaredOptions(t *testing.T) { + request := componentRequest(t) + request.Operation.Options = map[string]*pluginv1.ComponentValue{"iam_assume_role": encodedOption(t, "arn:aws:iam::1:role/option")} + for _, mode := range []string{"native", "executable"} { + request.Operation.Mode = mode + got, err := operation(request.RootDirectory, "terragrunt", request.Operation, request.Invocation) + require.NoError(t, err, mode) + require.Equal(t, "arn:aws:iam::1:role/option", got.Environment["TG_IAM_ASSUME_ROLE"]) + require.Equal(t, "native", got.Mode, "evaluation is the same in both modes") + } + require.Empty(t, request.Invocation.Environment["TG_IAM_ASSUME_ROLE"], "the host's invocation is never modified") +} + +func TestExecutableModeNeverPreparesNatively(t *testing.T) { + request := componentRequest(t) + request.Operation.Mode = "executable" + prepared := false + p := New(func(context.Context, model.Request) (*model.Resolution, error) { + prepared = true + return &model.Resolution{}, nil + }) + _, err := p.Prepare(t.Context(), request) + require.Error(t, err) + require.False(t, prepared, "no HCL evaluation or command runs for a unit the executable owns") + + // State resolution and validation remain available: Atmos reads state locations the same way in both modes. + _, err = p.Validate(t.Context(), request) + require.NoError(t, err) +} + +func TestSettingsAcceptBothModes(t *testing.T) { + for _, mode := range []string{"native", "executable"} { + value, err := encode(map[string]any{"enabled": true, "mode": mode}) + require.NoError(t, err) + require.NoError(t, settings(value), mode) + } + value, err := encode(map[string]any{"enabled": true, "mode": "cli"}) + require.NoError(t, err) + require.Error(t, settings(value)) +} + +// TestManifestDeclaresExactlyTheOptionsThePluginAccepts keeps the static metadata the host builds flags +// from in step with the options the plugin understands: a declared option the plugin rejects would fail +// every command, and an accepted option nobody declared could never be set. +func TestManifestDeclaresExactlyTheOptionsThePluginAccepts(t *testing.T) { + raw, err := os.ReadFile(filepath.Join("..", "..", "plugin.yaml")) + require.NoError(t, err) + var manifest struct { + Spec struct { + Capabilities struct { + Components struct { + Discovery struct { + Terragrunt struct { + Modes []string `yaml:"modes"` + Options []struct { + Name string `yaml:"name"` + Sensitive bool `yaml:"sensitive"` + Commands []string `yaml:"commands"` + } `yaml:"options"` + } `yaml:"terragrunt"` + } `yaml:"discovery"` + } `yaml:"components"` + } `yaml:"capabilities"` + } `yaml:"spec"` + } + require.NoError(t, yaml.Unmarshal(raw, &manifest)) + declared := manifest.Spec.Capabilities.Components.Discovery.Terragrunt + require.ElementsMatch(t, []string{"native", "executable"}, declared.Modes) + require.NotEmpty(t, declared.Options) + + names := []string{} + for _, option := range declared.Options { + names = append(names, option.Name) + require.NotEmpty(t, option.Commands, option.Name) + if option.Sensitive { + require.Equal(t, "iam_assume_role_web_identity_token", option.Name) + } + } + accepted := []string{"feature"} + for name := range toolEnvironment { + accepted = append(accepted, name) + } + require.ElementsMatch(t, accepted, names) +} diff --git a/plugins/terragrunt/plugin.tests.yaml b/plugins/terragrunt/plugin.tests.yaml index c0bbb71d48c..b60e6db3b0f 100644 --- a/plugins/terragrunt/plugin.tests.yaml +++ b/plugins/terragrunt/plugin.tests.yaml @@ -178,3 +178,99 @@ integration: script: | semantics = module.load("scripts/semantics.star") semantics.tflint_hook() + - name: values-exact-and-sensitive + type: script + interpreter: starlark + script: | + values = module.load("scripts/values_logging.star") + values.values() + - name: logging-through-atmos + type: script + interpreter: starlark + script: | + values = module.load("scripts/values_logging.star") + values.logging() + - name: warnings-once + type: script + interpreter: starlark + script: | + values = module.load("scripts/values_logging.star") + values.warnings_once() + - name: aws-identity-in-plugin + type: script + interpreter: starlark + script: | + values = module.load("scripts/values_logging.star") + values.aws_identity() + - name: provider-flags-help + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.help_lists_provider_flags() + - name: provider-flags-features + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.feature_flags() + - name: provider-flags-saved-plan + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.saved_plan_identity() + - name: executable-invocation + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_invocation() + - name: executable-flags-and-config + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_flags_and_config() + - name: executable-ordering + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_ordering() + - name: executable-consumers + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_consumers() + - name: executable-failures + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_failures() + - name: executable-requirements + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.executable_requirements() + - name: executable-real-terragrunt + type: script + interpreter: starlark + script: | + modes = module.load("scripts/modes.star") + modes.real_terragrunt() + - name: pro-cross-runner-saved-plan + type: script + interpreter: starlark + script: | + pro = module.load("scripts/pro.star") + pro.restored_plan_is_applied_on_another_runner() + - name: pro-deploy-verifies-stored-plan + type: script + interpreter: starlark + script: | + pro = module.load("scripts/pro.star") + pro.deploy_applies_after_verifying_the_stored_plan() diff --git a/plugins/terragrunt/plugin.yaml b/plugins/terragrunt/plugin.yaml index 4cb32a20527..ea09c2fb5b3 100644 --- a/plugins/terragrunt/plugin.yaml +++ b/plugins/terragrunt/plugin.yaml @@ -38,6 +38,43 @@ spec: terragrunt: component_type: terraform schema: schemas/config.json + modes: [native, executable] + # Static option declarations: Atmos registers these flags and renders their help without + # starting the plugin. Atmos owns stack selection, --affected, --all, --ui, and scheduling, + # so Terragrunt's queue, filter, parallelism, and auth-provider flags are not options. + options: + - name: feature + type: map + config: features + env: [TG_FEATURE] + commands: &unit-commands [plan, apply, deploy, destroy, init, import, output, refresh, show, state, taint, test, untaint, validate, workspace] + description: Override a Terragrunt feature flag with name=value. Repeat the flag for several features. + - name: iam_assume_role + type: string + env: [TG_IAM_ASSUME_ROLE] + commands: *unit-commands + description: IAM role ARN that overrides the unit's iam_role. + - name: iam_assume_role_duration + type: int + env: [TG_IAM_ASSUME_ROLE_DURATION] + commands: *unit-commands + description: Session duration in seconds for the assumed IAM role. + - name: iam_assume_role_session_name + type: string + env: [TG_IAM_ASSUME_ROLE_SESSION_NAME] + commands: *unit-commands + description: Session name for the assumed IAM role. + - name: iam_assume_role_web_identity_token + type: string + sensitive: true + env: [TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN] + commands: *unit-commands + description: Web identity token, or the path of a file that holds it, for AssumeRoleWithWebIdentity. + - name: download_dir + type: string + env: [TG_DOWNLOAD_DIR] + commands: *unit-commands + description: Directory that receives downloaded module sources instead of .terragrunt-cache. validation: terragrunt: component_type: terraform diff --git a/plugins/terragrunt/schemas/config.json b/plugins/terragrunt/schemas/config.json index 8ad46f931a1..b4ac8082e06 100644 --- a/plugins/terragrunt/schemas/config.json +++ b/plugins/terragrunt/schemas/config.json @@ -9,7 +9,11 @@ "const": "terragrunt" }, "mode": { - "const": "native" + "enum": [ + "native", + "executable" + ], + "description": "native adapts units to Atmos; executable runs each unit with the pinned terragrunt executable." }, "features": { "type": "object", diff --git a/plugins/terragrunt/scripts/modes.star b/plugins/terragrunt/scripts/modes.star new file mode 100644 index 00000000000..2754d79de60 --- /dev/null +++ b/plugins/terragrunt/scripts/modes.star @@ -0,0 +1,438 @@ +# Opt-in CLI acceptance tests for the typed provider flags and for executable mode. +# +# Provider flags: the options the package declares in plugin.yaml appear on `atmos terraform` commands +# and in help, follow command line > environment > configuration > declared default, are validated +# before anything runs, and are part of a saved plan's identity. +# +# Executable mode (`components.terraform.terragrunt.mode: executable`): Atmos discovers the units, +# orders them, authenticates, resolves the toolchain, and then runs one pinned `terragrunt run` command +# per unit instead of OpenTofu. Two kinds of executable are used: +# * a stand-in built from fixtures/toolprobe that records how Atmos invoked it and then runs the real +# OpenTofu in the unit directory. It proves the invocation (arguments, directory, environment, +# order); it does not prove Terragrunt behavior. +# * the real Terragrunt, installed by the Atmos toolchain, in one scenario. It needs network access and is +# skipped with a warning when the install fails. +# Every fixture uses only built-in terraform_data resources and local state. Importing this module has no effects. +fixtures = module.load("fixtures.star") +lifecycle = module.load("lifecycle_extended.star") +hardening = module.load("hardening.star") +semantics = module.load("semantics.star") + +STACK = lifecycle.STACK +TERRAGRUNT_VERSION = "1.2.1" + + +def contains(result, text): + return text in semantics.output_of(result) + + +def expect(result, text, context): + semantics.expect(result, text, context) + + +def expect_absent(result, text, context): + semantics.expect_absent(result, text, context) + + +# --------------------------------------------------------------------------------------------- +# Provider flags +# --------------------------------------------------------------------------------------------- + +def help_lists_provider_flags(): + binary = semantics.engine() + root = semantics.new_project("atmos-terragrunt-flags-help-", binary) + semantics.configure(root, binary) + plan = semantics.run(root, ["terraform", "plan", "--help"]) + for text in ["TERRAGRUNT FLAGS", "--terragrunt-feature", "--terragrunt-iam-assume-role", "--terragrunt-iam-assume-role-duration", "--terragrunt-download-dir"]: + expect(plan, text, "terraform plan --help") + # Commands that run no unit do not get the flags. + backend = semantics.run(root, ["terraform", "backend", "--help"]) + expect_absent(backend, "--terragrunt-feature", "terraform backend --help") + + # Without the provider enabled, nothing is registered. + plain = semantics.new_project("atmos-terragrunt-flags-off-", binary) + fixtures.write(plain, "atmos.yaml", json.encode({"base_path": ".", "components": {"terraform": {"command": binary}}})) + expect_absent(semantics.run(plain, ["terraform", "plan", "--help"]), "TERRAGRUNT FLAGS", "terraform plan --help without the provider") + ui.success("Provider flags: declared options appear in help under a provider section, only where they apply") + + +def feature_flags(): + binary = semantics.engine() + root = semantics.new_project("atmos-terragrunt-flags-feature-", binary) + lifecycle.write_unit(root, "featured", semantics.FEATURE_UNIT) + + # A declared default applies when nothing sets the feature. + semantics.configure(root, binary) + semantics.terraform(root, "apply", "featured", ["-auto-approve"]) + fixtures.check(semantics.value_of(root, "featured") == "basic|2|narrow|", "Default was not used: " + semantics.value_of(root, "featured")) + + # The flag outranks the environment, and the environment outranks the configuration, per name. + semantics.configure(root, binary, features={"tier": "config", "size": 7}) + semantics.terraform(root, "apply", "featured", ["-auto-approve"]) + fixtures.check(semantics.value_of(root, "featured") == "config|7|narrow|", "Configuration was not used: " + semantics.value_of(root, "featured")) + semantics.terraform(root, "apply", "featured", ["-auto-approve"], env={"TG_FEATURE": "tier=environment"}) + fixtures.check(semantics.value_of(root, "featured") == "environment|7|narrow|", "TG_FEATURE did not beat the configuration: " + semantics.value_of(root, "featured")) + semantics.terraform(root, "apply", "featured", ["-auto-approve"], env={"ATMOS_TERRAGRUNT_FEATURE": "tier=atmos-environment"}) + fixtures.check(semantics.value_of(root, "featured") == "atmos-environment|7|narrow|", "ATMOS_TERRAGRUNT_FEATURE was ignored: " + semantics.value_of(root, "featured")) + semantics.terraform(root, "apply", "featured", ["-auto-approve"], flags=["--terragrunt-feature", "tier=cli", "--terragrunt-feature=wide=true"], env={"TG_FEATURE": "tier=environment"}) + fixtures.check(semantics.value_of(root, "featured") == "cli|7|wide|", "The flag did not beat the environment: " + semantics.value_of(root, "featured")) + + # An explicit false is a value, not an absent flag. + semantics.terraform(root, "apply", "featured", ["-auto-approve"], flags=["--terragrunt-feature=wide=false"], env={"TG_FEATURE": "wide=true"}) + fixtures.check(semantics.value_of(root, "featured") == "config|7|narrow|", "An explicit false was dropped: " + semantics.value_of(root, "featured")) + + # A malformed value is rejected before any discovery or infrastructure effect. + fresh = "fresh" + lifecycle.write_unit(root, fresh, semantics.FEATURE_UNIT) + bad = semantics.terraform(root, "apply", fresh, ["-auto-approve"], flags=["--terragrunt-feature", "novalue"], failing=True) + expect(bad, "name=value", "malformed --terragrunt-feature") + fixtures.check(not fs.exists(lifecycle.state_path(root, fresh)), "A rejected flag still changed state") + ui.success("Provider flags: feature flag precedence (flag > environment > configuration > default), explicit false, validation before effects") + + +def saved_plan_identity(): + binary = semantics.engine() + root = semantics.new_project("atmos-terragrunt-flags-plan-", binary) + lifecycle.write_unit(root, "featured", semantics.FEATURE_UNIT) + semantics.configure(root, binary) + + # The effective options are part of what a saved plan is bound to. + semantics.terraform(root, "plan", "featured", flags=["--terragrunt-feature", "tier=reviewed"]) + other = semantics.terraform(root, "apply", "featured", ["-auto-approve"], flags=["--terragrunt-feature", "tier=different", "--from-plan"], failing=True) + fixtures.check("plan verification failed" in semantics.output_of(other), "A plan reviewed with other options was accepted:\n" + semantics.output_of(other)) + fixtures.check(not fs.exists(lifecycle.state_path(root, "featured")), "A rejected plan created state") + absent = semantics.terraform(root, "apply", "featured", ["-auto-approve"], flags=["--from-plan"], failing=True) + fixtures.check("plan verification failed" in semantics.output_of(absent), "A plan reviewed with options was applied without them:\n" + semantics.output_of(absent)) + + # The same options apply exactly what was reviewed. + semantics.terraform(root, "plan", "featured", flags=["--terragrunt-feature", "tier=reviewed"]) + applied = semantics.terraform(root, "apply", "featured", ["-auto-approve"], flags=["--terragrunt-feature", "tier=reviewed", "--from-plan"]) + fixtures.check("Apply complete! Resources: 1 added" in applied.stdout, applied.stdout) + fixtures.check(semantics.value_of(root, "featured") == "reviewed|2|narrow|", "The applied value differs from the reviewed plan: " + semantics.value_of(root, "featured")) + ui.success("Provider flags: effective options are part of the saved-plan identity") + + +# --------------------------------------------------------------------------------------------- +# Executable mode +# --------------------------------------------------------------------------------------------- + +UNIT_MODULE = """ +resource "terraform_data" "unit" { + input = "@NAME@" +} +output "value" { + value = terraform_data.unit.output +} +""" + +BACKEND_FILE = """ +terraform { + backend "local" { + path = "state/terraform.tfstate" + } +} +""" + +CONSUMER_STACK = """ +components: + terraform: + consumer: + vars: + from_output: !terraform.output producer live/dev value + from_state: !terraform.state producer live/dev value +""" + +FAILING_MODULE = """ +output "value" { + value = tonumber("not-a-number") +} +""" + + +def install_terragrunt_stand_in(tools, version, real, suffix, reported=None): + directory = tools + "/bin/gruntwork-io/terragrunt/" + version + fs.mkdir(directory, parents=True) + exec.run(["go", "build", "-o", directory + "/terragrunt" + suffix, "./fixtures/toolprobe"], working_directory=fs.resolve("."), output="capture") + fs.write_file(directory + "/real-tool.txt", real) + if reported != None: + fs.write_file(directory + "/version.txt", reported) + return directory + + +def write_stand_in_unit(root, name, content=None, module=None, dependencies=[]): + # The stand-in runs OpenTofu in the unit directory itself, so the unit carries its own module and backend. + unit = "terraform {\n source = \".\"\n}\n" + if dependencies: + unit += "dependencies {\n paths = [" + ", ".join(["\"../" + d + "\"" for d in dependencies]) + "]\n}\n" + unit += lifecycle.BACKEND + fixtures.write(root, "live/dev/" + name + "/terragrunt.hcl", content or unit) + fixtures.write(root, "live/dev/" + name + "/main.tf", (module or UNIT_MODULE).replace("@NAME@", name)) + fixtures.write(root, "live/dev/" + name + "/backend.tf", BACKEND_FILE) + + +def executable_config(binary, tools=None, features=None): + config = fixtures.configuration(fs.resolve("."), binary=binary) + config["components"]["terraform"]["terragrunt"]["mode"] = "executable" + if features != None: + config["components"]["terraform"]["terragrunt"]["features"] = features + config["stacks"] = {"base_path": "stacks", "included_paths": ["**/*.yaml"]} + if tools != None: + config["toolchain"] = {"install": "never", "install_path": tools} + return config + + +def stand_in_project(prefix, version="9.9.9", reported=None): + real = semantics.engine() + work = fixtures.workspace(prefix) + suffix = exec.run(["go", "env", "GOEXE"], output="capture").stdout.strip() + tools = work + "/tools" + stand_in = install_terragrunt_stand_in(tools, version, real, suffix, reported) + root = work + "/project" + fixtures.write(root, "atmos.yaml", json.encode(executable_config(real, tools))) + fixtures.write(root, ".tool-versions", "terragrunt " + version + "\n") + return struct(root=root, stand_in=stand_in, real=real, work=work, tools=tools, suffix=suffix) + + +def calls(project): + log = project.stand_in + "/terragrunt.log" + if not fs.exists(log): + return [] + return [json.decode(line) for line in fs.read_file(log).splitlines() if line.strip() != ""] + + +def engine_calls(project): + # Every recorded terragrunt command splits at `--` into Terragrunt arguments and the engine command. + result = [] + for call in calls(project): + arguments = call["args"] + index = arguments.index("--") + result.append(struct(before=arguments[:index], engine=arguments[index + 1:], dir=call["dir"], env=call["env"])) + return result + + +def executable_command(project, operation, unit, arguments=[], flags=[], env={}, failing=False): + return semantics.terraform(project.root, operation, unit, arguments, flags=flags, env=env, failing=failing) + + +def listed_engines(root): + rows = json.decode(semantics.run(root, ["list", "instances", "--format=json"]).stdout) + return {row["Component"]: row for row in rows} + + +def executable_invocation(): + project = stand_in_project("atmos-terragrunt-exec-") + write_stand_in_unit(project.root, "app") + + # Units are listed with the engine that runs them. + rows = listed_engines(project.root) + fixtures.check(rows["app"]["Engine"] == "terragrunt", "list instances did not show the terragrunt engine: " + str(rows)) + fixtures.check(rows["app"]["Type"] == "terraform", "The component type changed: " + str(rows)) + + # plan: one `terragrunt run` in the unit directory; the engine command and its arguments follow `--`. + plan = executable_command(project, "plan", "app") + expect(plan, "1 to add", "plan through terragrunt") + recorded = engine_calls(project) + fixtures.check(len(recorded) == 1, "Expected one terragrunt command, got " + str(recorded)) + first = recorded[0] + unit_dir = project.root + "/live/dev/app" + fixtures.check(first.engine == ["plan", "-no-color"], "Unexpected engine command: " + str(first.engine)) + fixtures.check(first.before[0] == "--working-dir" and first.before[1].endswith("live/dev/app") and first.before[2] == "run", "Unexpected terragrunt arguments: " + str(first.before)) + fixtures.check(first.env.get("TG_NON_INTERACTIVE") == "true", "Terragrunt was allowed to prompt: " + str(first.env)) + fixtures.check(first.env.get("TG_TF_FORWARD_STDOUT") == "true", "Engine output was not forwarded untouched: " + str(first.env)) + fixtures.check(first.env.get("TG_TF_PATH", "").endswith(semantics.engine().rsplit("/", 1)[-1]), "Terragrunt did not run the Atmos-selected engine: " + str(first.env)) + + # Native machinery never ran: no workdir, no generated varfile, no backend file written by Atmos. + fixtures.check(not fs.exists(project.root + "/.workdir"), "Native provisioning ran for an executable unit") + fixtures.check(fs.glob(unit_dir + "/*.terraform.tfvars.json") == [], "A native varfile was generated") + + # apply with pass-through arguments; deploy is apply without approval. + executable_command(project, "apply", "app", ["-auto-approve"]) + fixtures.check(lifecycle.state_output(project.root, "app") == "app", "The unit was not applied") + fixtures.check(engine_calls(project)[-1].engine == ["apply", "-auto-approve", "-no-color"], "Unexpected apply command: " + str(engine_calls(project)[-1].engine)) + executable_command(project, "deploy", "app") + fixtures.check(engine_calls(project)[-1].engine[:2] == ["apply", "-auto-approve"], "deploy did not apply without approval: " + str(engine_calls(project)[-1].engine)) + + # output and compound subcommands are forwarded as written. + out = semantics.terraform(project.root, "output", "app", ["-json"], flags=[]) + expect(out, "\"value\"", "output -json through terragrunt") + fixtures.check(engine_calls(project)[-1].engine[0] == "output", "output was not forwarded") + semantics.terraform(project.root, "validate", "app", flags=[]) + fixtures.check(engine_calls(project)[-1].engine[0] == "validate", "validate was not forwarded: " + str(engine_calls(project)[-1].engine)) + ui.success("Executable mode: engine listed as terragrunt; plan, apply, deploy, output and validate run one pinned terragrunt command per unit") + + +def executable_flags_and_config(): + project = stand_in_project("atmos-terragrunt-exec-flags-") + write_stand_in_unit(project.root, "app") + config = executable_config(project.real, project.tools, features={"from_config": True, "shared": "config"}) + fixtures.write(project.root, "atmos.yaml", json.encode(config)) + + token = "tok-s3cret-value" + result = executable_command(project, "plan", "app", flags=[ + "--terragrunt-feature", "shared=cli", "--terragrunt-feature=extra=1", + "--terragrunt-iam-assume-role", "arn:aws:iam::123456789012:role/ci", + "--terragrunt-iam-assume-role-duration=900", "--terragrunt-iam-assume-role-session-name", "atmos", + "--terragrunt-download-dir", project.work + "/downloads", + "--terragrunt-iam-assume-role-web-identity-token", token, + ]) + recorded = engine_calls(project)[-1] + before = " ".join(recorded.before) + for text in ["--feature extra=1", "--feature from_config=true", "--feature shared=cli", "--iam-assume-role arn:aws:iam::123456789012:role/ci", "--iam-assume-role-duration 900", "--iam-assume-role-session-name atmos", "--download-dir " + project.work + "/downloads"]: + fixtures.check(text in before, "Terragrunt was not given '" + text + "': " + before) + fixtures.check("shared=config" not in before, "A configured feature overrode the flag: " + before) + # The sensitive option travels through the environment, never through argv, and is never printed. + fixtures.check(token not in before, "The sensitive option reached the arguments") + fixtures.check(recorded.env.get("TG_IAM_ASSUME_ROLE_WEB_IDENTITY_TOKEN") == token, "The sensitive option did not reach the environment") + fixtures.check(token not in semantics.output_of(result), "The sensitive option was printed") + + # Absent options send nothing. + executable_command(project, "plan", "app") + quiet = " ".join(engine_calls(project)[-1].before) + for text in ["--iam-assume-role", "--download-dir"]: + fixtures.check(text not in quiet, "An absent option was sent: " + quiet) + ui.success("Executable mode: provider flags and configured features become Terragrunt flags; secrets stay out of argv and output") + + +def executable_ordering(): + project = stand_in_project("atmos-terragrunt-exec-all-") + write_stand_in_unit(project.root, "base") + write_stand_in_unit(project.root, "app", dependencies=["base"]) + result = semantics.run(project.root, ["terraform", "apply", "--all", "-s", STACK, "--", "-auto-approve", "-no-color"]) + expect(result, "Apply complete", "apply --all") + order = [c.dir.rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "apply"] + fixtures.check(order == ["base", "app"], "Dependencies were not applied first: " + str(order)) + # Atmos schedules the units; Terragrunt never receives --all. + for call in engine_calls(project): + fixtures.check("--all" not in call.before and "--all" not in call.engine, "terragrunt run --all was used: " + str(call.before)) + semantics.run(project.root, ["terraform", "destroy", "--all", "-s", STACK, "--", "-auto-approve", "-no-color"]) + order = [c.dir.rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "destroy"] + fixtures.check(order == ["app", "base"], "Destroy did not run in reverse dependency order: " + str(order)) + ui.success("Executable mode: Atmos schedules units in dependency order, one terragrunt command each, never terragrunt run --all") + + +def executable_consumers(): + project = stand_in_project("atmos-terragrunt-exec-consumer-") + write_stand_in_unit(project.root, "producer") + fixtures.write(project.root, "components/terraform/consumer/main.tf", lifecycle.CONSUMER_MODULE) + fixtures.write(project.root, "stacks/consumers.yaml", CONSUMER_STACK) + executable_command(project, "apply", "producer", ["-auto-approve"]) + # An ordinary component reads the executable unit's state and outputs through the discovered backend. + values = lifecycle.described_vars(project.root, "consumer") + fixtures.check(values["from_state"] == "producer" and values["from_output"] == "producer", "Consumers did not read the unit: " + str(values)) + ui.success("Executable mode: !terraform.state and !terraform.output read executable units through the discovered backend") + + +def executable_failures(): + project = stand_in_project("atmos-terragrunt-exec-fail-") + write_stand_in_unit(project.root, "app") + write_stand_in_unit(project.root, "broken", module=FAILING_MODULE) + + # A failing unit fails the command with its own error and a failing exit code. + failed = semantics.invoke(project.root, ["terraform", "plan", "broken", "-s", STACK, "--", "-no-color"]) + fixtures.check(failed.exit_code != 0, "A failing unit reported success:\n" + semantics.output_of(failed)) + expect(failed, "tonumber", "failing unit output") + + # Unsupported commands and stack overrides are rejected before anything runs. + before = len(calls(project)) + shell = semantics.invoke(project.root, ["terraform", "shell", "app", "-s", STACK]) + fixtures.check(shell.exit_code != 0, "shell was accepted in executable mode") + expect(shell, "no Terragrunt equivalent", "terraform shell") + saved = semantics.invoke(project.root, ["terraform", "apply", "app", "-s", STACK, "--from-plan"]) + fixtures.check(saved.exit_code != 0, "--from-plan was accepted in executable mode") + expect(saved, "saved plans", "apply --from-plan") + fixtures.write(project.root, "stacks/override.yaml", "import:\n - terragrunt://live/dev/app\ncomponents:\n terraform:\n app:\n vars:\n region: us-east-1\n") + overridden = semantics.invoke(project.root, ["terraform", "plan", "app", "-s", "override", "--", "-no-color"]) + fixtures.check(overridden.exit_code != 0, "Stack vars were accepted for an executable unit") + expect(overridden, "stack vars", "stack vars override") + fixtures.check(len(calls(project)) == before, "Rejected commands ran terragrunt") + + # Environment given to the unit's component reaches terragrunt. + fixtures.write(project.root, "stacks/env.yaml", "import:\n - terragrunt://live/dev/app\ncomponents:\n terraform:\n app:\n env:\n TG_TF_PATH: " + project.real + "\n MARKER: from-stack\n") + semantics.run(project.root, ["terraform", "plan", "app", "-s", "env", "--", "-no-color"]) + fixtures.check(engine_calls(project)[-1].env.get("TG_TF_PATH") == project.real, "A component env entry did not win over the default") + ui.success("Executable mode: failing units fail the command; unsupported commands and stack overrides are rejected before anything runs") + + +def executable_requirements(): + # The executable is not pinned and not on PATH: a clear error that says how to pin it. + project = stand_in_project("atmos-terragrunt-exec-missing-") + write_stand_in_unit(project.root, "app") + fs.remove(project.root + "/.tool-versions") + missing = semantics.invoke(project.root, ["terraform", "plan", "app", "-s", STACK, "--", "-no-color"], path=project.work) + fixtures.check(missing.exit_code != 0, "A missing terragrunt was accepted") + expect(missing, "terragrunt executable not found", "missing terragrunt") + expect(missing, ".tool-versions", "missing terragrunt") + + # A pinned version older than the minimum is rejected before the unit runs. + old = stand_in_project("atmos-terragrunt-exec-old-", reported="v0.99.0") + write_stand_in_unit(old.root, "app") + rejected = semantics.invoke(old.root, ["terraform", "plan", "app", "-s", STACK, "--", "-no-color"]) + fixtures.check(rejected.exit_code != 0, "An old terragrunt was accepted") + expect(rejected, "older than the minimum 1.0.0", "old terragrunt") + fixtures.check(engine_calls(old) == [], "The unit ran with an unsupported terragrunt") + ui.success("Executable mode: a missing or too old terragrunt is a clear error, and nothing runs") + + +# --------------------------------------------------------------------------------------------- +# Real Terragrunt +# --------------------------------------------------------------------------------------------- + +REAL_UNIT = """ +terraform { + source = "../../../modules/unit" +} + +feature "tier" { + default = "basic" +} + +inputs = { + greeting = feature.tier.value +} +""" + + +def real_terragrunt(): + real = semantics.engine() + work = fixtures.workspace("atmos-terragrunt-real-") + root = work + "/project" + tools = work + "/tools" + config = executable_config(real, tools) + config["toolchain"]["install"] = "auto" + fixtures.write(root, "atmos.yaml", json.encode(config)) + fixtures.write(root, ".tool-versions", "terragrunt " + TERRAGRUNT_VERSION + "\n") + fixtures.write(root, "modules/unit/main.tf", lifecycle.UNIT_MODULE) + fixtures.write(root, "components/terraform/consumer/main.tf", lifecycle.CONSUMER_MODULE) + fixtures.write(root, "stacks/consumers.yaml", CONSUMER_STACK) + lifecycle.write_unit(root, "producer", REAL_UNIT) + + # Installing the pinned executable needs network access; without it the scenario cannot run. + installed = atmos.run(["toolchain", "install", "gruntwork-io/terragrunt@" + TERRAGRUNT_VERSION], working_directory=root, env={"ATMOS_TELEMETRY_ENABLED": "false", "NO_COLOR": "1"}, output="capture", check=False) + if installed.exit_code != 0: + ui.warning("Real Terragrunt could not be installed (no network?); skipped") + return + + plan = semantics.terraform(root, "plan", "producer") + expect(plan, "1 to add", "plan through the real terragrunt") + # The real executable ran: Terragrunt creates its working copy of the module. + fixtures.check(fs.glob(root + "/live/dev/producer/.terragrunt-cache/*") != [], "Terragrunt did not run in the unit") + + semantics.terraform(root, "apply", "producer", ["-auto-approve"]) + fixtures.check(lifecycle.state_output(root, "producer") == "basic|||", "The real terragrunt did not apply the unit: " + str(lifecycle.state_output(root, "producer"))) + + # A feature flag reaches the real executable and changes the unit. + semantics.terraform(root, "apply", "producer", ["-auto-approve"], flags=["--terragrunt-feature", "tier=premium"]) + fixtures.check(lifecycle.state_output(root, "producer") == "premium|||", "The feature flag did not reach terragrunt: " + str(lifecycle.state_output(root, "producer"))) + semantics.terraform(root, "apply", "producer", ["-auto-approve"], env={"TG_FEATURE": "tier=environment"}) + fixtures.check(lifecycle.state_output(root, "producer") == "environment|||", "TG_FEATURE did not reach terragrunt: " + str(lifecycle.state_output(root, "producer"))) + + # Consumers read the unit written by the real executable. + values = lifecycle.described_vars(root, "consumer") + fixtures.check(values["from_state"] == "environment|||" and values["from_output"] == "environment|||", "Consumers did not read the unit: " + str(values)) + + out = semantics.terraform(root, "output", "producer", ["-json"]) + expect(out, "environment", "output -json through the real terragrunt") + semantics.terraform(root, "destroy", "producer", ["-auto-approve"]) + state = json.decode(fs.read_file(lifecycle.state_path(root, "producer"))) + fixtures.check(not state["resources"], "Destroy left resources") + ui.success("Executable mode with the real Terragrunt " + TERRAGRUNT_VERSION + ": plan, apply, feature flags, outputs, consumers, destroy") diff --git a/plugins/terragrunt/scripts/pro.star b/plugins/terragrunt/scripts/pro.star new file mode 100644 index 00000000000..ab4e35c7233 --- /dev/null +++ b/plugins/terragrunt/scripts/pro.star @@ -0,0 +1,152 @@ +# Opt-in CLI acceptance tests for running Terragrunt units under Atmos Pro and CI, where `plan` and +# `apply` happen on different runners and the plan travels as an artifact. Real OpenTofu or +# Terraform, local state, and the built-in terraform_data resource; no cloud and no Atmos Pro API +# (the payloads sent to Atmos Pro are covered with a fake API in the host's tests/ package). +# +# A runner is modelled by its execution state: the checkout (sources) and the remote backend (the +# unit's state directory stands in for it) survive, while the whole `.workdir` of the earlier run is +# gone. Only the documented artifact set, the plan file and its record, comes back from the plan +# store. Importing this module has no effects; each integration step calls one scenario. +fixtures = module.load("fixtures.star") +lifecycle = module.load("lifecycle_extended.star") +hardening = module.load("hardening.star") + +STACK = lifecycle.STACK +REVIEWED_SHA = "0123456789abcdef0123456789abcdef01234567" + + +def atmos_in(root, arguments, failing=False): + # The planfile store keys artifacts by commit; the fixture is not a Git repository, so say which. + result = atmos.run( + arguments, + working_directory=root, + env={"NO_COLOR": "1", "ATMOS_TELEMETRY_ENABLED": "false", "TF_IN_AUTOMATION": "true", "POC_REVISION": "r1", "ATMOS_CI_SHA": REVIEWED_SHA}, + output="capture", + check=False, + ) + label = " ".join(arguments) + ":\n" + result.stdout + result.stderr + if failing: + fixtures.check(result.exit_code != 0, label + "\nunexpectedly succeeded") + else: + fixtures.check(result.exit_code == 0, label) + return result + + +def reviewed_plan_in_store(): + # The plan runner: plan the unit, then publish the plan artifact to the store. + root = hardening.new_project("atmos-terragrunt-pro-") + lifecycle.write_unit(root, "planned", lifecycle.PLAN_UNIT.replace("@GREETING@", "reviewed")) + lifecycle.terraform(root, "plan", "planned") + published = atmos_in(root, ["terraform", "planfile", "upload", "planned", "-s", STACK, "--sha", REVIEWED_SHA]) + hardening.expect(published, "Uploaded planfile", "the planfile upload") + fixtures.check(not fs.exists(lifecycle.state_path(root, "planned")), "Planning created state") + return root + + +def new_runner(root): + # Everything the earlier run left in its execution state is gone; the checkout and backend remain. + fs.remove(root + "/.workdir", recursive=True) + fixtures.check(len(lifecycle.planfiles(root)) == 0, "The new runner still has a plan file") + + +def restore_artifacts(root): + # The apply runner restores the artifact where this unit's workdir will be. + restored = atmos_in(root, ["terraform", "planfile", "download", "planned", "-s", STACK]) + hardening.expect(restored, "Downloaded planfile", "the planfile download") + files = lifecycle.planfiles(root) + fixtures.check(len(files) == 1, "Expected the restored plan file, found " + str(files)) + fixtures.check(fs.exists(files[0] + ".atmos.json"), "The plan record did not travel with the plan") + workdir = files[0].rsplit("/", 1)[0] + fixtures.check(sorted([path.replace("\\", "/").rsplit("/", 1)[1] for path in fs.glob(workdir + "/*")]) == sorted([files[0].replace("\\", "/").rsplit("/", 1)[1], files[0].replace("\\", "/").rsplit("/", 1)[1] + ".atmos.json"]), "Restoring must write only the documented artifact set: " + str(fs.glob(workdir + "/*"))) + return files[0] + + +def expect_rejected(root, reason, context): + result = lifecycle.terraform(root, "apply", "planned", flags=["--from-plan"], failing=True) + output = hardening.output_of(result) + fixtures.check(reason in output, "Expected '" + reason + "' for " + context + ":\n" + output) + fixtures.check("Apply complete" not in output, "A plan was applied despite " + context) + fixtures.check(not fs.exists(lifecycle.state_path(root, "planned")), context + " created state") + + +def restored_plan_is_applied_on_another_runner(): + root = reviewed_plan_in_store() + module_path = "modules/unit/main.tf" + unit_path = "live/dev/planned/terragrunt.hcl" + original_module = fs.read_file(root + "/" + module_path) + original_unit = fs.read_file(root + "/" + unit_path) + + # A tampered plan, a swapped record, and a missing record are all refused. + new_runner(root) + planfile = restore_artifacts(root) + fs.write_file(planfile, "tampered", overwrite=True) + expect_rejected(root, "create a new plan", "a tampered plan") + + new_runner(root) + planfile = restore_artifacts(root) + record = json.decode(fs.read_file(planfile + ".atmos.json")) + record["PlanDigest"] = "0" * 64 + fs.write_file(planfile + ".atmos.json", json.encode(record), overwrite=True) + expect_rejected(root, "create a new plan", "a record that belongs to another plan") + + new_runner(root) + planfile = restore_artifacts(root) + fs.remove(planfile + ".atmos.json") + expect_rejected(root, "no Atmos plan record", "a plan without its record") + + # A different source revision: the module or the unit differs from what was reviewed. + new_runner(root) + restore_artifacts(root) + fixtures.write(root, module_path, original_module + "# another revision\n") + expect_rejected(root, "create a new plan", "a different module revision") + fixtures.write(root, module_path, original_module) + + new_runner(root) + restore_artifacts(root) + fixtures.write(root, unit_path, original_unit.replace("reviewed", "edited-after-review")) + expect_rejected(root, "create a new plan", "a different unit revision") + fixtures.write(root, unit_path, original_unit) + + # A working directory that holds anything beyond the restored artifacts cannot be verified. + new_runner(root) + planfile = restore_artifacts(root) + fs.write_file(planfile.rsplit("/", 1)[0] + "/rogue.tf", 'output "rogue" { value = "unreviewed" }\n') + expect_rejected(root, "not part of the reviewed plan", "unreviewed files in the workdir") + + # With only the documented artifact set restored, the workdir is re-provisioned from the checkout + # and the reviewed plan applies exactly, without planning again. + new_runner(root) + planfile = restore_artifacts(root) + applied = lifecycle.terraform(root, "apply", "planned", flags=["--from-plan"]) + fixtures.check("Plan:" not in applied.stdout, "Applying a restored plan planned again:\n" + applied.stdout) + fixtures.check("Apply complete! Resources: 1 added" in applied.stdout, applied.stdout) + fixtures.check(lifecycle.state_output(root, "planned") == "reviewed|||", "Applied value differs from the reviewed plan") + fixtures.check(not fs.exists(planfile), "A consumed plan file was kept") + fixtures.check(not fs.exists(planfile + ".atmos.json"), "A consumed plan record was kept") + + # The same artifact cannot be applied twice. + again = lifecycle.terraform(root, "apply", "planned", flags=["--from-plan"], failing=True) + hardening.expect(again, "has no saved plan", "a second apply of the restored plan") + ui.success("Cross-runner saved plans: tamper, record, revision, and workdir checks; exact apply from the documented artifact set") + + +def deploy_applies_after_verifying_the_stored_plan(): + # `deploy` in CI reconciles instead of replaying: it downloads the stored plan, plans again, and + # applies the new plan only when the two agree. + root = hardening.new_project("atmos-terragrunt-deploy-") + config = json.decode(fs.read_file(root + "/atmos.yaml")) + store = root + "/store" + config["components"]["terraform"]["planfiles"] = {"default": "local", "stores": {"local": {"type": "local/dir", "options": {"path": store}}}} + config["ci"] = {"enabled": True} + fixtures.write(root, "atmos.yaml", json.encode(config)) + lifecycle.write_unit(root, "planned", lifecycle.PLAN_UNIT.replace("@GREETING@", "reviewed")) + + atmos_in(root, ["terraform", "plan", "planned", "-s", STACK, "--ci"]) + artifacts = fs.glob(store + "/live/dev/planned/*.tfplan.tar") + fixtures.check(len(artifacts) == 1, "The CI plan did not store its artifact: " + str(fs.glob(store + "/live/dev/planned/*"))) + deployed = atmos_in(root, ["terraform", "deploy", "planned", "-s", STACK, "--ci"]) + output = hardening.output_of(deployed) + fixtures.check("Apply complete! Resources: 1 added" in output, "deploy did not apply the verified plan:\n" + output) + fixtures.check("without verification" not in output, "deploy applied without verifying the stored plan:\n" + output) + fixtures.check(lifecycle.state_output(root, "planned") == "reviewed|||", "Deployed value differs from the reviewed plan") + ui.success("Deploy: the stored plan of a unit is verified against a fresh plan before it is applied") diff --git a/plugins/terragrunt/scripts/release.star b/plugins/terragrunt/scripts/release.star index 809d79c60c2..a9603443d7e 100644 --- a/plugins/terragrunt/scripts/release.star +++ b/plugins/terragrunt/scripts/release.star @@ -29,9 +29,34 @@ def pack_native_release(work, package): fixtures.run(work, ["plugin", "build", payload]) layout = work + "/release" fixtures.run(work, ["plugin", "pack", payload, "--output", layout]) + verify_registry_links(work, payload, layout, manifest) return struct(layout=layout, version=manifest["metadata"]["version"]) +def release_annotations(layout): + # The index manifest's annotations are what GHCR reads to link a package to its repository. + index = json.decode(fs.read_file(layout + "/index.json")) + digest = index["manifests"][0]["digest"].split(":")[1] + return json.decode(fs.read_file(layout + "/blobs/sha256/" + digest))["annotations"] + + +def verify_registry_links(work, payload, layout, manifest): + # The repository declared in plugin.yaml links the published package; nothing else is implied. + annotations = release_annotations(layout) + metadata = manifest["metadata"] + fixtures.check(annotations["org.opencontainers.image.source"] == metadata["repository"], "The package is not linked to its repository: " + str(annotations)) + fixtures.check(annotations["org.opencontainers.image.version"] == metadata["version"], "Missing version annotation: " + str(annotations)) + fixtures.check(annotations["org.opencontainers.image.title"] == metadata["display_name"], "Missing title annotation: " + str(annotations)) + + # An explicit source overrides the manifest, and a source that could leak credentials is refused. + override = work + "/release-override" + fixtures.run(work, ["plugin", "pack", payload, "--output", override, "--source", "https://github.com/acme/internal-plugins"]) + fixtures.check(release_annotations(override)["org.opencontainers.image.source"] == "https://github.com/acme/internal-plugins", "--source did not override the manifest repository") + refused = fixtures.run_failing(work, ["plugin", "pack", payload, "--output", work + "/release-unsafe", "--source", "https://user:token@github.com/acme/internal-plugins"]) + fixtures.check("without credentials" in refused.stdout + refused.stderr, "A source with credentials must be refused with an explanation:\n" + refused.stderr) + fixtures.check(not fs.exists(work + "/release-unsafe"), "A refused pack left a layout behind") + + def install_and_discover(work, package, release): project = work + "/project" fixtures.copy_tree(package + "/fixtures/explicit-stack", project) diff --git a/plugins/terragrunt/scripts/values_logging.star b/plugins/terragrunt/scripts/values_logging.star new file mode 100644 index 00000000000..5dc3ef59128 --- /dev/null +++ b/plugins/terragrunt/scripts/values_logging.star @@ -0,0 +1,224 @@ +# Opt-in CLI acceptance tests for how native Terragrunt units exchange values and messages with Atmos: +# exact input values and sensitive inputs, Terragrunt's own log events shown through the Atmos logger, +# warnings shown once per command, and the AWS identity that functions such as get_aws_account_id() +# use. Every fixture is generated here, uses only built-in Terraform behavior with local state, and never +# touches a cloud: the AWS scenarios end at an unreachable STS endpoint, and the successful STS exchange +# is covered by Go tests against an STS test server. +# +# Importing this module has no effects; each integration step calls one scenario function. +fixtures = module.load("fixtures.star") +lifecycle = module.load("lifecycle_extended.star") +semantics = module.load("semantics.star") + +STACK = lifecycle.STACK +SECRET = "not-a-real-password" +BIG = "9007199254740993" +UNREACHABLE_STS = "http://127.0.0.1:1" + +VALUES_MODULE = """ +variable "large" { + type = number +} +variable "ratio" { + type = number +} +variable "items" { + type = any +} +variable "nothing" { + type = any + default = "unset" +} +variable "object" { + type = any +} +variable "password" { + type = string + sensitive = true +} +output "large" { + value = var.large +} +output "ratio" { + value = var.ratio +} +output "items" { + value = var.items +} +output "nothing" { + value = var.nothing +} +output "object" { + value = var.object +} +output "password_length" { + value = nonsensitive(length(var.password)) +} +# The variable file Atmos wrote beside the module, exactly as OpenTofu read it. +output "varfile" { + value = join("", [for f in fileset(path.module, "atmos-*.terraform.tfvars.json") : file("${path.module}/${f}")]) +} +""" + +VALUES_UNIT = """ +terraform { + source = "../../../modules/values" +} + +locals { + password = sensitive("@SECRET@") +} + +inputs = { + large = @BIG@ + ratio = 0.1 + items = ["a", 2, null] + nothing = null + object = { name = "x", count = 3 } + password = local.password +} +""" + +PLAIN_ENCRYPTION_UNIT = """ +terraform { + source = "../../../modules/values" +} + +remote_state { + backend = "local" + config = { path = "${get_terragrunt_dir()}/state/terraform.tfstate" } + encryption = { key_provider = "pbkdf2", passphrase = "correct-horse-battery-staple" } +} + +inputs = { + large = 1 + ratio = 1 + items = [] + object = {} + password = "x" +} +""" + +AWS_UNIT = """ +terraform { + source = "../../../modules/values" +} + +inputs = { + large = 1 + ratio = 1 + items = [] + object = {} + password = get_aws_account_id() +} +""" + + +def project(prefix): + root = semantics.new_project(prefix) + fixtures.write(root, "modules/values/main.tf", VALUES_MODULE) + return root + + +def combined(result): + return result.stdout + result.stderr + + +def values(): + root = project("atmos-terragrunt-values-") + lifecycle.write_unit(root, "values", VALUES_UNIT.replace("@SECRET@", SECRET).replace("@BIG@", BIG)) + + # Trace logging is the most any command can reveal: the secret must stay out of it, and the plan and apply + # must still succeed, so the sensitive input reaches OpenTofu even though it never touches a variable file. + planned = semantics.terraform(root, "plan", "values", flags=["--logs-level=Trace"]) + semantics.expect_absent(planned, SECRET, "trace plan") + applied = semantics.terraform(root, "apply", "values", ["-auto-approve"], flags=["--logs-level=Trace"]) + semantics.expect_absent(applied, SECRET, "trace apply") + + # What Terraform recorded, read from the state file rather than from any Atmos function under test. + state_text = fs.read_file(lifecycle.state_path(root, "values")) + fixtures.check('"value": ' + BIG in state_text, "A number beyond float64 precision did not survive into the state:\n" + state_text) + outputs = json.decode(state_text)["outputs"] + fixtures.check(outputs["large"]["value"] == int(BIG), "Exact integer lost: " + str(outputs["large"])) + fixtures.check(outputs["ratio"]["value"] == 0.1, "Decimal lost: " + str(outputs["ratio"])) + fixtures.check(outputs["items"]["value"] == ["a", 2, None], "List or null changed: " + str(outputs["items"])) + # A null input stays null instead of falling back to the variable default; Terraform does not record null outputs. + fixtures.check("nothing" not in outputs or outputs["nothing"]["value"] == None, "A null input became a value: " + str(outputs.get("nothing"))) + fixtures.check(outputs["object"]["value"] == {"name": "x", "count": 3}, "Object changed: " + str(outputs["object"])) + fixtures.check(outputs["password_length"]["value"] == len(SECRET), "The sensitive input did not reach OpenTofu: " + str(outputs["password_length"])) + + # The variable file Atmos wrote for OpenTofu keeps the exact number and leaves the secret out of the file, + # exactly like a secret: it reached OpenTofu through the environment, as the password length above proves. + written = outputs["varfile"]["value"] + fixtures.check(BIG in written, "The variable file lost the exact number:\n" + written) + fixtures.check(SECRET not in written, "A sensitive input was written to the variable file:\n" + written) + fixtures.check('"password"' not in written, "A sensitive input was written to the variable file:\n" + written) + + # Description and listing never reveal the value. + for command in (["describe", "component", "values", "-s", STACK], ["list", "instances", "--format=json"]): + semantics.expect_absent(semantics.run(root, command), SECRET, " ".join(command)) + ui.success("Values: exact numbers, null, and shapes survive into OpenTofu; a sensitive input is masked, kept out of the variable file, and still applied") + + +def logging(): + root = project("atmos-terragrunt-logging-") + lifecycle.write_unit(root, "values", VALUES_UNIT.replace("@SECRET@", SECRET).replace("@BIG@", BIG)) + + # At the default level Terragrunt's own events stay hidden. + quiet = semantics.terraform(root, "plan", "values") + semantics.expect_absent(quiet, "plugin=terragrunt", "default log level") + + # At Debug they appear through the Atmos logger, scoped to the component and stack, on stderr only. + for level in ("Debug", "Trace"): + loud = semantics.terraform(root, "plan", "values", flags=["--logs-level=" + level]) + for text in ("plugin=terragrunt", "component=values", "stack=" + STACK): + semantics.expect(loud, text, level + " log level") + fixtures.check("plugin=terragrunt" not in loud.stdout, level + " put Terragrunt log events on the data channel:\n" + loud.stdout) + semantics.expect_absent(loud, SECRET, level + " log level") + + # A failing unit keeps its error, its exit code, and now also the events that preceded the failure. + lifecycle.write_unit(root, "broken", 'terraform {\n source = "../../../modules/values"\n}\ninputs = { broken = local.absent }\n') + failed = semantics.terraform(root, "plan", "broken", failing=True, flags=["--logs-level=Debug"]) + semantics.expect(failed, "plugin=terragrunt", "debug log of a failing unit") + hidden = semantics.terraform(root, "plan", "broken", failing=True) + semantics.expect_absent(hidden, "plugin=terragrunt", "default log level of a failing unit") + fixtures.check(hidden.exit_code == failed.exit_code, "The log level changed the exit code") + ui.success("Logging: Terragrunt events are hidden by default, shown scoped and masked at Debug and Trace, and never change the outcome") + + +def warnings_once(): + root = project("atmos-terragrunt-warnings-") + fixtures.write(root, "live/dev/plain/terragrunt.hcl", PLAIN_ENCRYPTION_UNIT) + + # One command prepares the unit several times; the warning about it is shown once. + applied = semantics.terraform(root, "apply", "plain", ["-auto-approve"]) + lifecycle.expect_count(combined(applied), "no effect without remote_state.generate", 1, "apply output") + ui.success("Warnings: a warning about a unit is shown once per command") + + +def aws_identity(): + root = project("atmos-terragrunt-aws-") + lifecycle.write_unit(root, "account", AWS_UNIT) + work = fixtures.workspace("atmos-terragrunt-aws-files-") + fixtures.write(work, "credentials", "[atmos-identity]\naws_access_key_id = AKIAINVOCATIONONLY\naws_secret_access_key = invocation-only-secret\n") + fixtures.write(work, "config", "") + identity = { + "AWS_PROFILE": "atmos-identity", "AWS_SHARED_CREDENTIALS_FILE": work + "/credentials", "AWS_CONFIG_FILE": work + "/config", + "AWS_ENDPOINT_URL_STS": UNREACHABLE_STS, "AWS_REGION": "us-east-1", "AWS_EC2_METADATA_DISABLED": "true", + } + + # get_aws_account_id() signs an STS request with the profile that the environment selects and sends it to the + # configured endpoint. Nothing listens there, so the failure is the connection, which proves the request was + # attempted with resolved credentials; credentials that were not found would fail before any connection. + failed = semantics.terraform(root, "plan", "account", flags=["--logs-level=Debug"], env=identity, failing=True) + semantics.expect(failed, "127.0.0.1:1", "STS request of the selected profile") + semantics.expect_absent(failed, "could not be resolved", "STS request of the selected profile") + semantics.expect_absent(failed, "AKIAINVOCATIONONLY", "STS request of the selected profile") + + # A profile that does not exist is named instead of falling back to other credentials. + missing = dict(identity) + missing["AWS_PROFILE"] = "no-such-profile" + unresolved = semantics.terraform(root, "plan", "account", flags=["--logs-level=Debug"], env=missing, failing=True) + semantics.expect(unresolved, "no-such-profile", "unresolvable profile") + semantics.expect(unresolved, "invocation environment", "unresolvable profile") + ui.success("AWS identity: functions in a unit use the profile, files, and endpoint of the invocation, and name what is missing") diff --git a/proto/atmos/plugin/v1/plugin.proto b/proto/atmos/plugin/v1/plugin.proto index 09905c09df1..7be981c484a 100644 --- a/proto/atmos/plugin/v1/plugin.proto +++ b/proto/atmos/plugin/v1/plugin.proto @@ -19,6 +19,11 @@ message Invocation { string component = 7; string component_type = 8; bool interactive = 9; + // The host's effective log level: "trace", "debug", "info", "warn", "error", or "off". Engine log events + // are diagnostic chatter, so a plugin returns LogEntry messages only for "debug" and "trace" and none + // for any other level, including the Atmos default "warn". Anything the user must act on belongs in a + // Diagnostic or an ErrorDetail instead. The host filters entries by its level as well. + string log_level = 10; } message Credentials { @@ -83,6 +88,33 @@ message SourceLocation { uint32 column = 3; } +// LogLevel is the severity of a LogEntry, from most to least verbose. +enum LogLevel { + LOG_LEVEL_UNSPECIFIED = 0; + LOG_LEVEL_TRACE = 1; + LOG_LEVEL_DEBUG = 2; + LOG_LEVEL_INFO = 3; + LOG_LEVEL_WARN = 4; + LOG_LEVEL_ERROR = 5; +} + +// LogEntry is one structured log event from a plugin's engine, for example a Terragrunt logger event. +// A response carries the entries produced while it was computed, in order. The host renders them through +// the Atmos logger on the UI channel (stderr), scoped to the component and stack of the call, with secret +// masking, at the level each entry carries. They are hidden at the Atmos default level and shown with +// --logs-level=Debug or Trace. Entries never change the outcome of the call and are never written to the +// data channel. +// A plugin must not put evaluated values in message or fields; the host masks them anyway. +message LogEntry { + LogLevel level = 1; + string message = 2; + // Structured fields of the event, rendered as key/value pairs. + map fields = 3; + google.protobuf.Timestamp time = 4; + // Unit the event is about, relative to the project root, when the engine reports one. + string unit = 5; +} + // ErrorDetail is the structured, user-facing description of a plugin failure. // A plugin returns it as a gRPC status detail (google.rpc.Status.details) on a // failed call, or inside Diagnostic.detail for a per-item failure that must not @@ -117,6 +149,10 @@ message ErrorDetail { string operation = 10; // Severity of the problem. Unset means ERROR. Severity severity = 11; + // Log entries produced before the failure, in order. Only a failed call's status detail carries them, + // so that Debug and Trace output explains the failure. The host renders them like LogEntry messages + // of a successful response. + repeated LogEntry logs = 12; } // Severity classifies an ErrorDetail. A WARNING never fails a command: the host @@ -275,6 +311,8 @@ message DiscoverComponentsResponse { // reported only to commands that target that component; others keep working. // A diagnostic without a unit is a project-level failure. repeated Diagnostic diagnostics = 2; + // Engine log events produced while discovering. See LogEntry. + repeated LogEntry logs = 3; } service ComponentDiscovery { rpc Discover(DiscoverComponentsRequest) returns (DiscoverComponentsResponse); @@ -343,6 +381,11 @@ message PrepareComponentResponse { string engine = 1; string working_directory = 2; string module_source = 3; + // The evaluated variables of the unit, an object. Numbers keep their exact decimal value, null and + // empty collections are preserved, and the value is wholly known: an unknown value is a plugin bug and + // the host rejects it naming the input. sensitive_paths mark every input path the unit declared + // sensitive. The host masks those values in all output and logs and keeps them out of variable files, + // exactly like secrets. ComponentValue inputs = 4; ComponentStateIdentity state = 5; repeated ComponentGeneratedFile files = 6; @@ -357,24 +400,32 @@ message PrepareComponentResponse { // its value, for provenance reporting. Missing entries mean unknown origin. map input_origins = 12; - // Fields 13-18 are reserved for Terragrunt parity. The host does not read - // them yet; a plugin that cannot honor a setting must reject it with an - // ErrorDetail instead of returning it, and must leave these fields unset. - // Engine executable selected by terraform_binary. + // Fields 13-18 carry Terragrunt settings that decide how the host runs the unit. The host reads + // 13 to 17. A plugin that cannot honor a setting must reject it with an ErrorDetail instead of + // returning a value the host would silently ignore. + // Engine executable selected by terraform_binary. Empty means the engine of the component. string terraform_binary = 13; - // errors block: retry and ignore policies. + // errors block: retry and ignore policies. The host applies them around the engine subprocess. ComponentErrorsConfiguration errors = 14; - // exclude block: conditional unit exclusion. + // exclude block, set only when its condition holds and it applies to the current operation. + // The host skips the operation for the component and runs nothing. See ComponentExclude. ComponentExclude exclude = 15; // iam_role, iam_assume_role_session_name, iam_assume_role_duration, iam_web_identity_token. + // The host assumes the role, never the plugin. ComponentIam iam = 16; - // encryption block as opaque, provider-defined data. + // encryption block as opaque, provider-defined data (state and plan encryption settings). ComponentValue encryption = 17; - // feature flag name to its evaluated value rendered as a string. + // Feature flag name to its evaluated value rendered as a string. Informational: the plugin has + // already applied the flags while evaluating the unit, so they are reflected in every other field. + // The host keeps them with the prepared configuration for display and no host behavior depends on + // them. A plugin may leave this field unset. map feature_flags = 18; + // Engine log events produced while preparing. See LogEntry. + repeated LogEntry logs = 19; } -// ComponentErrorsConfiguration mirrors the Terragrunt errors block. Reserved; not implemented. +// ComponentErrorsConfiguration mirrors the Terragrunt errors block. The host retries or ignores a failed +// engine command according to these policies, in declaration order. message ComponentErrorsConfiguration { repeated ComponentRetryPolicy retry = 1; repeated ComponentIgnorePolicy ignore = 2; @@ -394,15 +445,19 @@ message ComponentIgnorePolicy { // Extra signals written for the caller, keyed by name. map signals = 4; } -// ComponentExclude mirrors the Terragrunt exclude block. Reserved; not implemented. +// ComponentExclude mirrors the Terragrunt exclude block for the operation being prepared. It does not +// carry no_run: the plugin applies no_run itself. The plugin sets the PrepareComponentResponse.exclude +// field only when the host must not run the command, and then actions equals that command. A response +// without the field means run the command. exclude_dependencies is informational for the host's graph. message ComponentExclude { - // Evaluated "if" condition. + // Evaluated "if" condition. The host skips the operation when it is true and the field is set. bool condition = 1; // Commands the exclusion applies to; "all" and "all_except_output" are plugin vocabulary. repeated string actions = 2; bool exclude_dependencies = 3; } -// ComponentIam mirrors the Terragrunt IAM settings. Reserved; not implemented. +// ComponentIam mirrors the Terragrunt IAM settings. The host assumes the role for the unit's commands, on +// top of the credentials of the invocation, unless an Atmos identity is selected explicitly. // The web identity token is a secret and must be carried as a sensitive value. message ComponentIam { string role = 1; @@ -420,6 +475,8 @@ message ResolveComponentStateResponse { ComponentStateIdentity state = 1; repeated ComponentSource sources = 2; repeated Diagnostic diagnostics = 3; + // Engine log events produced while resolving. See LogEntry. + repeated LogEntry logs = 4; } // Resolve backend identity without preparing a component, running hooks, // writing generated files, or reading unrelated dependency outputs. diff --git a/sdk/component/failure.go b/sdk/component/failure.go index 26734d2db4d..d8e5374c11c 100644 --- a/sdk/component/failure.go +++ b/sdk/component/failure.go @@ -76,6 +76,15 @@ func (f *Failure) Warning() *Failure { return f } +// Logs attaches the log events produced before the failure, in order. The host renders them at the +// Atmos log level, so Debug and Trace output explains the failure. +// +//nolint:lintroller // Pure SDK helper; the standalone SDK cannot import host perf tracking. +func (f *Failure) Logs(entries []*pluginv1.LogEntry) *Failure { + f.detail.Logs = entries + return f +} + // Proto returns an independent copy of the wire form. func (f *Failure) Proto() *pluginv1.ErrorDetail { return proto.Clone(f.detail).(*pluginv1.ErrorDetail) diff --git a/sdk/component/failure_test.go b/sdk/component/failure_test.go index 96e402ebf54..3b87ef57b6e 100644 --- a/sdk/component/failure_test.go +++ b/sdk/component/failure_test.go @@ -81,3 +81,21 @@ func TestFailureProtoIsIndependent(t *testing.T) { t.Fatalf("copy aliases the builder: %v", second) } } + +func TestFailureCarriesLogsThroughTheStatus(t *testing.T) { + t.Parallel() + logs := []*pluginv1.LogEntry{ + {Level: pluginv1.LogLevel_LOG_LEVEL_DEBUG, Message: "first", Fields: map[string]string{"k": "v"}}, + {Level: pluginv1.LogLevel_LOG_LEVEL_ERROR, Message: "last", Unit: "live/dev/app"}, + } + + err := component.NewFailure("c", "s").Logs(logs).Err(codes.InvalidArgument) + + detail, ok := component.FailureDetail(err) + if !ok || len(detail.Logs) != 2 { + t.Fatalf("logs lost: %v", detail) + } + if detail.Logs[0].Message != "first" || detail.Logs[0].Fields["k"] != "v" || detail.Logs[1].Message != "last" || detail.Logs[1].Unit != "live/dev/app" { + t.Fatalf("logs corrupted: %v", detail.Logs) + } +} diff --git a/sdk/proto/atmos/plugin/v1/plugin.pb.go b/sdk/proto/atmos/plugin/v1/plugin.pb.go index b4b5f535362..001d7def3a9 100644 --- a/sdk/proto/atmos/plugin/v1/plugin.pb.go +++ b/sdk/proto/atmos/plugin/v1/plugin.pb.go @@ -25,6 +25,65 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// LogLevel is the severity of a LogEntry, from most to least verbose. +type LogLevel int32 + +const ( + LogLevel_LOG_LEVEL_UNSPECIFIED LogLevel = 0 + LogLevel_LOG_LEVEL_TRACE LogLevel = 1 + LogLevel_LOG_LEVEL_DEBUG LogLevel = 2 + LogLevel_LOG_LEVEL_INFO LogLevel = 3 + LogLevel_LOG_LEVEL_WARN LogLevel = 4 + LogLevel_LOG_LEVEL_ERROR LogLevel = 5 +) + +// Enum value maps for LogLevel. +var ( + LogLevel_name = map[int32]string{ + 0: "LOG_LEVEL_UNSPECIFIED", + 1: "LOG_LEVEL_TRACE", + 2: "LOG_LEVEL_DEBUG", + 3: "LOG_LEVEL_INFO", + 4: "LOG_LEVEL_WARN", + 5: "LOG_LEVEL_ERROR", + } + LogLevel_value = map[string]int32{ + "LOG_LEVEL_UNSPECIFIED": 0, + "LOG_LEVEL_TRACE": 1, + "LOG_LEVEL_DEBUG": 2, + "LOG_LEVEL_INFO": 3, + "LOG_LEVEL_WARN": 4, + "LOG_LEVEL_ERROR": 5, + } +) + +func (x LogLevel) Enum() *LogLevel { + p := new(LogLevel) + *p = x + return p +} + +func (x LogLevel) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (LogLevel) Descriptor() protoreflect.EnumDescriptor { + return file_atmos_plugin_v1_plugin_proto_enumTypes[0].Descriptor() +} + +func (LogLevel) Type() protoreflect.EnumType { + return &file_atmos_plugin_v1_plugin_proto_enumTypes[0] +} + +func (x LogLevel) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use LogLevel.Descriptor instead. +func (LogLevel) EnumDescriptor() ([]byte, []int) { + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} +} + // Severity classifies an ErrorDetail. A WARNING never fails a command: the host // prints it on the UI channel and continues. An ERROR fails the commands that // target the named unit, or the whole command when no unit is named. @@ -61,11 +120,11 @@ func (x Severity) String() string { } func (Severity) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[0].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[1].Descriptor() } func (Severity) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[0] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[1] } func (x Severity) Number() protoreflect.EnumNumber { @@ -74,7 +133,7 @@ func (x Severity) Number() protoreflect.EnumNumber { // Deprecated: Use Severity.Descriptor instead. func (Severity) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{1} } type ComponentSource_Kind int32 @@ -113,11 +172,11 @@ func (x ComponentSource_Kind) String() string { } func (ComponentSource_Kind) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[1].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[2].Descriptor() } func (ComponentSource_Kind) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[1] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[2] } func (x ComponentSource_Kind) Number() protoreflect.EnumNumber { @@ -126,7 +185,7 @@ func (x ComponentSource_Kind) Number() protoreflect.EnumNumber { // Deprecated: Use ComponentSource_Kind.Descriptor instead. func (ComponentSource_Kind) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32, 0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33, 0} } type ComponentDependency_Kind int32 @@ -162,11 +221,11 @@ func (x ComponentDependency_Kind) String() string { } func (ComponentDependency_Kind) Descriptor() protoreflect.EnumDescriptor { - return file_atmos_plugin_v1_plugin_proto_enumTypes[2].Descriptor() + return file_atmos_plugin_v1_plugin_proto_enumTypes[3].Descriptor() } func (ComponentDependency_Kind) Type() protoreflect.EnumType { - return &file_atmos_plugin_v1_plugin_proto_enumTypes[2] + return &file_atmos_plugin_v1_plugin_proto_enumTypes[3] } func (x ComponentDependency_Kind) Number() protoreflect.EnumNumber { @@ -175,7 +234,7 @@ func (x ComponentDependency_Kind) Number() protoreflect.EnumNumber { // Deprecated: Use ComponentDependency_Kind.Descriptor instead. func (ComponentDependency_Kind) EnumDescriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33, 0} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34, 0} } // Invocation identifies the live call authorized to use the Atmos API broker. @@ -190,8 +249,13 @@ type Invocation struct { Component string `protobuf:"bytes,7,opt,name=component,proto3" json:"component,omitempty"` ComponentType string `protobuf:"bytes,8,opt,name=component_type,json=componentType,proto3" json:"component_type,omitempty"` Interactive bool `protobuf:"varint,9,opt,name=interactive,proto3" json:"interactive,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // The host's effective log level: "trace", "debug", "info", "warn", "error", or "off". Engine log events + // are diagnostic chatter, so a plugin returns LogEntry messages only for "debug" and "trace" and none + // for any other level, including the Atmos default "warn". Anything the user must act on belongs in a + // Diagnostic or an ErrorDetail instead. The host filters entries by its level as well. + LogLevel string `protobuf:"bytes,10,opt,name=log_level,json=logLevel,proto3" json:"log_level,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Invocation) Reset() { @@ -287,6 +351,13 @@ func (x *Invocation) GetInteractive() bool { return false } +func (x *Invocation) GetLogLevel() string { + if x != nil { + return x.LogLevel + } + return "" +} + type Credentials struct { state protoimpl.MessageState `protogen:"open.v1"` Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` @@ -1096,6 +1167,91 @@ func (x *SourceLocation) GetColumn() uint32 { return 0 } +// LogEntry is one structured log event from a plugin's engine, for example a Terragrunt logger event. +// A response carries the entries produced while it was computed, in order. The host renders them through +// the Atmos logger on the UI channel (stderr), scoped to the component and stack of the call, with secret +// masking, at the level each entry carries. They are hidden at the Atmos default level and shown with +// --logs-level=Debug or Trace. Entries never change the outcome of the call and are never written to the +// data channel. +// A plugin must not put evaluated values in message or fields; the host masks them anyway. +type LogEntry struct { + state protoimpl.MessageState `protogen:"open.v1"` + Level LogLevel `protobuf:"varint,1,opt,name=level,proto3,enum=atmos.plugin.v1.LogLevel" json:"level,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + // Structured fields of the event, rendered as key/value pairs. + Fields map[string]string `protobuf:"bytes,3,rep,name=fields,proto3" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Time *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=time,proto3" json:"time,omitempty"` + // Unit the event is about, relative to the project root, when the engine reports one. + Unit string `protobuf:"bytes,5,opt,name=unit,proto3" json:"unit,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LogEntry) Reset() { + *x = LogEntry{} + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LogEntry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogEntry) ProtoMessage() {} + +func (x *LogEntry) ProtoReflect() protoreflect.Message { + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LogEntry.ProtoReflect.Descriptor instead. +func (*LogEntry) Descriptor() ([]byte, []int) { + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{13} +} + +func (x *LogEntry) GetLevel() LogLevel { + if x != nil { + return x.Level + } + return LogLevel_LOG_LEVEL_UNSPECIFIED +} + +func (x *LogEntry) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *LogEntry) GetFields() map[string]string { + if x != nil { + return x.Fields + } + return nil +} + +func (x *LogEntry) GetTime() *timestamppb.Timestamp { + if x != nil { + return x.Time + } + return nil +} + +func (x *LogEntry) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + // ErrorDetail is the structured, user-facing description of a plugin failure. // A plugin returns it as a gRPC status detail (google.rpc.Status.details) on a // failed call, or inside Diagnostic.detail for a per-item failure that must not @@ -1130,14 +1286,18 @@ type ErrorDetail struct { // The operation that failed, such as "discover", "prepare", or "validate". Operation string `protobuf:"bytes,10,opt,name=operation,proto3" json:"operation,omitempty"` // Severity of the problem. Unset means ERROR. - Severity Severity `protobuf:"varint,11,opt,name=severity,proto3,enum=atmos.plugin.v1.Severity" json:"severity,omitempty"` + Severity Severity `protobuf:"varint,11,opt,name=severity,proto3,enum=atmos.plugin.v1.Severity" json:"severity,omitempty"` + // Log entries produced before the failure, in order. Only a failed call's status detail carries them, + // so that Debug and Trace output explains the failure. The host renders them like LogEntry messages + // of a successful response. + Logs []*LogEntry `protobuf:"bytes,12,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ErrorDetail) Reset() { *x = ErrorDetail{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1149,7 +1309,7 @@ func (x *ErrorDetail) String() string { func (*ErrorDetail) ProtoMessage() {} func (x *ErrorDetail) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[13] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1162,7 +1322,7 @@ func (x *ErrorDetail) ProtoReflect() protoreflect.Message { // Deprecated: Use ErrorDetail.ProtoReflect.Descriptor instead. func (*ErrorDetail) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{13} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{14} } func (x *ErrorDetail) GetCode() string { @@ -1242,6 +1402,13 @@ func (x *ErrorDetail) GetSeverity() Severity { return Severity_SEVERITY_UNSPECIFIED } +func (x *ErrorDetail) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + // Diagnostic describes one problem. field and message keep their original meaning; // detail adds the structured form and takes precedence when present. type Diagnostic struct { @@ -1255,7 +1422,7 @@ type Diagnostic struct { func (x *Diagnostic) Reset() { *x = Diagnostic{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1267,7 +1434,7 @@ func (x *Diagnostic) String() string { func (*Diagnostic) ProtoMessage() {} func (x *Diagnostic) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[14] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1280,7 +1447,7 @@ func (x *Diagnostic) ProtoReflect() protoreflect.Message { // Deprecated: Use Diagnostic.ProtoReflect.Descriptor instead. func (*Diagnostic) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{14} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{15} } func (x *Diagnostic) GetField() string { @@ -1313,7 +1480,7 @@ type ValidateResponse struct { func (x *ValidateResponse) Reset() { *x = ValidateResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1325,7 +1492,7 @@ func (x *ValidateResponse) String() string { func (*ValidateResponse) ProtoMessage() {} func (x *ValidateResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[15] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1338,7 +1505,7 @@ func (x *ValidateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ValidateResponse.ProtoReflect.Descriptor instead. func (*ValidateResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{15} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{16} } func (x *ValidateResponse) GetDiagnostics() []*Diagnostic { @@ -1358,7 +1525,7 @@ type Unsupported struct { func (x *Unsupported) Reset() { *x = Unsupported{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1370,7 +1537,7 @@ func (x *Unsupported) String() string { func (*Unsupported) ProtoMessage() {} func (x *Unsupported) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[16] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1383,7 +1550,7 @@ func (x *Unsupported) ProtoReflect() protoreflect.Message { // Deprecated: Use Unsupported.ProtoReflect.Descriptor instead. func (*Unsupported) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{16} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{17} } func (x *Unsupported) GetOperation() string { @@ -1410,7 +1577,7 @@ type RefreshRequest struct { func (x *RefreshRequest) Reset() { *x = RefreshRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1422,7 +1589,7 @@ func (x *RefreshRequest) String() string { func (*RefreshRequest) ProtoMessage() {} func (x *RefreshRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[17] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1435,7 +1602,7 @@ func (x *RefreshRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RefreshRequest.ProtoReflect.Descriptor instead. func (*RefreshRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{17} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{18} } func (x *RefreshRequest) GetProvider() *ProviderRequest { @@ -1465,7 +1632,7 @@ type RefreshResponse struct { func (x *RefreshResponse) Reset() { *x = RefreshResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1477,7 +1644,7 @@ func (x *RefreshResponse) String() string { func (*RefreshResponse) ProtoMessage() {} func (x *RefreshResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[18] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1490,7 +1657,7 @@ func (x *RefreshResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RefreshResponse.ProtoReflect.Descriptor instead. func (*RefreshResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{18} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{19} } func (x *RefreshResponse) GetResult() isRefreshResponse_Result { @@ -1543,7 +1710,7 @@ type EnvironmentResponse struct { func (x *EnvironmentResponse) Reset() { *x = EnvironmentResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1555,7 +1722,7 @@ func (x *EnvironmentResponse) String() string { func (*EnvironmentResponse) ProtoMessage() {} func (x *EnvironmentResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[19] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1568,7 +1735,7 @@ func (x *EnvironmentResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EnvironmentResponse.ProtoReflect.Descriptor instead. func (*EnvironmentResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{19} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{20} } func (x *EnvironmentResponse) GetEnvironment() map[string]string { @@ -1588,7 +1755,7 @@ type PrepareEnvironmentRequest struct { func (x *PrepareEnvironmentRequest) Reset() { *x = PrepareEnvironmentRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1600,7 +1767,7 @@ func (x *PrepareEnvironmentRequest) String() string { func (*PrepareEnvironmentRequest) ProtoMessage() {} func (x *PrepareEnvironmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[20] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1613,7 +1780,7 @@ func (x *PrepareEnvironmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PrepareEnvironmentRequest.ProtoReflect.Descriptor instead. func (*PrepareEnvironmentRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{20} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{21} } func (x *PrepareEnvironmentRequest) GetProvider() *ProviderRequest { @@ -1642,7 +1809,7 @@ type CredentialPath struct { func (x *CredentialPath) Reset() { *x = CredentialPath{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1654,7 +1821,7 @@ func (x *CredentialPath) String() string { func (*CredentialPath) ProtoMessage() {} func (x *CredentialPath) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[21] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1667,7 +1834,7 @@ func (x *CredentialPath) ProtoReflect() protoreflect.Message { // Deprecated: Use CredentialPath.ProtoReflect.Descriptor instead. func (*CredentialPath) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{21} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{22} } func (x *CredentialPath) GetLocation() string { @@ -1707,7 +1874,7 @@ type PathsResponse struct { func (x *PathsResponse) Reset() { *x = PathsResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1719,7 +1886,7 @@ func (x *PathsResponse) String() string { func (*PathsResponse) ProtoMessage() {} func (x *PathsResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[22] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1732,7 +1899,7 @@ func (x *PathsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PathsResponse.ProtoReflect.Descriptor instead. func (*PathsResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{22} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{23} } func (x *PathsResponse) GetPaths() []*CredentialPath { @@ -1752,7 +1919,7 @@ type IdentityAuthenticateRequest struct { func (x *IdentityAuthenticateRequest) Reset() { *x = IdentityAuthenticateRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1764,7 +1931,7 @@ func (x *IdentityAuthenticateRequest) String() string { func (*IdentityAuthenticateRequest) ProtoMessage() {} func (x *IdentityAuthenticateRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[23] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1777,7 +1944,7 @@ func (x *IdentityAuthenticateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use IdentityAuthenticateRequest.ProtoReflect.Descriptor instead. func (*IdentityAuthenticateRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{23} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{24} } func (x *IdentityAuthenticateRequest) GetIdentity() *IdentityRequest { @@ -1804,7 +1971,7 @@ type IdentityPrepareRequest struct { func (x *IdentityPrepareRequest) Reset() { *x = IdentityPrepareRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1816,7 +1983,7 @@ func (x *IdentityPrepareRequest) String() string { func (*IdentityPrepareRequest) ProtoMessage() {} func (x *IdentityPrepareRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[24] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1829,7 +1996,7 @@ func (x *IdentityPrepareRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use IdentityPrepareRequest.ProtoReflect.Descriptor instead. func (*IdentityPrepareRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{24} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{25} } func (x *IdentityPrepareRequest) GetIdentity() *IdentityRequest { @@ -1859,7 +2026,7 @@ type CommandRequest struct { func (x *CommandRequest) Reset() { *x = CommandRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1871,7 +2038,7 @@ func (x *CommandRequest) String() string { func (*CommandRequest) ProtoMessage() {} func (x *CommandRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[25] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1884,7 +2051,7 @@ func (x *CommandRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead. func (*CommandRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{25} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{26} } func (x *CommandRequest) GetInvocation() *Invocation { @@ -1924,7 +2091,7 @@ type CommandExit struct { func (x *CommandExit) Reset() { *x = CommandExit{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1936,7 +2103,7 @@ func (x *CommandExit) String() string { func (*CommandExit) ProtoMessage() {} func (x *CommandExit) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[26] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1949,7 +2116,7 @@ func (x *CommandExit) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandExit.ProtoReflect.Descriptor instead. func (*CommandExit) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{26} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{27} } func (x *CommandExit) GetCode() uint32 { @@ -1973,7 +2140,7 @@ type CommandEvent struct { func (x *CommandEvent) Reset() { *x = CommandEvent{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1985,7 +2152,7 @@ func (x *CommandEvent) String() string { func (*CommandEvent) ProtoMessage() {} func (x *CommandEvent) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[27] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1998,7 +2165,7 @@ func (x *CommandEvent) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandEvent.ProtoReflect.Descriptor instead. func (*CommandEvent) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{27} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{28} } func (x *CommandEvent) GetEvent() isCommandEvent_Event { @@ -2072,7 +2239,7 @@ type ComponentValue struct { func (x *ComponentValue) Reset() { *x = ComponentValue{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2084,7 +2251,7 @@ func (x *ComponentValue) String() string { func (*ComponentValue) ProtoMessage() {} func (x *ComponentValue) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[28] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2097,7 +2264,7 @@ func (x *ComponentValue) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValue.ProtoReflect.Descriptor instead. func (*ComponentValue) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{28} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{29} } func (x *ComponentValue) GetTypeJson() []byte { @@ -2130,7 +2297,7 @@ type ComponentValuePath struct { func (x *ComponentValuePath) Reset() { *x = ComponentValuePath{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2142,7 +2309,7 @@ func (x *ComponentValuePath) String() string { func (*ComponentValuePath) ProtoMessage() {} func (x *ComponentValuePath) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[29] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2155,7 +2322,7 @@ func (x *ComponentValuePath) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValuePath.ProtoReflect.Descriptor instead. func (*ComponentValuePath) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{29} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{30} } func (x *ComponentValuePath) GetSteps() []*ComponentValueStep { @@ -2178,7 +2345,7 @@ type ComponentValueStep struct { func (x *ComponentValueStep) Reset() { *x = ComponentValueStep{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2190,7 +2357,7 @@ func (x *ComponentValueStep) String() string { func (*ComponentValueStep) ProtoMessage() {} func (x *ComponentValueStep) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[30] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2203,7 +2370,7 @@ func (x *ComponentValueStep) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentValueStep.ProtoReflect.Descriptor instead. func (*ComponentValueStep) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{30} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{31} } func (x *ComponentValueStep) GetSelector() isComponentValueStep_Selector { @@ -2260,7 +2427,7 @@ type ComponentAddress struct { func (x *ComponentAddress) Reset() { *x = ComponentAddress{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2272,7 +2439,7 @@ func (x *ComponentAddress) String() string { func (*ComponentAddress) ProtoMessage() {} func (x *ComponentAddress) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[31] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2285,7 +2452,7 @@ func (x *ComponentAddress) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentAddress.ProtoReflect.Descriptor instead. func (*ComponentAddress) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{31} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32} } func (x *ComponentAddress) GetStack() string { @@ -2322,7 +2489,7 @@ type ComponentSource struct { func (x *ComponentSource) Reset() { *x = ComponentSource{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2334,7 +2501,7 @@ func (x *ComponentSource) String() string { func (*ComponentSource) ProtoMessage() {} func (x *ComponentSource) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[32] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2347,7 +2514,7 @@ func (x *ComponentSource) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentSource.ProtoReflect.Descriptor instead. func (*ComponentSource) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{32} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33} } func (x *ComponentSource) GetPath() string { @@ -2381,7 +2548,7 @@ type ComponentDependency struct { func (x *ComponentDependency) Reset() { *x = ComponentDependency{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2393,7 +2560,7 @@ func (x *ComponentDependency) String() string { func (*ComponentDependency) ProtoMessage() {} func (x *ComponentDependency) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[33] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2406,7 +2573,7 @@ func (x *ComponentDependency) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentDependency.ProtoReflect.Descriptor instead. func (*ComponentDependency) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{33} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34} } func (x *ComponentDependency) GetTarget() *ComponentAddress { @@ -2438,7 +2605,7 @@ type DiscoveredComponent struct { func (x *DiscoveredComponent) Reset() { *x = DiscoveredComponent{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2450,7 +2617,7 @@ func (x *DiscoveredComponent) String() string { func (*DiscoveredComponent) ProtoMessage() {} func (x *DiscoveredComponent) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[34] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2463,7 +2630,7 @@ func (x *DiscoveredComponent) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoveredComponent.ProtoReflect.Descriptor instead. func (*DiscoveredComponent) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{34} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{35} } func (x *DiscoveredComponent) GetAddress() *ComponentAddress { @@ -2530,7 +2697,7 @@ type ComponentEffects struct { func (x *ComponentEffects) Reset() { *x = ComponentEffects{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2542,7 +2709,7 @@ func (x *ComponentEffects) String() string { func (*ComponentEffects) ProtoMessage() {} func (x *ComponentEffects) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[35] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2555,7 +2722,7 @@ func (x *ComponentEffects) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentEffects.ProtoReflect.Descriptor instead. func (*ComponentEffects) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{35} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{36} } func (x *ComponentEffects) GetCommands() bool { @@ -2610,7 +2777,7 @@ type ComponentOperation struct { func (x *ComponentOperation) Reset() { *x = ComponentOperation{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2622,7 +2789,7 @@ func (x *ComponentOperation) String() string { func (*ComponentOperation) ProtoMessage() {} func (x *ComponentOperation) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[36] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2635,7 +2802,7 @@ func (x *ComponentOperation) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentOperation.ProtoReflect.Descriptor instead. func (*ComponentOperation) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{36} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{37} } func (x *ComponentOperation) GetCommand() string { @@ -2686,7 +2853,7 @@ type DiscoverComponentsRequest struct { func (x *DiscoverComponentsRequest) Reset() { *x = DiscoverComponentsRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2698,7 +2865,7 @@ func (x *DiscoverComponentsRequest) String() string { func (*DiscoverComponentsRequest) ProtoMessage() {} func (x *DiscoverComponentsRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[37] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2711,7 +2878,7 @@ func (x *DiscoverComponentsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoverComponentsRequest.ProtoReflect.Descriptor instead. func (*DiscoverComponentsRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{37} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{38} } func (x *DiscoverComponentsRequest) GetInvocation() *Invocation { @@ -2791,14 +2958,16 @@ type DiscoverComponentsResponse struct { // Per-component failures. A diagnostic whose detail names a unit and stack is // reported only to commands that target that component; others keep working. // A diagnostic without a unit is a project-level failure. - Diagnostics []*Diagnostic `protobuf:"bytes,2,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,2,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + // Engine log events produced while discovering. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,3,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *DiscoverComponentsResponse) Reset() { *x = DiscoverComponentsResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2810,7 +2979,7 @@ func (x *DiscoverComponentsResponse) String() string { func (*DiscoverComponentsResponse) ProtoMessage() {} func (x *DiscoverComponentsResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[38] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2823,7 +2992,7 @@ func (x *DiscoverComponentsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DiscoverComponentsResponse.ProtoReflect.Descriptor instead. func (*DiscoverComponentsResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{38} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{39} } func (x *DiscoverComponentsResponse) GetComponents() []*DiscoveredComponent { @@ -2840,6 +3009,13 @@ func (x *DiscoverComponentsResponse) GetDiagnostics() []*Diagnostic { return nil } +func (x *DiscoverComponentsResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + type ComponentRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Invocation *Invocation `protobuf:"bytes,1,opt,name=invocation,proto3" json:"invocation,omitempty"` @@ -2857,7 +3033,7 @@ type ComponentRequest struct { func (x *ComponentRequest) Reset() { *x = ComponentRequest{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2869,7 +3045,7 @@ func (x *ComponentRequest) String() string { func (*ComponentRequest) ProtoMessage() {} func (x *ComponentRequest) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[39] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2882,7 +3058,7 @@ func (x *ComponentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentRequest.ProtoReflect.Descriptor instead. func (*ComponentRequest) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{39} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{40} } func (x *ComponentRequest) GetInvocation() *Invocation { @@ -2962,7 +3138,7 @@ type ComponentStateIdentity struct { func (x *ComponentStateIdentity) Reset() { *x = ComponentStateIdentity{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2974,7 +3150,7 @@ func (x *ComponentStateIdentity) String() string { func (*ComponentStateIdentity) ProtoMessage() {} func (x *ComponentStateIdentity) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[40] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2987,7 +3163,7 @@ func (x *ComponentStateIdentity) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentStateIdentity.ProtoReflect.Descriptor instead. func (*ComponentStateIdentity) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{40} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{41} } func (x *ComponentStateIdentity) GetBackendType() string { @@ -3032,7 +3208,7 @@ type ComponentGeneratedFile struct { func (x *ComponentGeneratedFile) Reset() { *x = ComponentGeneratedFile{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3044,7 +3220,7 @@ func (x *ComponentGeneratedFile) String() string { func (*ComponentGeneratedFile) ProtoMessage() {} func (x *ComponentGeneratedFile) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[41] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3057,7 +3233,7 @@ func (x *ComponentGeneratedFile) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentGeneratedFile.ProtoReflect.Descriptor instead. func (*ComponentGeneratedFile) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{41} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{42} } func (x *ComponentGeneratedFile) GetPath() string { @@ -3102,7 +3278,7 @@ type ComponentExecutionConfiguration struct { func (x *ComponentExecutionConfiguration) Reset() { *x = ComponentExecutionConfiguration{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3114,7 +3290,7 @@ func (x *ComponentExecutionConfiguration) String() string { func (*ComponentExecutionConfiguration) ProtoMessage() {} func (x *ComponentExecutionConfiguration) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[42] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3127,7 +3303,7 @@ func (x *ComponentExecutionConfiguration) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExecutionConfiguration.ProtoReflect.Descriptor instead. func (*ComponentExecutionConfiguration) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{42} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{43} } func (x *ComponentExecutionConfiguration) GetExtraArguments() []*ComponentExtraArguments { @@ -3171,7 +3347,7 @@ type ComponentExtraArguments struct { func (x *ComponentExtraArguments) Reset() { *x = ComponentExtraArguments{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3183,7 +3359,7 @@ func (x *ComponentExtraArguments) String() string { func (*ComponentExtraArguments) ProtoMessage() {} func (x *ComponentExtraArguments) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[43] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3196,7 +3372,7 @@ func (x *ComponentExtraArguments) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExtraArguments.ProtoReflect.Descriptor instead. func (*ComponentExtraArguments) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{43} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{44} } func (x *ComponentExtraArguments) GetCommands() []string { @@ -3251,7 +3427,7 @@ type ComponentHook struct { func (x *ComponentHook) Reset() { *x = ComponentHook{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3263,7 +3439,7 @@ func (x *ComponentHook) String() string { func (*ComponentHook) ProtoMessage() {} func (x *ComponentHook) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[44] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3276,7 +3452,7 @@ func (x *ComponentHook) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentHook.ProtoReflect.Descriptor instead. func (*ComponentHook) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{44} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{45} } func (x *ComponentHook) GetName() string { @@ -3329,16 +3505,21 @@ func (x *ComponentHook) GetOnErrors() []string { } type PrepareComponentResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - Engine string `protobuf:"bytes,1,opt,name=engine,proto3" json:"engine,omitempty"` - WorkingDirectory string `protobuf:"bytes,2,opt,name=working_directory,json=workingDirectory,proto3" json:"working_directory,omitempty"` - ModuleSource string `protobuf:"bytes,3,opt,name=module_source,json=moduleSource,proto3" json:"module_source,omitempty"` - Inputs *ComponentValue `protobuf:"bytes,4,opt,name=inputs,proto3" json:"inputs,omitempty"` - State *ComponentStateIdentity `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty"` - Files []*ComponentGeneratedFile `protobuf:"bytes,6,rep,name=files,proto3" json:"files,omitempty"` - Dependencies []*ComponentDependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` - Sources []*ComponentSource `protobuf:"bytes,8,rep,name=sources,proto3" json:"sources,omitempty"` - Diagnostics []*Diagnostic `protobuf:"bytes,9,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Engine string `protobuf:"bytes,1,opt,name=engine,proto3" json:"engine,omitempty"` + WorkingDirectory string `protobuf:"bytes,2,opt,name=working_directory,json=workingDirectory,proto3" json:"working_directory,omitempty"` + ModuleSource string `protobuf:"bytes,3,opt,name=module_source,json=moduleSource,proto3" json:"module_source,omitempty"` + // The evaluated variables of the unit, an object. Numbers keep their exact decimal value, null and + // empty collections are preserved, and the value is wholly known: an unknown value is a plugin bug and + // the host rejects it naming the input. sensitive_paths mark every input path the unit declared + // sensitive. The host masks those values in all output and logs and keeps them out of variable files, + // exactly like secrets. + Inputs *ComponentValue `protobuf:"bytes,4,opt,name=inputs,proto3" json:"inputs,omitempty"` + State *ComponentStateIdentity `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty"` + Files []*ComponentGeneratedFile `protobuf:"bytes,6,rep,name=files,proto3" json:"files,omitempty"` + Dependencies []*ComponentDependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` + Sources []*ComponentSource `protobuf:"bytes,8,rep,name=sources,proto3" json:"sources,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,9,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` // A returned generated file owns the backend block. The host must not also // emit its default backend file. BackendGenerated bool `protobuf:"varint,10,opt,name=backend_generated,json=backendGenerated,proto3" json:"backend_generated,omitempty"` @@ -3346,28 +3527,35 @@ type PrepareComponentResponse struct { // Maps each input name to the authored file, line, and column that produced // its value, for provenance reporting. Missing entries mean unknown origin. InputOrigins map[string]*SourceLocation `protobuf:"bytes,12,rep,name=input_origins,json=inputOrigins,proto3" json:"input_origins,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - // Fields 13-18 are reserved for Terragrunt parity. The host does not read - // them yet; a plugin that cannot honor a setting must reject it with an - // ErrorDetail instead of returning it, and must leave these fields unset. - // Engine executable selected by terraform_binary. + // Fields 13-18 carry Terragrunt settings that decide how the host runs the unit. The host reads + // 13 to 17. A plugin that cannot honor a setting must reject it with an ErrorDetail instead of + // returning a value the host would silently ignore. + // Engine executable selected by terraform_binary. Empty means the engine of the component. TerraformBinary string `protobuf:"bytes,13,opt,name=terraform_binary,json=terraformBinary,proto3" json:"terraform_binary,omitempty"` - // errors block: retry and ignore policies. + // errors block: retry and ignore policies. The host applies them around the engine subprocess. Errors *ComponentErrorsConfiguration `protobuf:"bytes,14,opt,name=errors,proto3" json:"errors,omitempty"` - // exclude block: conditional unit exclusion. + // exclude block, set only when its condition holds and it applies to the current operation. + // The host skips the operation for the component and runs nothing. See ComponentExclude. Exclude *ComponentExclude `protobuf:"bytes,15,opt,name=exclude,proto3" json:"exclude,omitempty"` // iam_role, iam_assume_role_session_name, iam_assume_role_duration, iam_web_identity_token. + // The host assumes the role, never the plugin. Iam *ComponentIam `protobuf:"bytes,16,opt,name=iam,proto3" json:"iam,omitempty"` - // encryption block as opaque, provider-defined data. + // encryption block as opaque, provider-defined data (state and plan encryption settings). Encryption *ComponentValue `protobuf:"bytes,17,opt,name=encryption,proto3" json:"encryption,omitempty"` - // feature flag name to its evaluated value rendered as a string. - FeatureFlags map[string]string `protobuf:"bytes,18,rep,name=feature_flags,json=featureFlags,proto3" json:"feature_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // Feature flag name to its evaluated value rendered as a string. Informational: the plugin has + // already applied the flags while evaluating the unit, so they are reflected in every other field. + // The host keeps them with the prepared configuration for display and no host behavior depends on + // them. A plugin may leave this field unset. + FeatureFlags map[string]string `protobuf:"bytes,18,rep,name=feature_flags,json=featureFlags,proto3" json:"feature_flags,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // Engine log events produced while preparing. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,19,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *PrepareComponentResponse) Reset() { *x = PrepareComponentResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3379,7 +3567,7 @@ func (x *PrepareComponentResponse) String() string { func (*PrepareComponentResponse) ProtoMessage() {} func (x *PrepareComponentResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[45] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3392,7 +3580,7 @@ func (x *PrepareComponentResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PrepareComponentResponse.ProtoReflect.Descriptor instead. func (*PrepareComponentResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{45} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{46} } func (x *PrepareComponentResponse) GetEngine() string { @@ -3521,7 +3709,15 @@ func (x *PrepareComponentResponse) GetFeatureFlags() map[string]string { return nil } -// ComponentErrorsConfiguration mirrors the Terragrunt errors block. Reserved; not implemented. +func (x *PrepareComponentResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + +// ComponentErrorsConfiguration mirrors the Terragrunt errors block. The host retries or ignores a failed +// engine command according to these policies, in declaration order. type ComponentErrorsConfiguration struct { state protoimpl.MessageState `protogen:"open.v1"` Retry []*ComponentRetryPolicy `protobuf:"bytes,1,rep,name=retry,proto3" json:"retry,omitempty"` @@ -3532,7 +3728,7 @@ type ComponentErrorsConfiguration struct { func (x *ComponentErrorsConfiguration) Reset() { *x = ComponentErrorsConfiguration{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3544,7 +3740,7 @@ func (x *ComponentErrorsConfiguration) String() string { func (*ComponentErrorsConfiguration) ProtoMessage() {} func (x *ComponentErrorsConfiguration) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[46] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3557,7 +3753,7 @@ func (x *ComponentErrorsConfiguration) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentErrorsConfiguration.ProtoReflect.Descriptor instead. func (*ComponentErrorsConfiguration) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{46} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{47} } func (x *ComponentErrorsConfiguration) GetRetry() []*ComponentRetryPolicy { @@ -3587,7 +3783,7 @@ type ComponentRetryPolicy struct { func (x *ComponentRetryPolicy) Reset() { *x = ComponentRetryPolicy{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3599,7 +3795,7 @@ func (x *ComponentRetryPolicy) String() string { func (*ComponentRetryPolicy) ProtoMessage() {} func (x *ComponentRetryPolicy) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[47] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3612,7 +3808,7 @@ func (x *ComponentRetryPolicy) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentRetryPolicy.ProtoReflect.Descriptor instead. func (*ComponentRetryPolicy) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{47} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{48} } func (x *ComponentRetryPolicy) GetName() string { @@ -3657,7 +3853,7 @@ type ComponentIgnorePolicy struct { func (x *ComponentIgnorePolicy) Reset() { *x = ComponentIgnorePolicy{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3669,7 +3865,7 @@ func (x *ComponentIgnorePolicy) String() string { func (*ComponentIgnorePolicy) ProtoMessage() {} func (x *ComponentIgnorePolicy) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[48] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3682,7 +3878,7 @@ func (x *ComponentIgnorePolicy) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentIgnorePolicy.ProtoReflect.Descriptor instead. func (*ComponentIgnorePolicy) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{48} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{49} } func (x *ComponentIgnorePolicy) GetName() string { @@ -3713,10 +3909,13 @@ func (x *ComponentIgnorePolicy) GetSignals() map[string]*ComponentValue { return nil } -// ComponentExclude mirrors the Terragrunt exclude block. Reserved; not implemented. +// ComponentExclude mirrors the Terragrunt exclude block for the operation being prepared. It does not +// carry no_run: the plugin applies no_run itself. The plugin sets the PrepareComponentResponse.exclude +// field only when the host must not run the command, and then actions equals that command. A response +// without the field means run the command. exclude_dependencies is informational for the host's graph. type ComponentExclude struct { state protoimpl.MessageState `protogen:"open.v1"` - // Evaluated "if" condition. + // Evaluated "if" condition. The host skips the operation when it is true and the field is set. Condition bool `protobuf:"varint,1,opt,name=condition,proto3" json:"condition,omitempty"` // Commands the exclusion applies to; "all" and "all_except_output" are plugin vocabulary. Actions []string `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"` @@ -3727,7 +3926,7 @@ type ComponentExclude struct { func (x *ComponentExclude) Reset() { *x = ComponentExclude{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3739,7 +3938,7 @@ func (x *ComponentExclude) String() string { func (*ComponentExclude) ProtoMessage() {} func (x *ComponentExclude) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[49] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3752,7 +3951,7 @@ func (x *ComponentExclude) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentExclude.ProtoReflect.Descriptor instead. func (*ComponentExclude) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{49} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{50} } func (x *ComponentExclude) GetCondition() bool { @@ -3776,7 +3975,8 @@ func (x *ComponentExclude) GetExcludeDependencies() bool { return false } -// ComponentIam mirrors the Terragrunt IAM settings. Reserved; not implemented. +// ComponentIam mirrors the Terragrunt IAM settings. The host assumes the role for the unit's commands, on +// top of the credentials of the invocation, unless an Atmos identity is selected explicitly. // The web identity token is a secret and must be carried as a sensitive value. type ComponentIam struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -3790,7 +3990,7 @@ type ComponentIam struct { func (x *ComponentIam) Reset() { *x = ComponentIam{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3802,7 +4002,7 @@ func (x *ComponentIam) String() string { func (*ComponentIam) ProtoMessage() {} func (x *ComponentIam) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[50] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3815,7 +4015,7 @@ func (x *ComponentIam) ProtoReflect() protoreflect.Message { // Deprecated: Use ComponentIam.ProtoReflect.Descriptor instead. func (*ComponentIam) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{50} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{51} } func (x *ComponentIam) GetRole() string { @@ -3847,17 +4047,19 @@ func (x *ComponentIam) GetWebIdentityToken() *ComponentValue { } type ResolveComponentStateResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - State *ComponentStateIdentity `protobuf:"bytes,1,opt,name=state,proto3" json:"state,omitempty"` - Sources []*ComponentSource `protobuf:"bytes,2,rep,name=sources,proto3" json:"sources,omitempty"` - Diagnostics []*Diagnostic `protobuf:"bytes,3,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + State *ComponentStateIdentity `protobuf:"bytes,1,opt,name=state,proto3" json:"state,omitempty"` + Sources []*ComponentSource `protobuf:"bytes,2,rep,name=sources,proto3" json:"sources,omitempty"` + Diagnostics []*Diagnostic `protobuf:"bytes,3,rep,name=diagnostics,proto3" json:"diagnostics,omitempty"` + // Engine log events produced while resolving. See LogEntry. + Logs []*LogEntry `protobuf:"bytes,4,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ResolveComponentStateResponse) Reset() { *x = ResolveComponentStateResponse{} - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[52] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3869,7 +4071,7 @@ func (x *ResolveComponentStateResponse) String() string { func (*ResolveComponentStateResponse) ProtoMessage() {} func (x *ResolveComponentStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[51] + mi := &file_atmos_plugin_v1_plugin_proto_msgTypes[52] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3882,7 +4084,7 @@ func (x *ResolveComponentStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ResolveComponentStateResponse.ProtoReflect.Descriptor instead. func (*ResolveComponentStateResponse) Descriptor() ([]byte, []int) { - return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{51} + return file_atmos_plugin_v1_plugin_proto_rawDescGZIP(), []int{52} } func (x *ResolveComponentStateResponse) GetState() *ComponentStateIdentity { @@ -3906,11 +4108,18 @@ func (x *ResolveComponentStateResponse) GetDiagnostics() []*Diagnostic { return nil } +func (x *ResolveComponentStateResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + var File_atmos_plugin_v1_plugin_proto protoreflect.FileDescriptor const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\n" + - "\x1catmos/plugin/v1/plugin.proto\x12\x0fatmos.plugin.v1\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xa8\x03\n" + + "\x1catmos/plugin/v1/plugin.proto\x12\x0fatmos.plugin.v1\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xc5\x03\n" + "\n" + "Invocation\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x18\n" + @@ -3921,7 +4130,9 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x05stack\x18\x06 \x01(\tR\x05stack\x12\x1c\n" + "\tcomponent\x18\a \x01(\tR\tcomponent\x12%\n" + "\x0ecomponent_type\x18\b \x01(\tR\rcomponentType\x12 \n" + - "\vinteractive\x18\t \x01(\bR\vinteractive\x1a>\n" + + "\vinteractive\x18\t \x01(\bR\vinteractive\x12\x1b\n" + + "\tlog_level\x18\n" + + " \x01(\tR\blogLevel\x1a>\n" + "\x10EnvironmentEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\xb0\x01\n" + @@ -3993,7 +4204,16 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x0eSourceLocation\x12\x12\n" + "\x04file\x18\x01 \x01(\tR\x04file\x12\x12\n" + "\x04line\x18\x02 \x01(\rR\x04line\x12\x16\n" + - "\x06column\x18\x03 \x01(\rR\x06column\"\xe1\x02\n" + + "\x06column\x18\x03 \x01(\rR\x06column\"\x93\x02\n" + + "\bLogEntry\x12/\n" + + "\x05level\x18\x01 \x01(\x0e2\x19.atmos.plugin.v1.LogLevelR\x05level\x12\x18\n" + + "\amessage\x18\x02 \x01(\tR\amessage\x12=\n" + + "\x06fields\x18\x03 \x03(\v2%.atmos.plugin.v1.LogEntry.FieldsEntryR\x06fields\x12.\n" + + "\x04time\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\x04time\x12\x12\n" + + "\x04unit\x18\x05 \x01(\tR\x04unit\x1a9\n" + + "\vFieldsEntry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x90\x03\n" + "\vErrorDetail\x12\x12\n" + "\x04code\x18\x01 \x01(\tR\x04code\x12\x18\n" + "\asummary\x18\x02 \x01(\tR\asummary\x12\x16\n" + @@ -4007,7 +4227,8 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\tuser_safe\x18\t \x01(\bR\buserSafe\x12\x1c\n" + "\toperation\x18\n" + " \x01(\tR\toperation\x125\n" + - "\bseverity\x18\v \x01(\x0e2\x19.atmos.plugin.v1.SeverityR\bseverity\"r\n" + + "\bseverity\x18\v \x01(\x0e2\x19.atmos.plugin.v1.SeverityR\bseverity\x12-\n" + + "\x04logs\x18\f \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\"r\n" + "\n" + "Diagnostic\x12\x14\n" + "\x05field\x18\x01 \x01(\tR\x05field\x12\x18\n" + @@ -4134,12 +4355,13 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\toperation\x18\b \x01(\v2#.atmos.plugin.v1.ComponentOperationR\toperation\x12;\n" + "\aeffects\x18\t \x01(\v2!.atmos.plugin.v1.ComponentEffectsR\aeffects\x12V\n" + "\x16provider_configuration\x18\n" + - " \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x15providerConfiguration\"\xa1\x01\n" + + " \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x15providerConfiguration\"\xd0\x01\n" + "\x1aDiscoverComponentsResponse\x12D\n" + "\n" + "components\x18\x01 \x03(\v2$.atmos.plugin.v1.DiscoveredComponentR\n" + "components\x12=\n" + - "\vdiagnostics\x18\x02 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\"\x86\x04\n" + + "\vdiagnostics\x18\x02 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\x12-\n" + + "\x04logs\x18\x03 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\"\x86\x04\n" + "\x10ComponentRequest\x12;\n" + "\n" + "invocation\x18\x01 \x01(\v2\x1b.atmos.plugin.v1.InvocationR\n" + @@ -4186,7 +4408,7 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\frun_on_error\x18\x05 \x01(\bR\n" + "runOnError\x12'\n" + "\x0fsuppress_stdout\x18\x06 \x01(\bR\x0esuppressStdout\x12\x1b\n" + - "\ton_errors\x18\a \x03(\tR\bonErrors\"\x85\n" + + "\ton_errors\x18\a \x03(\tR\bonErrors\"\xb4\n" + "\n" + "\x18PrepareComponentResponse\x12\x16\n" + "\x06engine\x18\x01 \x01(\tR\x06engine\x12+\n" + @@ -4209,7 +4431,8 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\n" + "encryption\x18\x11 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\n" + "encryption\x12`\n" + - "\rfeature_flags\x18\x12 \x03(\v2;.atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntryR\ffeatureFlags\x1a`\n" + + "\rfeature_flags\x18\x12 \x03(\v2;.atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntryR\ffeatureFlags\x12-\n" + + "\x04logs\x18\x13 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs\x1a`\n" + "\x11InputOriginsEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x125\n" + "\x05value\x18\x02 \x01(\v2\x1f.atmos.plugin.v1.SourceLocationR\x05value:\x028\x01\x1a?\n" + @@ -4240,11 +4463,19 @@ const file_atmos_plugin_v1_plugin_proto_rawDesc = "" + "\x04role\x18\x01 \x01(\tR\x04role\x12!\n" + "\fsession_name\x18\x02 \x01(\tR\vsessionName\x12)\n" + "\x10duration_seconds\x18\x03 \x01(\rR\x0fdurationSeconds\x12M\n" + - "\x12web_identity_token\x18\x04 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x10webIdentityToken\"\xd9\x01\n" + + "\x12web_identity_token\x18\x04 \x01(\v2\x1f.atmos.plugin.v1.ComponentValueR\x10webIdentityToken\"\x88\x02\n" + "\x1dResolveComponentStateResponse\x12=\n" + "\x05state\x18\x01 \x01(\v2'.atmos.plugin.v1.ComponentStateIdentityR\x05state\x12:\n" + "\asources\x18\x02 \x03(\v2 .atmos.plugin.v1.ComponentSourceR\asources\x12=\n" + - "\vdiagnostics\x18\x03 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics*N\n" + + "\vdiagnostics\x18\x03 \x03(\v2\x1b.atmos.plugin.v1.DiagnosticR\vdiagnostics\x12-\n" + + "\x04logs\x18\x04 \x03(\v2\x19.atmos.plugin.v1.LogEntryR\x04logs*\x8c\x01\n" + + "\bLogLevel\x12\x19\n" + + "\x15LOG_LEVEL_UNSPECIFIED\x10\x00\x12\x13\n" + + "\x0fLOG_LEVEL_TRACE\x10\x01\x12\x13\n" + + "\x0fLOG_LEVEL_DEBUG\x10\x02\x12\x12\n" + + "\x0eLOG_LEVEL_INFO\x10\x03\x12\x12\n" + + "\x0eLOG_LEVEL_WARN\x10\x04\x12\x13\n" + + "\x0fLOG_LEVEL_ERROR\x10\x05*N\n" + "\bSeverity\x12\x18\n" + "\x14SEVERITY_UNSPECIFIED\x10\x00\x12\x12\n" + "\x0eSEVERITY_ERROR\x10\x01\x12\x14\n" + @@ -4291,216 +4522,226 @@ func file_atmos_plugin_v1_plugin_proto_rawDescGZIP() []byte { } var ( - file_atmos_plugin_v1_plugin_proto_enumTypes = make([]protoimpl.EnumInfo, 3) - file_atmos_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 63) + file_atmos_plugin_v1_plugin_proto_enumTypes = make([]protoimpl.EnumInfo, 4) + file_atmos_plugin_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 65) file_atmos_plugin_v1_plugin_proto_goTypes = []any{ - Severity(0), // 0: atmos.plugin.v1.Severity - ComponentSource_Kind(0), // 1: atmos.plugin.v1.ComponentSource.Kind - ComponentDependency_Kind(0), // 2: atmos.plugin.v1.ComponentDependency.Kind - (*Invocation)(nil), // 3: atmos.plugin.v1.Invocation - (*Credentials)(nil), // 4: atmos.plugin.v1.Credentials - (*ServiceVersionRange)(nil), // 5: atmos.plugin.v1.ServiceVersionRange - (*Export)(nil), // 6: atmos.plugin.v1.Export - (*DescribeRequest)(nil), // 7: atmos.plugin.v1.DescribeRequest - (*DescribeResponse)(nil), // 8: atmos.plugin.v1.DescribeResponse - (*ConfigureRequest)(nil), // 9: atmos.plugin.v1.ConfigureRequest - (*ProviderRequest)(nil), // 10: atmos.plugin.v1.ProviderRequest - (*IdentityRequest)(nil), // 11: atmos.plugin.v1.IdentityRequest - (*Progress)(nil), // 12: atmos.plugin.v1.Progress - (*Interaction)(nil), // 13: atmos.plugin.v1.Interaction - (*AuthenticateEvent)(nil), // 14: atmos.plugin.v1.AuthenticateEvent - (*SourceLocation)(nil), // 15: atmos.plugin.v1.SourceLocation - (*ErrorDetail)(nil), // 16: atmos.plugin.v1.ErrorDetail - (*Diagnostic)(nil), // 17: atmos.plugin.v1.Diagnostic - (*ValidateResponse)(nil), // 18: atmos.plugin.v1.ValidateResponse - (*Unsupported)(nil), // 19: atmos.plugin.v1.Unsupported - (*RefreshRequest)(nil), // 20: atmos.plugin.v1.RefreshRequest - (*RefreshResponse)(nil), // 21: atmos.plugin.v1.RefreshResponse - (*EnvironmentResponse)(nil), // 22: atmos.plugin.v1.EnvironmentResponse - (*PrepareEnvironmentRequest)(nil), // 23: atmos.plugin.v1.PrepareEnvironmentRequest - (*CredentialPath)(nil), // 24: atmos.plugin.v1.CredentialPath - (*PathsResponse)(nil), // 25: atmos.plugin.v1.PathsResponse - (*IdentityAuthenticateRequest)(nil), // 26: atmos.plugin.v1.IdentityAuthenticateRequest - (*IdentityPrepareRequest)(nil), // 27: atmos.plugin.v1.IdentityPrepareRequest - (*CommandRequest)(nil), // 28: atmos.plugin.v1.CommandRequest - (*CommandExit)(nil), // 29: atmos.plugin.v1.CommandExit - (*CommandEvent)(nil), // 30: atmos.plugin.v1.CommandEvent - (*ComponentValue)(nil), // 31: atmos.plugin.v1.ComponentValue - (*ComponentValuePath)(nil), // 32: atmos.plugin.v1.ComponentValuePath - (*ComponentValueStep)(nil), // 33: atmos.plugin.v1.ComponentValueStep - (*ComponentAddress)(nil), // 34: atmos.plugin.v1.ComponentAddress - (*ComponentSource)(nil), // 35: atmos.plugin.v1.ComponentSource - (*ComponentDependency)(nil), // 36: atmos.plugin.v1.ComponentDependency - (*DiscoveredComponent)(nil), // 37: atmos.plugin.v1.DiscoveredComponent - (*ComponentEffects)(nil), // 38: atmos.plugin.v1.ComponentEffects - (*ComponentOperation)(nil), // 39: atmos.plugin.v1.ComponentOperation - (*DiscoverComponentsRequest)(nil), // 40: atmos.plugin.v1.DiscoverComponentsRequest - (*DiscoverComponentsResponse)(nil), // 41: atmos.plugin.v1.DiscoverComponentsResponse - (*ComponentRequest)(nil), // 42: atmos.plugin.v1.ComponentRequest - (*ComponentStateIdentity)(nil), // 43: atmos.plugin.v1.ComponentStateIdentity - (*ComponentGeneratedFile)(nil), // 44: atmos.plugin.v1.ComponentGeneratedFile - (*ComponentExecutionConfiguration)(nil), // 45: atmos.plugin.v1.ComponentExecutionConfiguration - (*ComponentExtraArguments)(nil), // 46: atmos.plugin.v1.ComponentExtraArguments - (*ComponentHook)(nil), // 47: atmos.plugin.v1.ComponentHook - (*PrepareComponentResponse)(nil), // 48: atmos.plugin.v1.PrepareComponentResponse - (*ComponentErrorsConfiguration)(nil), // 49: atmos.plugin.v1.ComponentErrorsConfiguration - (*ComponentRetryPolicy)(nil), // 50: atmos.plugin.v1.ComponentRetryPolicy - (*ComponentIgnorePolicy)(nil), // 51: atmos.plugin.v1.ComponentIgnorePolicy - (*ComponentExclude)(nil), // 52: atmos.plugin.v1.ComponentExclude - (*ComponentIam)(nil), // 53: atmos.plugin.v1.ComponentIam - (*ResolveComponentStateResponse)(nil), // 54: atmos.plugin.v1.ResolveComponentStateResponse - nil, // 55: atmos.plugin.v1.Invocation.EnvironmentEntry - nil, // 56: atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry - nil, // 57: atmos.plugin.v1.Interaction.FieldsEntry - nil, // 58: atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry - nil, // 59: atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry - nil, // 60: atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry - nil, // 61: atmos.plugin.v1.ComponentOperation.OptionsEntry - nil, // 62: atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry - nil, // 63: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry - nil, // 64: atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry - nil, // 65: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry - (*timestamppb.Timestamp)(nil), // 66: google.protobuf.Timestamp - (*structpb.Struct)(nil), // 67: google.protobuf.Struct - (*emptypb.Empty)(nil), // 68: google.protobuf.Empty + LogLevel(0), // 0: atmos.plugin.v1.LogLevel + Severity(0), // 1: atmos.plugin.v1.Severity + ComponentSource_Kind(0), // 2: atmos.plugin.v1.ComponentSource.Kind + ComponentDependency_Kind(0), // 3: atmos.plugin.v1.ComponentDependency.Kind + (*Invocation)(nil), // 4: atmos.plugin.v1.Invocation + (*Credentials)(nil), // 5: atmos.plugin.v1.Credentials + (*ServiceVersionRange)(nil), // 6: atmos.plugin.v1.ServiceVersionRange + (*Export)(nil), // 7: atmos.plugin.v1.Export + (*DescribeRequest)(nil), // 8: atmos.plugin.v1.DescribeRequest + (*DescribeResponse)(nil), // 9: atmos.plugin.v1.DescribeResponse + (*ConfigureRequest)(nil), // 10: atmos.plugin.v1.ConfigureRequest + (*ProviderRequest)(nil), // 11: atmos.plugin.v1.ProviderRequest + (*IdentityRequest)(nil), // 12: atmos.plugin.v1.IdentityRequest + (*Progress)(nil), // 13: atmos.plugin.v1.Progress + (*Interaction)(nil), // 14: atmos.plugin.v1.Interaction + (*AuthenticateEvent)(nil), // 15: atmos.plugin.v1.AuthenticateEvent + (*SourceLocation)(nil), // 16: atmos.plugin.v1.SourceLocation + (*LogEntry)(nil), // 17: atmos.plugin.v1.LogEntry + (*ErrorDetail)(nil), // 18: atmos.plugin.v1.ErrorDetail + (*Diagnostic)(nil), // 19: atmos.plugin.v1.Diagnostic + (*ValidateResponse)(nil), // 20: atmos.plugin.v1.ValidateResponse + (*Unsupported)(nil), // 21: atmos.plugin.v1.Unsupported + (*RefreshRequest)(nil), // 22: atmos.plugin.v1.RefreshRequest + (*RefreshResponse)(nil), // 23: atmos.plugin.v1.RefreshResponse + (*EnvironmentResponse)(nil), // 24: atmos.plugin.v1.EnvironmentResponse + (*PrepareEnvironmentRequest)(nil), // 25: atmos.plugin.v1.PrepareEnvironmentRequest + (*CredentialPath)(nil), // 26: atmos.plugin.v1.CredentialPath + (*PathsResponse)(nil), // 27: atmos.plugin.v1.PathsResponse + (*IdentityAuthenticateRequest)(nil), // 28: atmos.plugin.v1.IdentityAuthenticateRequest + (*IdentityPrepareRequest)(nil), // 29: atmos.plugin.v1.IdentityPrepareRequest + (*CommandRequest)(nil), // 30: atmos.plugin.v1.CommandRequest + (*CommandExit)(nil), // 31: atmos.plugin.v1.CommandExit + (*CommandEvent)(nil), // 32: atmos.plugin.v1.CommandEvent + (*ComponentValue)(nil), // 33: atmos.plugin.v1.ComponentValue + (*ComponentValuePath)(nil), // 34: atmos.plugin.v1.ComponentValuePath + (*ComponentValueStep)(nil), // 35: atmos.plugin.v1.ComponentValueStep + (*ComponentAddress)(nil), // 36: atmos.plugin.v1.ComponentAddress + (*ComponentSource)(nil), // 37: atmos.plugin.v1.ComponentSource + (*ComponentDependency)(nil), // 38: atmos.plugin.v1.ComponentDependency + (*DiscoveredComponent)(nil), // 39: atmos.plugin.v1.DiscoveredComponent + (*ComponentEffects)(nil), // 40: atmos.plugin.v1.ComponentEffects + (*ComponentOperation)(nil), // 41: atmos.plugin.v1.ComponentOperation + (*DiscoverComponentsRequest)(nil), // 42: atmos.plugin.v1.DiscoverComponentsRequest + (*DiscoverComponentsResponse)(nil), // 43: atmos.plugin.v1.DiscoverComponentsResponse + (*ComponentRequest)(nil), // 44: atmos.plugin.v1.ComponentRequest + (*ComponentStateIdentity)(nil), // 45: atmos.plugin.v1.ComponentStateIdentity + (*ComponentGeneratedFile)(nil), // 46: atmos.plugin.v1.ComponentGeneratedFile + (*ComponentExecutionConfiguration)(nil), // 47: atmos.plugin.v1.ComponentExecutionConfiguration + (*ComponentExtraArguments)(nil), // 48: atmos.plugin.v1.ComponentExtraArguments + (*ComponentHook)(nil), // 49: atmos.plugin.v1.ComponentHook + (*PrepareComponentResponse)(nil), // 50: atmos.plugin.v1.PrepareComponentResponse + (*ComponentErrorsConfiguration)(nil), // 51: atmos.plugin.v1.ComponentErrorsConfiguration + (*ComponentRetryPolicy)(nil), // 52: atmos.plugin.v1.ComponentRetryPolicy + (*ComponentIgnorePolicy)(nil), // 53: atmos.plugin.v1.ComponentIgnorePolicy + (*ComponentExclude)(nil), // 54: atmos.plugin.v1.ComponentExclude + (*ComponentIam)(nil), // 55: atmos.plugin.v1.ComponentIam + (*ResolveComponentStateResponse)(nil), // 56: atmos.plugin.v1.ResolveComponentStateResponse + nil, // 57: atmos.plugin.v1.Invocation.EnvironmentEntry + nil, // 58: atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry + nil, // 59: atmos.plugin.v1.Interaction.FieldsEntry + nil, // 60: atmos.plugin.v1.LogEntry.FieldsEntry + nil, // 61: atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry + nil, // 62: atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry + nil, // 63: atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry + nil, // 64: atmos.plugin.v1.ComponentOperation.OptionsEntry + nil, // 65: atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry + nil, // 66: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry + nil, // 67: atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry + nil, // 68: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry + (*timestamppb.Timestamp)(nil), // 69: google.protobuf.Timestamp + (*structpb.Struct)(nil), // 70: google.protobuf.Struct + (*emptypb.Empty)(nil), // 71: google.protobuf.Empty } ) var file_atmos_plugin_v1_plugin_proto_depIdxs = []int32{ - 66, // 0: atmos.plugin.v1.Invocation.deadline:type_name -> google.protobuf.Timestamp - 55, // 1: atmos.plugin.v1.Invocation.environment:type_name -> atmos.plugin.v1.Invocation.EnvironmentEntry - 66, // 2: atmos.plugin.v1.Credentials.expires_at:type_name -> google.protobuf.Timestamp - 67, // 3: atmos.plugin.v1.Credentials.data:type_name -> google.protobuf.Struct - 5, // 4: atmos.plugin.v1.DescribeRequest.host_supported:type_name -> atmos.plugin.v1.ServiceVersionRange - 5, // 5: atmos.plugin.v1.DescribeResponse.services:type_name -> atmos.plugin.v1.ServiceVersionRange - 6, // 6: atmos.plugin.v1.DescribeResponse.exports:type_name -> atmos.plugin.v1.Export - 56, // 7: atmos.plugin.v1.ConfigureRequest.broker_ids:type_name -> atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry - 67, // 8: atmos.plugin.v1.ConfigureRequest.settings:type_name -> google.protobuf.Struct - 3, // 9: atmos.plugin.v1.ProviderRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 10: atmos.plugin.v1.ProviderRequest.spec:type_name -> google.protobuf.Struct - 3, // 11: atmos.plugin.v1.IdentityRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 12: atmos.plugin.v1.IdentityRequest.spec:type_name -> google.protobuf.Struct - 67, // 13: atmos.plugin.v1.IdentityRequest.principal:type_name -> google.protobuf.Struct - 57, // 14: atmos.plugin.v1.Interaction.fields:type_name -> atmos.plugin.v1.Interaction.FieldsEntry - 12, // 15: atmos.plugin.v1.AuthenticateEvent.progress:type_name -> atmos.plugin.v1.Progress - 13, // 16: atmos.plugin.v1.AuthenticateEvent.interaction:type_name -> atmos.plugin.v1.Interaction - 4, // 17: atmos.plugin.v1.AuthenticateEvent.result:type_name -> atmos.plugin.v1.Credentials - 15, // 18: atmos.plugin.v1.ErrorDetail.location:type_name -> atmos.plugin.v1.SourceLocation - 0, // 19: atmos.plugin.v1.ErrorDetail.severity:type_name -> atmos.plugin.v1.Severity - 16, // 20: atmos.plugin.v1.Diagnostic.detail:type_name -> atmos.plugin.v1.ErrorDetail - 17, // 21: atmos.plugin.v1.ValidateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 10, // 22: atmos.plugin.v1.RefreshRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest - 4, // 23: atmos.plugin.v1.RefreshRequest.current:type_name -> atmos.plugin.v1.Credentials - 4, // 24: atmos.plugin.v1.RefreshResponse.credentials:type_name -> atmos.plugin.v1.Credentials - 19, // 25: atmos.plugin.v1.RefreshResponse.unsupported:type_name -> atmos.plugin.v1.Unsupported - 58, // 26: atmos.plugin.v1.EnvironmentResponse.environment:type_name -> atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry - 10, // 27: atmos.plugin.v1.PrepareEnvironmentRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest - 59, // 28: atmos.plugin.v1.PrepareEnvironmentRequest.environment:type_name -> atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry - 24, // 29: atmos.plugin.v1.PathsResponse.paths:type_name -> atmos.plugin.v1.CredentialPath - 11, // 30: atmos.plugin.v1.IdentityAuthenticateRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest - 4, // 31: atmos.plugin.v1.IdentityAuthenticateRequest.upstream:type_name -> atmos.plugin.v1.Credentials - 11, // 32: atmos.plugin.v1.IdentityPrepareRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest - 60, // 33: atmos.plugin.v1.IdentityPrepareRequest.environment:type_name -> atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry - 3, // 34: atmos.plugin.v1.CommandRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 67, // 35: atmos.plugin.v1.CommandRequest.settings:type_name -> google.protobuf.Struct - 29, // 36: atmos.plugin.v1.CommandEvent.exit:type_name -> atmos.plugin.v1.CommandExit - 32, // 37: atmos.plugin.v1.ComponentValue.sensitive_paths:type_name -> atmos.plugin.v1.ComponentValuePath - 33, // 38: atmos.plugin.v1.ComponentValuePath.steps:type_name -> atmos.plugin.v1.ComponentValueStep - 31, // 39: atmos.plugin.v1.ComponentValueStep.index:type_name -> atmos.plugin.v1.ComponentValue - 1, // 40: atmos.plugin.v1.ComponentSource.kind:type_name -> atmos.plugin.v1.ComponentSource.Kind - 34, // 41: atmos.plugin.v1.ComponentDependency.target:type_name -> atmos.plugin.v1.ComponentAddress - 2, // 42: atmos.plugin.v1.ComponentDependency.kind:type_name -> atmos.plugin.v1.ComponentDependency.Kind - 34, // 43: atmos.plugin.v1.DiscoveredComponent.address:type_name -> atmos.plugin.v1.ComponentAddress - 31, // 44: atmos.plugin.v1.DiscoveredComponent.configuration:type_name -> atmos.plugin.v1.ComponentValue - 35, // 45: atmos.plugin.v1.DiscoveredComponent.sources:type_name -> atmos.plugin.v1.ComponentSource - 36, // 46: atmos.plugin.v1.DiscoveredComponent.dependencies:type_name -> atmos.plugin.v1.ComponentDependency - 61, // 47: atmos.plugin.v1.ComponentOperation.options:type_name -> atmos.plugin.v1.ComponentOperation.OptionsEntry - 3, // 48: atmos.plugin.v1.DiscoverComponentsRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 39, // 49: atmos.plugin.v1.DiscoverComponentsRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation - 38, // 50: atmos.plugin.v1.DiscoverComponentsRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects - 31, // 51: atmos.plugin.v1.DiscoverComponentsRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue - 37, // 52: atmos.plugin.v1.DiscoverComponentsResponse.components:type_name -> atmos.plugin.v1.DiscoveredComponent - 17, // 53: atmos.plugin.v1.DiscoverComponentsResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 3, // 54: atmos.plugin.v1.ComponentRequest.invocation:type_name -> atmos.plugin.v1.Invocation - 34, // 55: atmos.plugin.v1.ComponentRequest.address:type_name -> atmos.plugin.v1.ComponentAddress - 39, // 56: atmos.plugin.v1.ComponentRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation - 38, // 57: atmos.plugin.v1.ComponentRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects - 31, // 58: atmos.plugin.v1.ComponentRequest.configuration:type_name -> atmos.plugin.v1.ComponentValue - 31, // 59: atmos.plugin.v1.ComponentRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue - 31, // 60: atmos.plugin.v1.ComponentStateIdentity.backend:type_name -> atmos.plugin.v1.ComponentValue - 46, // 61: atmos.plugin.v1.ComponentExecutionConfiguration.extra_arguments:type_name -> atmos.plugin.v1.ComponentExtraArguments - 47, // 62: atmos.plugin.v1.ComponentExecutionConfiguration.before_hooks:type_name -> atmos.plugin.v1.ComponentHook - 47, // 63: atmos.plugin.v1.ComponentExecutionConfiguration.after_hooks:type_name -> atmos.plugin.v1.ComponentHook - 47, // 64: atmos.plugin.v1.ComponentExecutionConfiguration.error_hooks:type_name -> atmos.plugin.v1.ComponentHook - 62, // 65: atmos.plugin.v1.ComponentExtraArguments.environment:type_name -> atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry - 31, // 66: atmos.plugin.v1.PrepareComponentResponse.inputs:type_name -> atmos.plugin.v1.ComponentValue - 43, // 67: atmos.plugin.v1.PrepareComponentResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity - 44, // 68: atmos.plugin.v1.PrepareComponentResponse.files:type_name -> atmos.plugin.v1.ComponentGeneratedFile - 36, // 69: atmos.plugin.v1.PrepareComponentResponse.dependencies:type_name -> atmos.plugin.v1.ComponentDependency - 35, // 70: atmos.plugin.v1.PrepareComponentResponse.sources:type_name -> atmos.plugin.v1.ComponentSource - 17, // 71: atmos.plugin.v1.PrepareComponentResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 45, // 72: atmos.plugin.v1.PrepareComponentResponse.execution:type_name -> atmos.plugin.v1.ComponentExecutionConfiguration - 63, // 73: atmos.plugin.v1.PrepareComponentResponse.input_origins:type_name -> atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry - 49, // 74: atmos.plugin.v1.PrepareComponentResponse.errors:type_name -> atmos.plugin.v1.ComponentErrorsConfiguration - 52, // 75: atmos.plugin.v1.PrepareComponentResponse.exclude:type_name -> atmos.plugin.v1.ComponentExclude - 53, // 76: atmos.plugin.v1.PrepareComponentResponse.iam:type_name -> atmos.plugin.v1.ComponentIam - 31, // 77: atmos.plugin.v1.PrepareComponentResponse.encryption:type_name -> atmos.plugin.v1.ComponentValue - 64, // 78: atmos.plugin.v1.PrepareComponentResponse.feature_flags:type_name -> atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry - 50, // 79: atmos.plugin.v1.ComponentErrorsConfiguration.retry:type_name -> atmos.plugin.v1.ComponentRetryPolicy - 51, // 80: atmos.plugin.v1.ComponentErrorsConfiguration.ignore:type_name -> atmos.plugin.v1.ComponentIgnorePolicy - 65, // 81: atmos.plugin.v1.ComponentIgnorePolicy.signals:type_name -> atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry - 31, // 82: atmos.plugin.v1.ComponentIam.web_identity_token:type_name -> atmos.plugin.v1.ComponentValue - 43, // 83: atmos.plugin.v1.ResolveComponentStateResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity - 35, // 84: atmos.plugin.v1.ResolveComponentStateResponse.sources:type_name -> atmos.plugin.v1.ComponentSource - 17, // 85: atmos.plugin.v1.ResolveComponentStateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic - 31, // 86: atmos.plugin.v1.ComponentOperation.OptionsEntry.value:type_name -> atmos.plugin.v1.ComponentValue - 15, // 87: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry.value:type_name -> atmos.plugin.v1.SourceLocation - 31, // 88: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry.value:type_name -> atmos.plugin.v1.ComponentValue - 7, // 89: atmos.plugin.v1.Info.Describe:input_type -> atmos.plugin.v1.DescribeRequest - 9, // 90: atmos.plugin.v1.Info.Configure:input_type -> atmos.plugin.v1.ConfigureRequest - 10, // 91: atmos.plugin.v1.AuthProvider.Validate:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 92: atmos.plugin.v1.AuthProvider.Authenticate:input_type -> atmos.plugin.v1.ProviderRequest - 20, // 93: atmos.plugin.v1.AuthProvider.Refresh:input_type -> atmos.plugin.v1.RefreshRequest - 10, // 94: atmos.plugin.v1.AuthProvider.Logout:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 95: atmos.plugin.v1.AuthProvider.Environment:input_type -> atmos.plugin.v1.ProviderRequest - 10, // 96: atmos.plugin.v1.AuthProvider.Paths:input_type -> atmos.plugin.v1.ProviderRequest - 23, // 97: atmos.plugin.v1.AuthProvider.PrepareEnvironment:input_type -> atmos.plugin.v1.PrepareEnvironmentRequest - 11, // 98: atmos.plugin.v1.AuthIdentity.Validate:input_type -> atmos.plugin.v1.IdentityRequest - 26, // 99: atmos.plugin.v1.AuthIdentity.Authenticate:input_type -> atmos.plugin.v1.IdentityAuthenticateRequest - 11, // 100: atmos.plugin.v1.AuthIdentity.Logout:input_type -> atmos.plugin.v1.IdentityRequest - 11, // 101: atmos.plugin.v1.AuthIdentity.Environment:input_type -> atmos.plugin.v1.IdentityRequest - 11, // 102: atmos.plugin.v1.AuthIdentity.Paths:input_type -> atmos.plugin.v1.IdentityRequest - 27, // 103: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:input_type -> atmos.plugin.v1.IdentityPrepareRequest - 28, // 104: atmos.plugin.v1.Commands.Run:input_type -> atmos.plugin.v1.CommandRequest - 40, // 105: atmos.plugin.v1.ComponentDiscovery.Discover:input_type -> atmos.plugin.v1.DiscoverComponentsRequest - 42, // 106: atmos.plugin.v1.ComponentValidation.Validate:input_type -> atmos.plugin.v1.ComponentRequest - 42, // 107: atmos.plugin.v1.ComponentPreparation.Prepare:input_type -> atmos.plugin.v1.ComponentRequest - 42, // 108: atmos.plugin.v1.ComponentState.Resolve:input_type -> atmos.plugin.v1.ComponentRequest - 8, // 109: atmos.plugin.v1.Info.Describe:output_type -> atmos.plugin.v1.DescribeResponse - 68, // 110: atmos.plugin.v1.Info.Configure:output_type -> google.protobuf.Empty - 18, // 111: atmos.plugin.v1.AuthProvider.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 14, // 112: atmos.plugin.v1.AuthProvider.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent - 21, // 113: atmos.plugin.v1.AuthProvider.Refresh:output_type -> atmos.plugin.v1.RefreshResponse - 68, // 114: atmos.plugin.v1.AuthProvider.Logout:output_type -> google.protobuf.Empty - 22, // 115: atmos.plugin.v1.AuthProvider.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse - 25, // 116: atmos.plugin.v1.AuthProvider.Paths:output_type -> atmos.plugin.v1.PathsResponse - 22, // 117: atmos.plugin.v1.AuthProvider.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse - 18, // 118: atmos.plugin.v1.AuthIdentity.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 14, // 119: atmos.plugin.v1.AuthIdentity.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent - 68, // 120: atmos.plugin.v1.AuthIdentity.Logout:output_type -> google.protobuf.Empty - 22, // 121: atmos.plugin.v1.AuthIdentity.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse - 25, // 122: atmos.plugin.v1.AuthIdentity.Paths:output_type -> atmos.plugin.v1.PathsResponse - 22, // 123: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse - 30, // 124: atmos.plugin.v1.Commands.Run:output_type -> atmos.plugin.v1.CommandEvent - 41, // 125: atmos.plugin.v1.ComponentDiscovery.Discover:output_type -> atmos.plugin.v1.DiscoverComponentsResponse - 18, // 126: atmos.plugin.v1.ComponentValidation.Validate:output_type -> atmos.plugin.v1.ValidateResponse - 48, // 127: atmos.plugin.v1.ComponentPreparation.Prepare:output_type -> atmos.plugin.v1.PrepareComponentResponse - 54, // 128: atmos.plugin.v1.ComponentState.Resolve:output_type -> atmos.plugin.v1.ResolveComponentStateResponse - 109, // [109:129] is the sub-list for method output_type - 89, // [89:109] is the sub-list for method input_type - 89, // [89:89] is the sub-list for extension type_name - 89, // [89:89] is the sub-list for extension extendee - 0, // [0:89] is the sub-list for field type_name + 69, // 0: atmos.plugin.v1.Invocation.deadline:type_name -> google.protobuf.Timestamp + 57, // 1: atmos.plugin.v1.Invocation.environment:type_name -> atmos.plugin.v1.Invocation.EnvironmentEntry + 69, // 2: atmos.plugin.v1.Credentials.expires_at:type_name -> google.protobuf.Timestamp + 70, // 3: atmos.plugin.v1.Credentials.data:type_name -> google.protobuf.Struct + 6, // 4: atmos.plugin.v1.DescribeRequest.host_supported:type_name -> atmos.plugin.v1.ServiceVersionRange + 6, // 5: atmos.plugin.v1.DescribeResponse.services:type_name -> atmos.plugin.v1.ServiceVersionRange + 7, // 6: atmos.plugin.v1.DescribeResponse.exports:type_name -> atmos.plugin.v1.Export + 58, // 7: atmos.plugin.v1.ConfigureRequest.broker_ids:type_name -> atmos.plugin.v1.ConfigureRequest.BrokerIdsEntry + 70, // 8: atmos.plugin.v1.ConfigureRequest.settings:type_name -> google.protobuf.Struct + 4, // 9: atmos.plugin.v1.ProviderRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 10: atmos.plugin.v1.ProviderRequest.spec:type_name -> google.protobuf.Struct + 4, // 11: atmos.plugin.v1.IdentityRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 12: atmos.plugin.v1.IdentityRequest.spec:type_name -> google.protobuf.Struct + 70, // 13: atmos.plugin.v1.IdentityRequest.principal:type_name -> google.protobuf.Struct + 59, // 14: atmos.plugin.v1.Interaction.fields:type_name -> atmos.plugin.v1.Interaction.FieldsEntry + 13, // 15: atmos.plugin.v1.AuthenticateEvent.progress:type_name -> atmos.plugin.v1.Progress + 14, // 16: atmos.plugin.v1.AuthenticateEvent.interaction:type_name -> atmos.plugin.v1.Interaction + 5, // 17: atmos.plugin.v1.AuthenticateEvent.result:type_name -> atmos.plugin.v1.Credentials + 0, // 18: atmos.plugin.v1.LogEntry.level:type_name -> atmos.plugin.v1.LogLevel + 60, // 19: atmos.plugin.v1.LogEntry.fields:type_name -> atmos.plugin.v1.LogEntry.FieldsEntry + 69, // 20: atmos.plugin.v1.LogEntry.time:type_name -> google.protobuf.Timestamp + 16, // 21: atmos.plugin.v1.ErrorDetail.location:type_name -> atmos.plugin.v1.SourceLocation + 1, // 22: atmos.plugin.v1.ErrorDetail.severity:type_name -> atmos.plugin.v1.Severity + 17, // 23: atmos.plugin.v1.ErrorDetail.logs:type_name -> atmos.plugin.v1.LogEntry + 18, // 24: atmos.plugin.v1.Diagnostic.detail:type_name -> atmos.plugin.v1.ErrorDetail + 19, // 25: atmos.plugin.v1.ValidateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 11, // 26: atmos.plugin.v1.RefreshRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest + 5, // 27: atmos.plugin.v1.RefreshRequest.current:type_name -> atmos.plugin.v1.Credentials + 5, // 28: atmos.plugin.v1.RefreshResponse.credentials:type_name -> atmos.plugin.v1.Credentials + 21, // 29: atmos.plugin.v1.RefreshResponse.unsupported:type_name -> atmos.plugin.v1.Unsupported + 61, // 30: atmos.plugin.v1.EnvironmentResponse.environment:type_name -> atmos.plugin.v1.EnvironmentResponse.EnvironmentEntry + 11, // 31: atmos.plugin.v1.PrepareEnvironmentRequest.provider:type_name -> atmos.plugin.v1.ProviderRequest + 62, // 32: atmos.plugin.v1.PrepareEnvironmentRequest.environment:type_name -> atmos.plugin.v1.PrepareEnvironmentRequest.EnvironmentEntry + 26, // 33: atmos.plugin.v1.PathsResponse.paths:type_name -> atmos.plugin.v1.CredentialPath + 12, // 34: atmos.plugin.v1.IdentityAuthenticateRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest + 5, // 35: atmos.plugin.v1.IdentityAuthenticateRequest.upstream:type_name -> atmos.plugin.v1.Credentials + 12, // 36: atmos.plugin.v1.IdentityPrepareRequest.identity:type_name -> atmos.plugin.v1.IdentityRequest + 63, // 37: atmos.plugin.v1.IdentityPrepareRequest.environment:type_name -> atmos.plugin.v1.IdentityPrepareRequest.EnvironmentEntry + 4, // 38: atmos.plugin.v1.CommandRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 70, // 39: atmos.plugin.v1.CommandRequest.settings:type_name -> google.protobuf.Struct + 31, // 40: atmos.plugin.v1.CommandEvent.exit:type_name -> atmos.plugin.v1.CommandExit + 34, // 41: atmos.plugin.v1.ComponentValue.sensitive_paths:type_name -> atmos.plugin.v1.ComponentValuePath + 35, // 42: atmos.plugin.v1.ComponentValuePath.steps:type_name -> atmos.plugin.v1.ComponentValueStep + 33, // 43: atmos.plugin.v1.ComponentValueStep.index:type_name -> atmos.plugin.v1.ComponentValue + 2, // 44: atmos.plugin.v1.ComponentSource.kind:type_name -> atmos.plugin.v1.ComponentSource.Kind + 36, // 45: atmos.plugin.v1.ComponentDependency.target:type_name -> atmos.plugin.v1.ComponentAddress + 3, // 46: atmos.plugin.v1.ComponentDependency.kind:type_name -> atmos.plugin.v1.ComponentDependency.Kind + 36, // 47: atmos.plugin.v1.DiscoveredComponent.address:type_name -> atmos.plugin.v1.ComponentAddress + 33, // 48: atmos.plugin.v1.DiscoveredComponent.configuration:type_name -> atmos.plugin.v1.ComponentValue + 37, // 49: atmos.plugin.v1.DiscoveredComponent.sources:type_name -> atmos.plugin.v1.ComponentSource + 38, // 50: atmos.plugin.v1.DiscoveredComponent.dependencies:type_name -> atmos.plugin.v1.ComponentDependency + 64, // 51: atmos.plugin.v1.ComponentOperation.options:type_name -> atmos.plugin.v1.ComponentOperation.OptionsEntry + 4, // 52: atmos.plugin.v1.DiscoverComponentsRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 41, // 53: atmos.plugin.v1.DiscoverComponentsRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation + 40, // 54: atmos.plugin.v1.DiscoverComponentsRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects + 33, // 55: atmos.plugin.v1.DiscoverComponentsRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue + 39, // 56: atmos.plugin.v1.DiscoverComponentsResponse.components:type_name -> atmos.plugin.v1.DiscoveredComponent + 19, // 57: atmos.plugin.v1.DiscoverComponentsResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 17, // 58: atmos.plugin.v1.DiscoverComponentsResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 4, // 59: atmos.plugin.v1.ComponentRequest.invocation:type_name -> atmos.plugin.v1.Invocation + 36, // 60: atmos.plugin.v1.ComponentRequest.address:type_name -> atmos.plugin.v1.ComponentAddress + 41, // 61: atmos.plugin.v1.ComponentRequest.operation:type_name -> atmos.plugin.v1.ComponentOperation + 40, // 62: atmos.plugin.v1.ComponentRequest.effects:type_name -> atmos.plugin.v1.ComponentEffects + 33, // 63: atmos.plugin.v1.ComponentRequest.configuration:type_name -> atmos.plugin.v1.ComponentValue + 33, // 64: atmos.plugin.v1.ComponentRequest.provider_configuration:type_name -> atmos.plugin.v1.ComponentValue + 33, // 65: atmos.plugin.v1.ComponentStateIdentity.backend:type_name -> atmos.plugin.v1.ComponentValue + 48, // 66: atmos.plugin.v1.ComponentExecutionConfiguration.extra_arguments:type_name -> atmos.plugin.v1.ComponentExtraArguments + 49, // 67: atmos.plugin.v1.ComponentExecutionConfiguration.before_hooks:type_name -> atmos.plugin.v1.ComponentHook + 49, // 68: atmos.plugin.v1.ComponentExecutionConfiguration.after_hooks:type_name -> atmos.plugin.v1.ComponentHook + 49, // 69: atmos.plugin.v1.ComponentExecutionConfiguration.error_hooks:type_name -> atmos.plugin.v1.ComponentHook + 65, // 70: atmos.plugin.v1.ComponentExtraArguments.environment:type_name -> atmos.plugin.v1.ComponentExtraArguments.EnvironmentEntry + 33, // 71: atmos.plugin.v1.PrepareComponentResponse.inputs:type_name -> atmos.plugin.v1.ComponentValue + 45, // 72: atmos.plugin.v1.PrepareComponentResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity + 46, // 73: atmos.plugin.v1.PrepareComponentResponse.files:type_name -> atmos.plugin.v1.ComponentGeneratedFile + 38, // 74: atmos.plugin.v1.PrepareComponentResponse.dependencies:type_name -> atmos.plugin.v1.ComponentDependency + 37, // 75: atmos.plugin.v1.PrepareComponentResponse.sources:type_name -> atmos.plugin.v1.ComponentSource + 19, // 76: atmos.plugin.v1.PrepareComponentResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 47, // 77: atmos.plugin.v1.PrepareComponentResponse.execution:type_name -> atmos.plugin.v1.ComponentExecutionConfiguration + 66, // 78: atmos.plugin.v1.PrepareComponentResponse.input_origins:type_name -> atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry + 51, // 79: atmos.plugin.v1.PrepareComponentResponse.errors:type_name -> atmos.plugin.v1.ComponentErrorsConfiguration + 54, // 80: atmos.plugin.v1.PrepareComponentResponse.exclude:type_name -> atmos.plugin.v1.ComponentExclude + 55, // 81: atmos.plugin.v1.PrepareComponentResponse.iam:type_name -> atmos.plugin.v1.ComponentIam + 33, // 82: atmos.plugin.v1.PrepareComponentResponse.encryption:type_name -> atmos.plugin.v1.ComponentValue + 67, // 83: atmos.plugin.v1.PrepareComponentResponse.feature_flags:type_name -> atmos.plugin.v1.PrepareComponentResponse.FeatureFlagsEntry + 17, // 84: atmos.plugin.v1.PrepareComponentResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 52, // 85: atmos.plugin.v1.ComponentErrorsConfiguration.retry:type_name -> atmos.plugin.v1.ComponentRetryPolicy + 53, // 86: atmos.plugin.v1.ComponentErrorsConfiguration.ignore:type_name -> atmos.plugin.v1.ComponentIgnorePolicy + 68, // 87: atmos.plugin.v1.ComponentIgnorePolicy.signals:type_name -> atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry + 33, // 88: atmos.plugin.v1.ComponentIam.web_identity_token:type_name -> atmos.plugin.v1.ComponentValue + 45, // 89: atmos.plugin.v1.ResolveComponentStateResponse.state:type_name -> atmos.plugin.v1.ComponentStateIdentity + 37, // 90: atmos.plugin.v1.ResolveComponentStateResponse.sources:type_name -> atmos.plugin.v1.ComponentSource + 19, // 91: atmos.plugin.v1.ResolveComponentStateResponse.diagnostics:type_name -> atmos.plugin.v1.Diagnostic + 17, // 92: atmos.plugin.v1.ResolveComponentStateResponse.logs:type_name -> atmos.plugin.v1.LogEntry + 33, // 93: atmos.plugin.v1.ComponentOperation.OptionsEntry.value:type_name -> atmos.plugin.v1.ComponentValue + 16, // 94: atmos.plugin.v1.PrepareComponentResponse.InputOriginsEntry.value:type_name -> atmos.plugin.v1.SourceLocation + 33, // 95: atmos.plugin.v1.ComponentIgnorePolicy.SignalsEntry.value:type_name -> atmos.plugin.v1.ComponentValue + 8, // 96: atmos.plugin.v1.Info.Describe:input_type -> atmos.plugin.v1.DescribeRequest + 10, // 97: atmos.plugin.v1.Info.Configure:input_type -> atmos.plugin.v1.ConfigureRequest + 11, // 98: atmos.plugin.v1.AuthProvider.Validate:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 99: atmos.plugin.v1.AuthProvider.Authenticate:input_type -> atmos.plugin.v1.ProviderRequest + 22, // 100: atmos.plugin.v1.AuthProvider.Refresh:input_type -> atmos.plugin.v1.RefreshRequest + 11, // 101: atmos.plugin.v1.AuthProvider.Logout:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 102: atmos.plugin.v1.AuthProvider.Environment:input_type -> atmos.plugin.v1.ProviderRequest + 11, // 103: atmos.plugin.v1.AuthProvider.Paths:input_type -> atmos.plugin.v1.ProviderRequest + 25, // 104: atmos.plugin.v1.AuthProvider.PrepareEnvironment:input_type -> atmos.plugin.v1.PrepareEnvironmentRequest + 12, // 105: atmos.plugin.v1.AuthIdentity.Validate:input_type -> atmos.plugin.v1.IdentityRequest + 28, // 106: atmos.plugin.v1.AuthIdentity.Authenticate:input_type -> atmos.plugin.v1.IdentityAuthenticateRequest + 12, // 107: atmos.plugin.v1.AuthIdentity.Logout:input_type -> atmos.plugin.v1.IdentityRequest + 12, // 108: atmos.plugin.v1.AuthIdentity.Environment:input_type -> atmos.plugin.v1.IdentityRequest + 12, // 109: atmos.plugin.v1.AuthIdentity.Paths:input_type -> atmos.plugin.v1.IdentityRequest + 29, // 110: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:input_type -> atmos.plugin.v1.IdentityPrepareRequest + 30, // 111: atmos.plugin.v1.Commands.Run:input_type -> atmos.plugin.v1.CommandRequest + 42, // 112: atmos.plugin.v1.ComponentDiscovery.Discover:input_type -> atmos.plugin.v1.DiscoverComponentsRequest + 44, // 113: atmos.plugin.v1.ComponentValidation.Validate:input_type -> atmos.plugin.v1.ComponentRequest + 44, // 114: atmos.plugin.v1.ComponentPreparation.Prepare:input_type -> atmos.plugin.v1.ComponentRequest + 44, // 115: atmos.plugin.v1.ComponentState.Resolve:input_type -> atmos.plugin.v1.ComponentRequest + 9, // 116: atmos.plugin.v1.Info.Describe:output_type -> atmos.plugin.v1.DescribeResponse + 71, // 117: atmos.plugin.v1.Info.Configure:output_type -> google.protobuf.Empty + 20, // 118: atmos.plugin.v1.AuthProvider.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 15, // 119: atmos.plugin.v1.AuthProvider.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent + 23, // 120: atmos.plugin.v1.AuthProvider.Refresh:output_type -> atmos.plugin.v1.RefreshResponse + 71, // 121: atmos.plugin.v1.AuthProvider.Logout:output_type -> google.protobuf.Empty + 24, // 122: atmos.plugin.v1.AuthProvider.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse + 27, // 123: atmos.plugin.v1.AuthProvider.Paths:output_type -> atmos.plugin.v1.PathsResponse + 24, // 124: atmos.plugin.v1.AuthProvider.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse + 20, // 125: atmos.plugin.v1.AuthIdentity.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 15, // 126: atmos.plugin.v1.AuthIdentity.Authenticate:output_type -> atmos.plugin.v1.AuthenticateEvent + 71, // 127: atmos.plugin.v1.AuthIdentity.Logout:output_type -> google.protobuf.Empty + 24, // 128: atmos.plugin.v1.AuthIdentity.Environment:output_type -> atmos.plugin.v1.EnvironmentResponse + 27, // 129: atmos.plugin.v1.AuthIdentity.Paths:output_type -> atmos.plugin.v1.PathsResponse + 24, // 130: atmos.plugin.v1.AuthIdentity.PrepareEnvironment:output_type -> atmos.plugin.v1.EnvironmentResponse + 32, // 131: atmos.plugin.v1.Commands.Run:output_type -> atmos.plugin.v1.CommandEvent + 43, // 132: atmos.plugin.v1.ComponentDiscovery.Discover:output_type -> atmos.plugin.v1.DiscoverComponentsResponse + 20, // 133: atmos.plugin.v1.ComponentValidation.Validate:output_type -> atmos.plugin.v1.ValidateResponse + 50, // 134: atmos.plugin.v1.ComponentPreparation.Prepare:output_type -> atmos.plugin.v1.PrepareComponentResponse + 56, // 135: atmos.plugin.v1.ComponentState.Resolve:output_type -> atmos.plugin.v1.ResolveComponentStateResponse + 116, // [116:136] is the sub-list for method output_type + 96, // [96:116] is the sub-list for method input_type + 96, // [96:96] is the sub-list for extension type_name + 96, // [96:96] is the sub-list for extension extendee + 0, // [0:96] is the sub-list for field type_name } func init() { file_atmos_plugin_v1_plugin_proto_init() } @@ -4513,16 +4754,16 @@ func file_atmos_plugin_v1_plugin_proto_init() { (*AuthenticateEvent_Interaction)(nil), (*AuthenticateEvent_Result)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[18].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[19].OneofWrappers = []any{ (*RefreshResponse_Credentials)(nil), (*RefreshResponse_Unsupported)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[27].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[28].OneofWrappers = []any{ (*CommandEvent_Stdout)(nil), (*CommandEvent_Stderr)(nil), (*CommandEvent_Exit)(nil), } - file_atmos_plugin_v1_plugin_proto_msgTypes[30].OneofWrappers = []any{ + file_atmos_plugin_v1_plugin_proto_msgTypes[31].OneofWrappers = []any{ (*ComponentValueStep_Attribute)(nil), (*ComponentValueStep_Index)(nil), } @@ -4531,8 +4772,8 @@ func file_atmos_plugin_v1_plugin_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_atmos_plugin_v1_plugin_proto_rawDesc), len(file_atmos_plugin_v1_plugin_proto_rawDesc)), - NumEnums: 3, - NumMessages: 63, + NumEnums: 4, + NumMessages: 65, NumExtensions: 0, NumServices: 8, }, diff --git a/tests/terragrunt_pro_test.go b/tests/terragrunt_pro_test.go new file mode 100644 index 00000000000..4d6a89513c1 --- /dev/null +++ b/tests/terragrunt_pro_test.go @@ -0,0 +1,429 @@ +package tests + +import ( + "archive/tar" + "bytes" + "encoding/json" + "errors" + "io" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "sync" + "testing" + "time" + + gogit "github.com/go-git/go-git/v5" + gitconfig "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// proRequest is one call the fake Atmos Pro server received. +type proRequest struct { + Method string + Path string + Query string + Body []byte +} + +// fakeAtmosPro records every request and acknowledges it the way the real API does. It is a +// stand-in for the Atmos Pro API: no request ever leaves the machine. +type fakeAtmosPro struct { + server *httptest.Server + mutex sync.Mutex + requests []proRequest +} + +func newFakeAtmosPro(t *testing.T) *fakeAtmosPro { + t.Helper() + fake := &fakeAtmosPro{} + fake.server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var body bytes.Buffer + _, _ = body.ReadFrom(r.Body) + fake.mutex.Lock() + fake.requests = append(fake.requests, proRequest{Method: r.Method, Path: r.URL.Path, Query: r.URL.RawQuery, Body: body.Bytes()}) + fake.mutex.Unlock() + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"success":true,"status":200}`)) + })) + t.Cleanup(fake.server.Close) + return fake +} + +// take returns and forgets the requests with the given method whose path ends with suffix. +func (f *fakeAtmosPro) take(method, suffix string) []proRequest { + f.mutex.Lock() + defer f.mutex.Unlock() + var matched, rest []proRequest + for _, request := range f.requests { + if request.Method == method && strings.HasSuffix(request.Path, suffix) { + matched = append(matched, request) + } else { + rest = append(rest, request) + } + } + f.requests = rest + return matched +} + +// terragruntProject is a throwaway Git repository with Terragrunt units, imported into stack "dev". +type terragruntProject struct { + t *testing.T + root string + repo *gogit.Repository + pro *fakeAtmosPro +} + +const proUnitModule = `variable "greeting" { + default = "unset" +} +resource "terraform_data" "unit" { + input = var.greeting +} +output "value" { + value = terraform_data.unit.output +} +` + +const proNetworkUnit = `terraform { source = "../../../modules/unit" } +remote_state { + backend = "local" + config = { path = "${get_terragrunt_dir()}/state/terraform.tfstate" } + generate = { path = "backend.tf", if_exists = "overwrite" } +} +inputs = { greeting = "network" } +` + +const proAppUnit = `terraform { + source = "../../../modules/unit" + extra_arguments "vars" { + commands = ["plan", "apply"] + required_var_files = ["${get_terragrunt_dir()}/app.tfvars"] + } +} +remote_state { + backend = "local" + config = { path = "${get_terragrunt_dir()}/state/terraform.tfstate" } + generate = { path = "backend.tf", if_exists = "overwrite" } +} +dependency "network" { + config_path = "../network" + mock_outputs = { value = "mock" } +} +inputs = { greeting = "app" } +` + +// buildTerragruntPluginPackage compiles the Terragrunt plugin from this checkout into a package +// directory and returns it. The plugin is its own Go module; the package needs the manifest, +// its schemas, and the executable for this platform. +func buildTerragruntPluginPackage(t *testing.T) string { + t.Helper() + source := filepath.Join(repoRoot, "plugins", "terragrunt") + pkg := t.TempDir() + for _, name := range []string{"plugin.yaml"} { + data, err := os.ReadFile(filepath.Join(source, name)) + require.NoError(t, err) + require.NoError(t, os.WriteFile(filepath.Join(pkg, name), data, 0o644)) + } + schemas, err := filepath.Glob(filepath.Join(source, "schemas", "*")) + require.NoError(t, err) + require.Positive(t, len(schemas), "the plugin ships its configuration schema") + require.NoError(t, os.MkdirAll(filepath.Join(pkg, "schemas"), 0o755)) + for _, schema := range schemas { + data, err := os.ReadFile(schema) + require.NoError(t, err) + require.NoError(t, os.WriteFile(filepath.Join(pkg, "schemas", filepath.Base(schema)), data, 0o644)) + } + executable := "plugin" + if runtime.GOOS == "windows" { + executable += ".exe" + } + output := filepath.Join(pkg, "bin", runtime.GOOS+"-"+runtime.GOARCH, executable) + build := exec.Command("go", "build", "-o", output, ".") + build.Dir = source + build.Env = append(os.Environ(), "CGO_ENABLED=0") + if combined, err := build.CombinedOutput(); err != nil { + t.Skipf("cannot build the Terragrunt plugin: %v\n%s", err, combined) + } + return pkg +} + +func newTerragruntProject(t *testing.T, pluginPackage string, pro *fakeAtmosPro) *terragruntProject { + t.Helper() + root := t.TempDir() + project := &terragruntProject{t: t, root: root, pro: pro} + tofu := RequireTofuPath(t) + project.write("atmos.yaml", `base_path: "." +settings: + pro: + base_url: `+pro.server.URL+` + endpoint: api/v1 + token: test-token +components: + terraform: + base_path: components/terraform + command: `+filepath.ToSlash(tofu)+` + terragrunt: + enabled: true + mode: native + discovery: + enabled: false +plugins: + packages: + terragrunt: + path: `+filepath.ToSlash(pluginPackage)+` +stacks: + base_path: stacks + included_paths: ["*.yaml"] +`) + project.write("modules/unit/main.tf", proUnitModule) + project.write("live/dev/network/terragrunt.hcl", proNetworkUnit) + project.write("live/dev/app/terragrunt.hcl", proAppUnit) + project.write("live/dev/app/app.tfvars", "greeting = \"from-file\"\n") + // A unit carries no vars, labels, or settings of its own; the stack that imports it supplies + // them, and it is where Atmos Pro enablement for a unit is declared. + project.write("stacks/dev.yaml", `import: + - terragrunt://live/dev +components: + terraform: + app: + settings: + pro: + enabled: true + drift_detection: + enabled: true +`) + repo, err := gogit.PlainInit(root, false) + require.NoError(t, err) + project.repo = repo + _, err = repo.CreateRemote(&gitconfig.RemoteConfig{Name: "origin", URLs: []string{"https://github.com/acme/infra.git"}}) + require.NoError(t, err) + project.commit("initial units") + return project +} + +func (p *terragruntProject) write(path, content string) { + p.t.Helper() + target := filepath.Join(p.root, filepath.FromSlash(path)) + require.NoError(p.t, os.MkdirAll(filepath.Dir(target), 0o755)) + require.NoError(p.t, os.WriteFile(target, []byte(content), 0o644)) +} + +func (p *terragruntProject) head() string { + p.t.Helper() + ref, err := p.repo.Head() + require.NoError(p.t, err) + return ref.Hash().String() +} + +func (p *terragruntProject) commit(message string) { + p.t.Helper() + worktree, err := p.repo.Worktree() + require.NoError(p.t, err) + require.NoError(p.t, worktree.AddWithOptions(&gogit.AddOptions{All: true})) + _, err = worktree.Commit(message, &gogit.CommitOptions{Author: &object.Signature{Name: "Test", Email: "test@example.invalid", When: time.Now()}}) + require.NoError(p.t, err) +} + +// atmos runs the CLI built from this checkout in the project and returns its stdout and stderr. +func (p *terragruntProject) atmos(args ...string) (string, string, error) { + p.t.Helper() + cmd := atmosRunner.Command(args...) + cmd.Dir = p.root + cmd.Env = append(cmd.Env, "NO_COLOR=1", "ATMOS_TELEMETRY_ENABLED=false", "TF_IN_AUTOMATION=true") + var stdout, stderr bytes.Buffer + cmd.Stdout, cmd.Stderr = &stdout, &stderr + err := cmd.Run() + return stdout.String(), stderr.String(), err +} + +// exitCode returns the process exit code of a finished command, or -1 when it did not exit normally. +func exitCode(err error) int { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + return exitErr.ExitCode() + } + if err == nil { + return 0 + } + return -1 +} + +func (p *terragruntProject) mustAtmos(args ...string) { + p.t.Helper() + stdout, stderr, err := p.atmos(args...) + require.NoError(p.t, err, "atmos %s:\n%s\n%s", strings.Join(args, " "), stdout, stderr) +} + +// affectedUpload runs `describe affected --upload` against base and returns the component names that +// reached Atmos Pro, with the dependents of each. +func (p *terragruntProject) affectedUpload(base string) map[string][]string { + p.t.Helper() + p.mustAtmos("describe", "affected", "--upload", "--base", base) + posted := p.pro.take(http.MethodPost, "/affected-stacks") + require.Len(p.t, posted, 1, "exactly one affected-stacks upload") + var payload struct { + Stacks []struct { + Component string `json:"component"` + Stack string `json:"stack"` + Dependents []struct { + Component string `json:"component"` + Stack string `json:"stack"` + } `json:"dependents"` + } `json:"stacks"` + } + require.NoError(p.t, json.Unmarshal(posted[0].Body, &payload)) + result := map[string][]string{} + for _, stack := range payload.Stacks { + assert.Equal(p.t, "dev", stack.Stack) + dependents := []string{} + for _, dependent := range stack.Dependents { + dependents = append(dependents, dependent.Component) + } + result[stack.Component] = dependents + } + return result +} + +// TestTerragruntUnitsAreOrdinaryAtmosProInstances proves, with the real CLI, real OpenTofu, and a +// fake Atmos Pro API, that native Terragrunt units reach Atmos Pro as ordinary Terraform components. +func TestTerragruntUnitsAreOrdinaryAtmosProInstances(t *testing.T) { + if testing.Short() { + t.Skip("builds the Terragrunt plugin and runs OpenTofu") + } + ensureAtmosRunner(t) + pluginPackage := buildTerragruntPluginPackage(t) + pro := newFakeAtmosPro(t) + project := newTerragruntProject(t, pluginPackage, pro) + + t.Run("instance inventory lists units with component, stack, type and the settings.pro of their stack", func(t *testing.T) { + project.mustAtmos("list", "instances", "--upload") + posted := pro.take(http.MethodPost, "/instances") + require.Len(t, posted, 1) + var payload struct { + Instances []struct { + Component string `json:"component"` + Stack string `json:"stack"` + ComponentType string `json:"component_type"` + Settings map[string]any `json:"settings"` + } `json:"instances"` + } + require.NoError(t, json.Unmarshal(posted[0].Body, &payload)) + byComponent := map[string]map[string]any{} + for _, instance := range payload.Instances { + assert.Equal(t, "dev", instance.Stack) + assert.Equal(t, "terraform", instance.ComponentType, "a unit is an ordinary Terraform component") + byComponent[instance.Component] = instance.Settings + } + require.Contains(t, byComponent, "app") + require.Contains(t, byComponent, "network") + assert.Equal(t, map[string]any{"pro": map[string]any{"enabled": true, "drift_detection": map[string]any{"enabled": true}}}, byComponent["app"], + "settings.pro declared by the importing stack enables Atmos Pro for the unit") + assert.NotContains(t, byComponent["network"], "pro", "a unit the stack does not enable carries no Atmos Pro settings") + }) + + // Each case commits one change and asks which components Atmos Pro is told about, relative to the commit before it. + change := func(path, content, message string) map[string][]string { + base := project.head() + project.write(path, content) + project.commit(message) + return project.affectedUpload(base) + } + + t.Run("a changed unit selects it", func(t *testing.T) { + assert.Equal(t, map[string][]string{"app": {}}, change("live/dev/app/terragrunt.hcl", proAppUnit+"# reviewed change\n", "change app unit")) + }) + + t.Run("a changed dependency selects its dependents and the upload carries the relation", func(t *testing.T) { + affected := change("live/dev/network/terragrunt.hcl", proNetworkUnit+"# reviewed change\n", "change network unit") + assert.Equal(t, []string{"app"}, affected["network"]) + }) + + t.Run("a changed module file selects every unit that uses the module", func(t *testing.T) { + affected := change("modules/unit/main.tf", proUnitModule+"# changed\n", "change module") + assert.Contains(t, affected, "app") + assert.Contains(t, affected, "network") + }) + + t.Run("a changed extra_arguments var file selects the unit that reads it", func(t *testing.T) { + assert.Equal(t, map[string][]string{"app": {}}, change("live/dev/app/app.tfvars", "greeting = \"changed-file\"\n", "change var file")) + }) + + t.Run("the CI plan artifact of a unit carries its plan record", func(t *testing.T) { + testPlanArtifactCarriesThePlanRecord(t, pluginPackage) + }) + + t.Run("planning and applying one unit reports its status like any component", func(t *testing.T) { + // --upload-status makes plan report changes through its exit code, exactly as for ordinary components. + _, planErr, err := project.atmos("terraform", "plan", "app", "-s", "dev", "--upload-status") + require.Equal(t, 2, exitCode(err), planErr) + plan := pro.take(http.MethodPatch, "/instances") + require.Len(t, plan, 1, "one status upload for the planned unit") + assert.Equal(t, http.MethodPatch, plan[0].Method) + assert.Equal(t, "/api/v1/repos/acme/infra/instances", plan[0].Path) + assert.Equal(t, "stack=dev&component=app", plan[0].Query) + assert.JSONEq(t, `{"command":"plan","exit_code":2}`, statusBody(t, plan[0].Body)) + + project.mustAtmos("terraform", "apply", "app", "-s", "dev", "--upload-status", "--", "-auto-approve") + apply := pro.take(http.MethodPatch, "/instances") + require.Len(t, apply, 1) + assert.Equal(t, "stack=dev&component=app", apply[0].Query) + assert.JSONEq(t, `{"command":"apply","exit_code":0}`, statusBody(t, apply[0].Body)) + + // A unit whose stack does not enable Atmos Pro uploads nothing. + _, _, err = project.atmos("terraform", "plan", "network", "-s", "dev", "--upload-status") + require.Contains(t, []int{0, 2}, exitCode(err)) + assert.Empty(t, pro.take(http.MethodPatch, "/instances"), "Atmos Pro is enabled per component by settings.pro.enabled") + }) +} + +// testPlanArtifactCarriesThePlanRecord checks that the CI plan store receives the record that lets +// another runner verify a unit's plan, next to the plan itself. +func testPlanArtifactCarriesThePlanRecord(t *testing.T, pluginPackage string) { + t.Helper() + project := newTerragruntProject(t, pluginPackage, newFakeAtmosPro(t)) + store := t.TempDir() + config, err := os.ReadFile(filepath.Join(project.root, "atmos.yaml")) + require.NoError(t, err) + config = bytes.Replace(config, []byte(" command: "), []byte(" planfiles:\n default: local\n stores:\n local:\n type: local/dir\n options:\n path: "+filepath.ToSlash(store)+"\n command: "), 1) + project.write("atmos.yaml", string(config)+"ci:\n enabled: true\n") + + _, stderr, err := project.atmos("terraform", "plan", "app", "-s", "dev", "--ci") + require.NoError(t, err, stderr) + + bundles, err := filepath.Glob(filepath.Join(store, "dev", "app", "*.tfplan.tar")) + require.NoError(t, err) + require.Len(t, bundles, 1, "one planfile bundle for the unit in the CI plan store") + file, err := os.Open(bundles[0]) + require.NoError(t, err) + defer file.Close() + var names []string + reader := tar.NewReader(file) + for { + header, nextErr := reader.Next() + if errors.Is(nextErr, io.EOF) { + break + } + require.NoError(t, nextErr) + names = append(names, header.Name) + } + assert.Contains(t, names, "plan.tfplan") + assert.Contains(t, names, "plan.tfplan.atmos.json", "the record that lets another runner verify the plan travels with it") +} + +// statusBody keeps the stable fields of a status upload (the request also carries a timestamp). +func statusBody(t *testing.T, body []byte) string { + t.Helper() + var payload map[string]any + require.NoError(t, json.Unmarshal(body, &payload)) + kept := map[string]any{"command": payload["command"], "exit_code": payload["exit_code"]} + data, err := json.Marshal(kept) + require.NoError(t, err) + return string(data) +} diff --git a/website/blog/2026-10-29-native-terragrunt-compatibility.mdx b/website/blog/2026-10-29-native-terragrunt-compatibility.mdx index 1d3240d8054..cb6c6b65dda 100644 --- a/website/blog/2026-10-29-native-terragrunt-compatibility.mdx +++ b/website/blog/2026-10-29-native-terragrunt-compatibility.mdx @@ -106,12 +106,22 @@ Units that rely on `before_hook`, `after_hook`, `error_hook`, or `extra_argument ## Apply the plan you reviewed -After `atmos terraform plan`, `atmos terraform apply --from-plan` applies that exact plan. Atmos rejects the apply if the plan file, the unit's configuration, or the working directory changed in between. The original working directory must still exist, so this does not yet cover applying a plan on a different runner. +After `atmos terraform plan`, `atmos terraform apply --from-plan` applies that exact plan. Atmos rejects the apply if the plan file, the unit's configuration, or the working directory changed in between. + +The same flow works across runners, which is how Atmos Pro plans on one runner and applies on another. `atmos terraform planfile upload` publishes the plan together with its record. On the next runner, `atmos terraform planfile download` and `atmos terraform apply --from-plan` re-provision the working directory from the checkout, verify it against the reviewed plan, and apply exactly that plan. + +## The settings Terragrunt users already rely on + +`terraform_binary`, `errors` retry and ignore policies, `exclude`, feature flags, `iam_role` and web identity tokens, `remote_state` encryption, `tfr://` registry sources, and the `read-config` and `init-from-module` hook lifecycles all run natively. Atmos assumes IAM roles in process on top of the identity you already use, applies retry and ignore policies around each Terraform step, and names every unit an `exclude` block skips. Functions such as `get_aws_account_id()` use the same identity as the rest of the run. + +## Atmos Pro and executable mode + +Units are ordinary Terraform components to Atmos Pro: `atmos describe affected --upload` and `atmos list instances --upload` report them, and you can plan and apply one unit at a time. Teams that want to keep Terragrunt itself as the engine can set `mode: executable`, and Atmos still orders the units and supplies authentication, the toolchain, and the environment for each `terragrunt run`. ## Compatibility is explicit -Native mode evaluates HCL through Terragrunt Go modules and executes through Atmos. It does not call the Terragrunt executable or silently fall back to it. Unsupported behavior produces an error before infrastructure execution: for example `terraform_binary`, `errors` and `exclude` blocks, feature flags, IAM role settings, and the `read-config` and `init-from-module` hook lifecycles. +Native mode evaluates HCL through Terragrunt Go modules and executes through Atmos. It does not call the Terragrunt executable or silently fall back to it. Unsupported behavior produces an error before infrastructure execution, and the error names the unit, the file, and the setting. -The package remains experimental. Real cloud provisioning, remote-runner plan relocation, and live Pro integration require their own acceptance evidence. Local fixture results do not establish a compatibility percentage. +The package remains experimental. Local fixture results do not establish a compatibility percentage, and real cloud provisioning needs its own acceptance evidence. See the [Terragrunt migration guide](/migration/terragrunt), [plugin usage](/cli/commands/plugin/usage), and [instance listing](/cli/commands/list/list-instances). diff --git a/website/docs/cli/commands/plugin/pack.mdx b/website/docs/cli/commands/plugin/pack.mdx index 46eda216e19..4e3689b4f3f 100644 --- a/website/docs/cli/commands/plugin/pack.mdx +++ b/website/docs/cli/commands/plugin/pack.mdx @@ -60,6 +60,11 @@ and run conformance on native runners before publishing. Native-header validatio OS and architecture; it does not prove CPU instruction-set requirements or external library compatibility. Publishers are responsible for testing the variants they declare. +Every packed release also records the package title, description, and version as the +`org.opencontainers.image.title`, `.description`, and `.version` annotations, so registries can +show them. Publishing to a private registry never requires making the package public; public +visibility is a publisher's choice (see [`--verify-public`](/cli/commands/plugin/publish)). + ## Arguments and flags
@@ -67,6 +72,8 @@ compatibility. Publishers are responsible for testing the variants they declare.
Package directory; defaults to the current directory.
--output, -o
New destination directory for the OCI layout. Every declared platform must already be compiled.
+
--source
+
Repository URL recorded as the org.opencontainers.image.source annotation, which registries such as GHCR use to link the package to its repository. Defaults to metadata.repository in plugin.yaml when that is an https URL. Pass github-actions to derive it from GITHUB_SERVER_URL and GITHUB_REPOSITORY. URLs with credentials, a query string, or a fragment are rejected, and nothing is derived from the environment unless requested. Also configurable with ATMOS_PLUGIN_SOURCE.
--format
Output format: table (default), json, yaml, csv, or tsv. Also configurable with ATMOS_PLUGIN_FORMAT.
diff --git a/website/docs/cli/commands/plugin/publish.mdx b/website/docs/cli/commands/plugin/publish.mdx index 583c086ec41..de355d169dd 100644 --- a/website/docs/cli/commands/plugin/publish.mdx +++ b/website/docs/cli/commands/plugin/publish.mdx @@ -52,7 +52,8 @@ published releases are immutable.
--verify-public
After upload and any requested signing, anonymously download and verify the published digest and every platform payload. Disabled by default so private registries remain supported. This checks access; - it does not change registry visibility. Verification failure returns an error and leaves the upload intact.
+ it does not change registry visibility. Verification failure returns an error and leaves the upload intact. + Opt-in: publishing to a private registry or a private package needs no public visibility, so leave it off for internal plugins.
--cosign-version
Exact managed Cosign 3 version used with --sign. Defaults to 3.1.3. Requires --sign; without it the command fails instead of ignoring the flag.
diff --git a/website/docs/cli/commands/plugin/release.mdx b/website/docs/cli/commands/plugin/release.mdx index 6ad90c9b37e..8c2af47d0c3 100644 --- a/website/docs/cli/commands/plugin/release.mdx +++ b/website/docs/cli/commands/plugin/release.mdx @@ -60,6 +60,8 @@ in the protected release job.
--verify-public
After upload and any requested signing, verify anonymous access to the published digest and complete OCI graph. Disabled by default. Does not change registry visibility; a failed check leaves the upload intact.
+
--source
+
Repository URL recorded as the org.opencontainers.image.source annotation so registries such as GHCR link the package to its repository. Defaults to metadata.repository in plugin.yaml; pass github-actions to derive it from GITHUB_SERVER_URL and GITHUB_REPOSITORY. See plugin pack.
--format
Publication output format: table (default), json, yaml, csv, or tsv.
diff --git a/website/docs/migration/terragrunt.mdx b/website/docs/migration/terragrunt.mdx index ecfecdb9b16..d1804b46ba8 100644 --- a/website/docs/migration/terragrunt.mdx +++ b/website/docs/migration/terragrunt.mdx @@ -1067,6 +1067,28 @@ Atmos follows the same rules as Terragrunt v1.2.1, whose symlink support is an o - `remote_state.encryption` is written to the file that `remote_state.generate` creates, as an OpenTofu `encryption` block, so it requires OpenTofu. Any OpenTofu key provider works, for example `pbkdf2`, `aws_kms`, or `gcp_kms`. Without `generate` it has no effect, as in Terragrunt, and Atmos warns. `remote_state.disable_init` is accepted: Terragrunt uses it only to skip creating backend resources, Atmos never creates them, and OpenTofu initializes the backend as usual. - `tfr://` module sources are resolved when a unit is prepared, using the Terraform module registry protocol. `?version=` pins an exact version, the `terraform { version }` constraint selects among published versions, and with neither the latest stable release is used. Private registries authenticate with `TF_TOKEN_`, a `credentials` block in the CLI configuration, or `TG_TF_REGISTRY_TOKEN`. A `//subdir` selects a directory inside the module. +### Credentials, values, and logs + +- Terragrunt functions that call AWS, such as `get_aws_account_id()`, and S3 dependency state reads use the identity of the Atmos invocation: its profile, shared credentials and config files, web identity token file, static keys, and `AWS_ENDPOINT_URL` or `AWS_ENDPOINT_URL_` overrides. `TG_IAM_ASSUME_ROLE` applies on top. An Atmos identity takes precedence over a `profile` set in a `remote_state` block. +- Unit inputs reach OpenTofu with their exact numeric values and with null preserved. An input written as `sensitive(...)`, directly or through a local, an object literal, or `merge()`, is masked in all output and logs, kept out of the generated variable file, and passed to OpenTofu through a `TF_VAR_` environment variable. +- Terragrunt's own log events are hidden by default. With `--logs-level=Debug` or `Trace`, or `ATMOS_LOGS_LEVEL`, Atmos prints them on stderr with the plugin, component, and stack, with secrets masked. They never change a command's output or exit code. A warning about a unit is shown once per command. + +### Flags + +Options a configuration provider declares in its package metadata appear as flags on the `atmos terraform` commands that accept them, under a section named for the provider. A flag follows the order command line, then environment, then `atmos.yaml`, then the declared default, and a value you leave unset is never sent. Provider flags cannot reuse a flag Atmos owns. + +The Terragrunt provider adds `--terragrunt-feature name=value` (repeatable, also `ATMOS_TERRAGRUNT_FEATURE` and `TG_FEATURE`), `--terragrunt-iam-assume-role`, `--terragrunt-iam-assume-role-duration`, `--terragrunt-iam-assume-role-session-name`, `--terragrunt-iam-assume-role-web-identity-token`, and `--terragrunt-download-dir`. The token is never written to configuration or printed. A saved plan is bound to the provider options it was created with: apply it with the same options, or create a new plan. + +### Atmos Pro + +Terragrunt units are ordinary Terraform components to Atmos Pro: `atmos describe affected --upload` and `atmos list instances --upload` report them by component and stack, and a unit joins Atmos Pro when the stack that imports it sets `settings.pro.enabled: true`. + +To plan one unit on one runner and apply it on another, run `atmos terraform plan` followed by `atmos terraform planfile upload`, which publishes the plan and its record together. On the next runner, `atmos terraform planfile download` followed by `atmos terraform apply --from-plan` re-provisions the working directory from the checkout, verifies it against the reviewed plan, and applies exactly that plan. With an absolute `base_path`, the checkout must be at the same absolute path on both runners. + +### Executable mode + +Set `components.terraform.terragrunt.mode: executable` to keep Terragrunt itself as the engine while Atmos still discovers and orders units, authenticates, resolves the toolchain and environment, and runs one pinned `terragrunt run` per unit. Pin Terragrunt 1.0.0 or newer in `.tool-versions` or `dependencies.tools`. Hooks, `errors`, `exclude`, and IAM roles are Terragrunt's own in this mode. Atmos-managed saved plans, stack `vars` and `providers` overrides, and `terraform shell` are not available, and `--all` is scheduled by Atmos, not by `terragrunt run --all`. A project is either native or executable, never both, and native mode never falls back to the executable. + ### What it does not support yet ### What it does not support yet @@ -1077,7 +1099,7 @@ Unsupported settings fail before any infrastructure command runs, with an error - Output dependencies in a non-default workspace during discovery. - Stack-level overrides of a unit's `backend`, `backend_type`, `metadata.component`, or `source.uri`, because they would change state identity. Edit the unit's `remote_state` instead. -Terragrunt's built-in default retry list for transient errors, the `--no-auto-retry` flag, and `errors` handling around `read-config` hooks are not implemented; use `settings.retry` or an `errors` block. Discovery runs without side effects, so a unit whose `locals` call `run_cmd` cannot be discovered. +Terragrunt's built-in default retry list for transient errors, the `--no-auto-retry` flag, and `errors` handling around `read-config` hooks are not implemented; use `settings.retry` or an `errors` block. `atmos terraform deploy` verification of a stored plan on a fresh runner is not supported; use `planfile download` and `apply --from-plan`. Discovery runs without side effects, so a unit whose `locals` call `run_cmd` cannot be discovered. ## Migration Steps From bfa6850b3b81241012fcd992c50fe6e360bd8ecb Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sat, 31 Oct 2026 18:48:29 -0500 Subject: [PATCH 02/75] refactor(terraform): split component execution preparation and export validation into named steps Extract prepareConfigurationPhase, prepareComponentDirectory, nameFiles, and resolveExecutionToolchain from prepareComponentExecution, and componentExportSchema from ValidateComponent, so each stays within the complexity budget. --- pkg/component/terraform/execute_pipeline.go | 131 +++++++++++++------- pkg/plugin/extension/component.go | 36 ++++-- 2 files changed, 109 insertions(+), 58 deletions(-) diff --git a/pkg/component/terraform/execute_pipeline.go b/pkg/component/terraform/execute_pipeline.go index 4de1c5bd204..ede8635ce64 100644 --- a/pkg/component/terraform/execute_pipeline.go +++ b/pkg/component/terraform/execute_pipeline.go @@ -48,6 +48,47 @@ func (e *Executor) prepareComponentExecution( atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, shouldProcess bool, +) (*componentExecContext, error) { + execCtx, err := e.prepareConfigurationPhase(ctx, atmosConfig, info, shouldProcess) + if err != nil { + return nil, err + } + + execCtx.componentPath, err = e.prepareComponentDirectory(ctx, writers, atmosConfig, info, execCtx) + if err != nil { + return nil, err + } + + if err = checkComponentRestrictions(info); err != nil { + return nil, err + } + + if execCtx.tenv, err = resolveExecutionToolchain(atmosConfig, info, execCtx.tenv, shouldProcess); err != nil { + return nil, err + } + execCtx.nameFiles(atmosConfig, info) + + if err = e.runPreExecutionSteps(atmosConfig, info, execCtx.workingDir, execCtx.tenv); err != nil { + return nil, err + } + // Execution has now written its own files, so the directory is complete and must equal the reviewed one. + if execCtx.rebuild != nil { + if err = execCtx.rebuild.verify(execCtx.workingDir); err != nil { + return nil, err + } + } + + return execCtx, nil +} + +// prepareConfigurationPhase checks the Terraform configuration, evaluates the configuration provider, +// skips excluded components, and runs the read-config hooks. The returned context carries the prepared +// configuration, the toolchain environment the provider needed, and the reviewed-plan rebuild when one is pending. +func (e *Executor) prepareConfigurationPhase( + ctx context.Context, + atmosConfig *schema.AtmosConfiguration, + info *schema.ConfigAndStacksInfo, + shouldProcess bool, ) (*componentExecContext, error) { if err := checkTerraformConfig(*atmosConfig); err != nil { return nil, err @@ -69,71 +110,71 @@ func (e *Executor) prepareComponentExecution( if err = e.runReadConfigHooks(ctx, atmosConfig, info, prepared); err != nil { return nil, err } + return &componentExecContext{preparedConfiguration: prepared, tenv: tenv, rebuild: rebuild}, nil +} +// resolveExecutionToolchain installs the toolchain dependencies when none were resolved while the +// configuration was prepared, and points the command at the resolved executable. +func resolveExecutionToolchain( + atmosConfig *schema.AtmosConfiguration, + info *schema.ConfigAndStacksInfo, + tenv *dependencies.ToolchainEnvironment, + shouldProcess bool, +) (*dependencies.ToolchainEnvironment, error) { + if !shouldProcess || tenv != nil { + return tenv, nil + } + tenv, err := resolveAndInstallToolchainDeps(atmosConfig, info) + if err != nil { + return nil, err + } + info.Command = tenv.Resolve(info.Command) + return tenv, nil +} + +// prepareComponentDirectory resolves the directory the component runs in, provisioning or rebuilding it +// when needed, and writes the files the configuration provider generated into it. +func (e *Executor) prepareComponentDirectory( + ctx context.Context, + writers provisioner.OutputWriters, + atmosConfig *schema.AtmosConfiguration, + info *schema.ConfigAndStacksInfo, + execCtx *componentExecContext, +) (string, error) { + prepared, rebuild := execCtx.preparedConfiguration, execCtx.rebuild var componentPath string + var err error switch { case rebuild != nil: // The plan was restored without its workdir: provision it again and prove it equals the reviewed one. componentPath, err = e.rebuildReviewedWorkdir(ctx, writers, atmosConfig, info, rebuild) - if err != nil { - return nil, err - } case prepared != nil && usesConfigurationPlan(info): // A reviewed plan uses the retained workdir; provisioning could replace its modules. componentPath = ConstructTerraformComponentWorkingDir(atmosConfig, info) default: componentPath, err = e.resolveAndProvisionComponentPath(ctx, writers, atmosConfig, info) - if err != nil { - return nil, err - } + } + if err != nil { + return "", err } if prepared != nil && !info.DryRun { if err := configuration.WriteFiles(componentPath, prepared.Files); err != nil { - return nil, fmt.Errorf("component %s in stack %s, working directory %s: %w", info.ComponentFromArg, info.Stack, componentPath, err) + return "", fmt.Errorf("component %s in stack %s, working directory %s: %w", info.ComponentFromArg, info.Stack, componentPath, err) } } + return componentPath, nil +} - if err = checkComponentRestrictions(info); err != nil { - return nil, err - } - - if shouldProcess && tenv == nil { - tenv, err = resolveAndInstallToolchainDeps(atmosConfig, info) - if err != nil { - return nil, err - } - info.Command = tenv.Resolve(info.Command) - } - - varFile := ConstructTerraformComponentVarfileName(info) - testVarFile := "" +// nameFiles sets the variable, test variable, and plan files and the working directory of a component. +func (c *componentExecContext) nameFiles(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo) { + c.testVarFile = "" if hasTerraformTestVars(info) { - testVarFile = ConstructTerraformComponentTestVarfileName(info) + c.testVarFile = ConstructTerraformComponentTestVarfileName(info) } - planFile := ConstructTerraformComponentPlanfileName(info) - workingDir := ConstructTerraformComponentWorkingDir(atmosConfig, info) - - if err = e.runPreExecutionSteps(atmosConfig, info, workingDir, tenv); err != nil { - return nil, err - } - // Execution has now written its own files, so the directory is complete and must equal the reviewed one. - if rebuild != nil { - if err = rebuild.verify(workingDir); err != nil { - return nil, err - } - } - - return &componentExecContext{ - preparedConfiguration: prepared, - componentPath: componentPath, - varFile: varFile, - testVarFile: testVarFile, - planFile: planFile, - workingDir: workingDir, - tenv: tenv, - rebuild: rebuild, - }, nil + c.varFile = ConstructTerraformComponentVarfileName(info) + c.planFile = ConstructTerraformComponentPlanfileName(info) + c.workingDir = ConstructTerraformComponentWorkingDir(atmosConfig, info) } // runPreExecutionSteps performs validation, auth pre-hook, config file generation, diff --git a/pkg/plugin/extension/component.go b/pkg/plugin/extension/component.go index ce26368dab4..dee31ee480e 100644 --- a/pkg/plugin/extension/component.go +++ b/pkg/plugin/extension/component.go @@ -30,18 +30,9 @@ func IsComponent(capability string) bool { func ValidateComponent(binding Binding) error { defer perf.Track(nil, "extension.ValidateComponent")() - for key := range binding.Metadata { - if key != "component_type" && key != "schema" && key != "modes" && key != "options" { - return invalidMetadata("Unsupported component configuration export metadata.", "Declare only `component_type`, `schema`, `modes`, and `options` for this contract version.") - } - } - componentType, ok := binding.Metadata["component_type"].(string) - if !ok || componentType == "" || strings.TrimSpace(componentType) != componentType { - return invalidMetadata("The configuration export has no valid `component_type`.", "Name the component family it supplies, for example `terraform`.") - } - schemaPath, ok := binding.Metadata["schema"].(string) - if !ok { - return invalidMetadata("The configuration export has no `schema` path.", "Declare a package-local JSON Schema for provider settings.") + schemaPath, err := componentExportSchema(binding.Metadata) + if err != nil { + return err } if _, err := CompileSchema(binding.Directory, schemaPath); err != nil { return err @@ -49,10 +40,29 @@ func ValidateComponent(binding Binding) error { if _, err := ComponentModes(binding.Metadata); err != nil { return err } - _, err := provideroptions.Parse(binding.Name, binding.Metadata["options"]) + _, err = provideroptions.Parse(binding.Name, binding.Metadata["options"]) return err } +// componentExportSchema checks the metadata keys and the `component_type` of a configuration export +// and returns the package-local path of its provider-settings schema. +func componentExportSchema(metadata map[string]any) (string, error) { + for key := range metadata { + if key != "component_type" && key != "schema" && key != "modes" && key != "options" { + return "", invalidMetadata("Unsupported component configuration export metadata.", "Declare only `component_type`, `schema`, `modes`, and `options` for this contract version.") + } + } + componentType, ok := metadata["component_type"].(string) + if !ok || componentType == "" || strings.TrimSpace(componentType) != componentType { + return "", invalidMetadata("The configuration export has no valid `component_type`.", "Name the component family it supplies, for example `terraform`.") + } + schemaPath, ok := metadata["schema"].(string) + if !ok { + return "", invalidMetadata("The configuration export has no `schema` path.", "Declare a package-local JSON Schema for provider settings.") + } + return schemaPath, nil +} + // ComponentModes returns the execution modes a configuration export declares. An export that declares // none supports only the native mode. func ComponentModes(metadata map[string]any) ([]string, error) { From 16fc492f910ac8ea1d5057b875109258090e71f7 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sun, 1 Nov 2026 09:22:49 -0600 Subject: [PATCH 03/75] fix(terragrunt): make the integration layer's tests and fixtures platform-neutral - Strip escape sequences before asserting on the provider flag help. - Recognize the Terragrunt probe name regardless of case and extension. - Normalize recorded working directories to slashes in the executable-mode scenarios. - Build Pro fixture paths with forward slashes only. Co-Authored-By: Claude Sonnet 5.5 --- cmd/help_template_test.go | 3 ++- plugins/terragrunt/fixtures/toolprobe/main.go | 9 +++++++- .../fixtures/toolprobe/main_test.go | 21 +++++++++++++++++++ plugins/terragrunt/scripts/modes.star | 13 ++++++++---- tests/terragrunt_pro_test.go | 10 ++++++--- 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 plugins/terragrunt/fixtures/toolprobe/main_test.go diff --git a/cmd/help_template_test.go b/cmd/help_template_test.go index 51322cd661e..02c37dbc8db 100644 --- a/cmd/help_template_test.go +++ b/cmd/help_template_test.go @@ -1443,7 +1443,8 @@ func TestPrintFlagsGroupsProviderFlagsUnderTheirProvider(t *testing.T) { var buf bytes.Buffer styles := createHelpStyles(lipgloss.NewRenderer(&buf)) printFlags(&buf, plan, &schema.AtmosConfiguration{}, &styles) - output := buf.String() + // Runners advertise color, and styling splits words with escape sequences; assert on the text. + output := ansi.Strip(buf.String()) flags, providerFlags, found := strings.Cut(output, "TOOL FLAGS") if !found { diff --git a/plugins/terragrunt/fixtures/toolprobe/main.go b/plugins/terragrunt/fixtures/toolprobe/main.go index ae7405e423b..103461930dc 100644 --- a/plugins/terragrunt/fixtures/toolprobe/main.go +++ b/plugins/terragrunt/fixtures/toolprobe/main.go @@ -38,7 +38,7 @@ func run() int { if err != nil { return fail(err) } - if strings.TrimSuffix(filepath.Base(self), ".exe") == "terragrunt" { + if answersAsTerragrunt(self) { return terragrunt(directory, strings.TrimSpace(string(real)), os.Args[1:]) } if err := record(filepath.Join(directory, "invocations.log"), os.Args[1:]); err != nil { @@ -47,6 +47,13 @@ func run() int { return execute(strings.TrimSpace(string(real)), "", os.Args[1:]) } +// answersAsTerragrunt reports whether the probe was launched under the Terragrunt executable name. Windows +// resolves the extension as spelled in PATHEXT and file names are case-insensitive there, so "terragrunt.EXE" +// must match too. +func answersAsTerragrunt(self string) bool { + return strings.EqualFold(strings.TrimSuffix(strings.ToLower(filepath.Base(self)), ".exe"), "terragrunt") +} + // execute runs the real tool with the process streams. func execute(tool, directory string, arguments []string) int { // The target is the path a test wrote beside this fixture, never external input. diff --git a/plugins/terragrunt/fixtures/toolprobe/main_test.go b/plugins/terragrunt/fixtures/toolprobe/main_test.go new file mode 100644 index 00000000000..3793d4a4f90 --- /dev/null +++ b/plugins/terragrunt/fixtures/toolprobe/main_test.go @@ -0,0 +1,21 @@ +package main + +import "testing" + +func TestAnswersAsTerragruntIgnoresCaseAndExtension(t *testing.T) { + for name, want := range map[string]bool{ + "terragrunt": true, + "terragrunt.exe": true, + "terragrunt.EXE": true, + "Terragrunt.Exe": true, + "tofu": false, + "tofu.exe": false, + "terragrunt-wrapper.exe": false, + "not-terragrunt": false, + "terragrunt.exe.bak": false, + } { + if got := answersAsTerragrunt(name); got != want { + t.Errorf("answersAsTerragrunt(%q) = %v, want %v", name, got, want) + } + } +} diff --git a/plugins/terragrunt/scripts/modes.star b/plugins/terragrunt/scripts/modes.star index 2754d79de60..425b9be24b0 100644 --- a/plugins/terragrunt/scripts/modes.star +++ b/plugins/terragrunt/scripts/modes.star @@ -236,10 +236,10 @@ def executable_invocation(): first = recorded[0] unit_dir = project.root + "/live/dev/app" fixtures.check(first.engine == ["plan", "-no-color"], "Unexpected engine command: " + str(first.engine)) - fixtures.check(first.before[0] == "--working-dir" and first.before[1].endswith("live/dev/app") and first.before[2] == "run", "Unexpected terragrunt arguments: " + str(first.before)) + fixtures.check(first.before[0] == "--working-dir" and slashes(first.before[1]).endswith("live/dev/app") and first.before[2] == "run", "Unexpected terragrunt arguments: " + str(first.before)) fixtures.check(first.env.get("TG_NON_INTERACTIVE") == "true", "Terragrunt was allowed to prompt: " + str(first.env)) fixtures.check(first.env.get("TG_TF_FORWARD_STDOUT") == "true", "Engine output was not forwarded untouched: " + str(first.env)) - fixtures.check(first.env.get("TG_TF_PATH", "").endswith(semantics.engine().rsplit("/", 1)[-1]), "Terragrunt did not run the Atmos-selected engine: " + str(first.env)) + fixtures.check(first.env.get("TG_TF_PATH", "").endswith(slashes(semantics.engine()).rsplit("/", 1)[-1]), "Terragrunt did not run the Atmos-selected engine: " + str(first.env)) # Native machinery never ran: no workdir, no generated varfile, no backend file written by Atmos. fixtures.check(not fs.exists(project.root + "/.workdir"), "Native provisioning ran for an executable unit") @@ -293,19 +293,24 @@ def executable_flags_and_config(): ui.success("Executable mode: provider flags and configured features become Terragrunt flags; secrets stay out of argv and output") +def slashes(path): + # Recorded working directories use the platform separator; compare them slash-separated. + return path.replace("\\", "/") + + def executable_ordering(): project = stand_in_project("atmos-terragrunt-exec-all-") write_stand_in_unit(project.root, "base") write_stand_in_unit(project.root, "app", dependencies=["base"]) result = semantics.run(project.root, ["terraform", "apply", "--all", "-s", STACK, "--", "-auto-approve", "-no-color"]) expect(result, "Apply complete", "apply --all") - order = [c.dir.rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "apply"] + order = [slashes(c.dir).rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "apply"] fixtures.check(order == ["base", "app"], "Dependencies were not applied first: " + str(order)) # Atmos schedules the units; Terragrunt never receives --all. for call in engine_calls(project): fixtures.check("--all" not in call.before and "--all" not in call.engine, "terragrunt run --all was used: " + str(call.before)) semantics.run(project.root, ["terraform", "destroy", "--all", "-s", STACK, "--", "-auto-approve", "-no-color"]) - order = [c.dir.rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "destroy"] + order = [slashes(c.dir).rsplit("/", 1)[-1] for c in engine_calls(project) if c.engine[0] == "destroy"] fixtures.check(order == ["app", "base"], "Destroy did not run in reverse dependency order: " + str(order)) ui.success("Executable mode: Atmos schedules units in dependency order, one terragrunt command each, never terragrunt run --all") diff --git a/tests/terragrunt_pro_test.go b/tests/terragrunt_pro_test.go index 4d6a89513c1..6def79bdc4e 100644 --- a/tests/terragrunt_pro_test.go +++ b/tests/terragrunt_pro_test.go @@ -91,10 +91,14 @@ output "value" { } ` +// The unit directory is spelled with forward slashes only. On Windows, get_terragrunt_dir() returns +// backslashes, and joining it with a slash-separated suffix would produce mixed separators. +const proUnitDir = `${replace(get_terragrunt_dir(), "\\", "/")}` + const proNetworkUnit = `terraform { source = "../../../modules/unit" } remote_state { backend = "local" - config = { path = "${get_terragrunt_dir()}/state/terraform.tfstate" } + config = { path = "` + proUnitDir + `/state/terraform.tfstate" } generate = { path = "backend.tf", if_exists = "overwrite" } } inputs = { greeting = "network" } @@ -104,12 +108,12 @@ const proAppUnit = `terraform { source = "../../../modules/unit" extra_arguments "vars" { commands = ["plan", "apply"] - required_var_files = ["${get_terragrunt_dir()}/app.tfvars"] + required_var_files = ["` + proUnitDir + `/app.tfvars"] } } remote_state { backend = "local" - config = { path = "${get_terragrunt_dir()}/state/terraform.tfstate" } + config = { path = "` + proUnitDir + `/state/terraform.tfstate" } generate = { path = "backend.tf", if_exists = "overwrite" } } dependency "network" { From 64f8e5f8665d9303f8ef0f7546e3a53104ce4bf6 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sun, 1 Nov 2026 09:54:53 -0600 Subject: [PATCH 04/75] test(terragrunt): match rejection reasons in the Pro scenario regardless of line wrapping The error text is wrapped to the terminal width, which split "no Atmos plan record" across two lines in one full integration run. Co-Authored-By: Claude Sonnet 5.5 --- plugins/terragrunt/scripts/pro.star | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/terragrunt/scripts/pro.star b/plugins/terragrunt/scripts/pro.star index ab4e35c7233..217120866c2 100644 --- a/plugins/terragrunt/scripts/pro.star +++ b/plugins/terragrunt/scripts/pro.star @@ -64,7 +64,8 @@ def restore_artifacts(root): def expect_rejected(root, reason, context): result = lifecycle.terraform(root, "apply", "planned", flags=["--from-plan"], failing=True) output = hardening.output_of(result) - fixtures.check(reason in output, "Expected '" + reason + "' for " + context + ":\n" + output) + # Error text is wrapped to the terminal width, which can split a phrase across lines. + fixtures.check(reason in " ".join(output.split()), "Expected '" + reason + "' for " + context + ":\n" + output) fixtures.check("Apply complete" not in output, "A plan was applied despite " + context) fixtures.check(not fs.exists(lifecycle.state_path(root, "planned")), context + " created state") From d7b62ffc457fe9629ff046b1a97f7a68fb5c1d4a Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Sun, 8 Nov 2026 16:15:07 -0600 Subject: [PATCH 05/75] fix(terragrunt): validate provider option declarations and resolve flags on compound commands Reject a non-boolean `sensitive` and a second declaration of one option name for the same command. Register provider flags as persistent on commands with Cobra children so `state rm` and `workspace select` honor them, and keep an explicitly empty ATMOS__