Skip to content

Deploy --target cloud still requires env vars from the unused deploy.server section #239

Description

@vsilent

Description

When a project defines both deploy.server (with host: ${EXISTING_SERVER_HOST}) and deploy.cloud, running stacker deploy --target cloud still fails if EXISTING_SERVER_HOST is not present in .env, even though the server section is never used for a cloud deploy.

Steps to Reproduce

# stacker.yml
deploy:
  target: server
  server:
    host: ${EXISTING_SERVER_HOST}
    user: ${EXISTING_SERVER_USER}
    ssh_key: ${BASE_PATH}/stacker-project-test
  cloud:
    provider: hetzner
    region: fsn1
    size: cpx22
    public_ports:
      - "3579"

With a fresh .env that has only the app's secrets (no EXISTING_SERVER_HOST):

stacker deploy --target cloud --key htz-0 --force-new

Result:

Error: Environment variable not found: $EXISTING_SERVER_HOST

stacker config validate fails with the same error.

Expected Behavior

--target cloud should ignore deploy.server entirely — env var substitution should only apply to the sections that are actually used for the selected target. The command should deploy successfully with just the cloud section vars present.

Actual Behavior

The CLI resolves env vars for deploy.server even when deploying to cloud, so every new project that doesn't pre-seed the server vars fails before deployment starts.

Impact

  • Confusing for the dual-target pattern (server + cloud in one stacker.yml), which is the recommended layout in this repo (see SKILL.md §15).
  • New projects can't be cloud-deployed without manually copying unrelated server env vars into .env.
  • stacker config validate also fails, blocking CI-style preflight checks.

Suggested Fix

Filter env-var substitution by the active target: resolve deploy.cloud.* vars for cloud deploys, deploy.server.* for server deploys, and skip the inactive branch entirely.

Environment

  • Stacker CLI: 0.3.1
  • Cloud provider: Hetzner (htz-0 / htz-13)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status
In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions