CLI Configuration#
Atlantis's CLI configuration lives in the cmd/ package. The primary entry point is cmd/server.go, which defines all flags, their defaults, help descriptions, and the full startup sequence for the atlantis server subcommand.
Typed Flag Maps#
All flags are declared as typed maps at package level :
| Map | Go type | Examples |
|---|---|---|
stringFlags | map[string]stringFlag | --gh-token, --repo-allowlist, --log-level |
boolFlags | map[string]boolFlag | --automerge, --allow-fork-prs, --parallel-plan |
intFlags | map[string]intFlag | --port, --parallel-pool-size, --redis-port |
int64Flags | map[string]int64Flag | --gh-app-id, --gh-app-installation-id |
Each entry carries a description, defaultValue, and optional hidden field . These maps are the single source of truth for what flags exist β adding a new flag requires adding a constant, a UserConfig field with a matching mapstructure tag, and an entry in one of the maps .
All flag names are declared as const strings in alphabetical order , making them safe to reference from both the CLI layer and the server initialization code.
Viper Integration and YAML Config#
ServerCmd.Init() configures Viper to accept environment variables prefixed with ATLANTIS_ and to translate hyphens to underscores . Every flag is bound to Viper with BindPFlag, so flags, env vars, and YAML config files are resolved in a unified priority order (cobra flag > env var > config file > default).
The --config flag points to a YAML file that is loaded during preRun . The YAML keys are the flag names (e.g., gh-token: abc123) because UserConfig fields carry matching mapstructure tags .
GitHub App Authentication Flags#
GitHub App auth uses a dedicated int64Flags sub-map. The two relevant flags are :
--gh-app-id(GithubAppID int64) β activates GitHub App credentials when non-zero.--gh-app-installation-id(GithubAppInstallationID int64) β pins a specific installation; required when one App has multiple installations.
Alongside these, the string flags --gh-app-key / --gh-app-key-file supply the private key , and --gh-app-slug provides the URL-friendly App name .
Validation enforces mutual exclusivity: if --gh-app-id is set, exactly one of --gh-app-key or --gh-app-key-file must be provided β not both and not neither .
Help Generation#
cmd/help_fmt.go defines usageTmpl, a custom Cobra usage template that replaces the default flag listing. It:
- Collects all non-hidden flag names from
stringFlags,boolFlags, andintFlags, then sorts them alphabetically . - Formats each entry as
--name=<value>(or--namefor booleans) followed by the description wrapped at 80 characters . - Embeds the result in a Cobra-compatible template string .
Note: int64Flags (i.e., --gh-app-id, --gh-app-installation-id) are not included in the usageTmpl call . These flags are registered with Cobra and Viper normally but won't appear in the custom --help output β a known gap.
Validation Logic#
After Viper unmarshals flags into server.UserConfig, ServerCmd.run() calls validate() . Key checks include:
- Log level β must be one of
debug,info,warn,error. - TF distribution β must be
terraformoropentofu. - Checkout strategy β must be
branchormerge. - VCS credentials β at least one VCS provider must be fully configured (user+token or App ID+key); partial pairs are rejected .
--repo-allowlistβ required; cannot contain://.- SSL β
--ssl-cert-fileand--ssl-key-filemust both be set or both unset . - Redis cluster mode β
--redis-cluster-addressescannot be combined with--redis-host,--redis-port, or--redis-db. - Token newline detection β warns if any token value contains a
\n.
Security warnings are emitted separately via securityWarnings() when webhook secrets are absent .
Kubernetes Environment Sanitization#
Kubernetes injects service-discovery environment variables for co-located services. For example, an atlantis Service in the same namespace produces ATLANTIS_REDIS_PORT=tcp://10.x.x.x:6379, which Viper picks up as the redis-port flag and then fails to parse as an integer.
sanitizeKubernetesServiceLinks() addresses this by iterating intFlags and resetting any value whose string form starts with tcp:// or udp:// back to its declared default. It is called at the top of run(), before Viper.Unmarshal .
Startup Sequence#
ServerCmd.run() executes in this order :
sanitizeKubernetesServiceLinks()β fix K8s env collisionsViper.Unmarshal(&userConfig)β populateUserConfigsetDefaults()β fill zero-valued fields with their defaultsvalidate()β enforce all constraintssetAtlantisURL(),setDataDir(),setMarkdownTemplateOverridesDir()β expand~and resolve relative pathssetVarFileAllowlist()β default todata-dirif unsetdeprecationWarnings()/securityWarnings()/trimAtSymbolFromUsers()β housekeepingServerCreator.NewServer()βserver.Start()
Key Files#
| File | Purpose |
|---|---|
cmd/server.go | Flag declarations, defaults, ServerCmd, validation, startup sequence |
cmd/help_fmt.go | Custom Cobra usage template generation |
server/user_config.go | UserConfig struct with mapstructure tags |
main.go | Entry point; registers server, version, and testdrive subcommands |