-
Notifications
You must be signed in to change notification settings - Fork 48
add CLI authentication support for provider configuration #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add CLI authentication support for provider configuration #1076
Conversation
This commit adds support for CLI-based authentication in the Terraform provider, enabling users to authenticate using credentials from the STACKIT CLI without managing separate service account credentials. Changes: - Add cli_auth boolean attribute to enable CLI authentication - Add cli_profile string attribute for profile selection - Implement authentication priority: explicit credentials > CLI > env vars - Integrate with SDK's WithCLIProviderAuth() configuration option The implementation follows the explicit opt-in pattern requested in RFC stackitcloud#880, requiring users to set cli_auth = true to enable the feature. Profile resolution follows the standard precedence: explicit config > STACKIT_CLI_PROFILE env var > ~/.config/stackit/cli-profile.txt > default. This change depends on SDK PR stackitcloud/stackit-sdk-go#3865 which adds the core CLI authentication functionality, and CLI PR stackitcloud/stackit-cli#1130 which implements the provider credential storage. Closes stackitcloud#719 Related to stackitcloud#880
42832a0 to
5872de6
Compare
Add replace directive to use SDK fork with CLI authentication support from PR stackitcloud/stackit-sdk-go#3865 until it's merged and released. This allows the provider to be built and tested with the CLI auth functionality before the SDK changes are officially released. The replace directive references commit 25b6b99bd648 from github.com/franklouwers/stackit-sdk-go/core which includes the core/cliauth package and config.WithCLIProviderAuth() function. Once SDK PR #3865 is merged and a new SDK version is released, this replace directive should be removed and the provider updated to require the new SDK version.
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
Keep |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
| // See: https://github.com/stackitcloud/stackit-sdk-go/pull/3865 | ||
| // For testing, use: replace github.com/stackitcloud/stackit-sdk-go/core => ../stackit-sdk-go/core | ||
| // For CI/others: replace github.com/stackitcloud/stackit-sdk-go/core => github.com/franklouwers/stackit-sdk-go/core v0.0.0-20251127223915-25b6b99bd648 | ||
| replace github.com/stackitcloud/stackit-sdk-go/core => github.com/franklouwers/stackit-sdk-go/core v0.0.0-20251127223915-25b6b99bd648 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder: Remove this before merge
Add CLI Authentication Support
Overview
This PR implements CLI-based authentication for the Terraform provider, enabling users to authenticate using credentials from the STACKIT CLI without managing separate service account credentials. This addresses a longstanding user request for seamless authentication across STACKIT tools.
Related Issues & PRs
Closes: #719
Related Discussion: #880
Dependencies:
core/cliauthpackage andconfig.WithCLIProviderAuth())stackit auth provider logincommand)Motivation
Users currently need to create service accounts and manage credentials separately for Terraform, even when already authenticated with the STACKIT CLI. This creates friction and complexity, especially for personal development workflows.
As highlighted in issue #719:
Implementation
User-Facing Changes
Two new optional provider attributes:
Authentication Priority
The provider now follows this precedence:
service_account_key,service_account_key_path,token)cli_auth = trueand CLI is authenticated)sdkauth.SetupAuth())This ensures backward compatibility while providing a convenient default for interactive use.
Profile Resolution
When
cli_profileis not specified, the provider uses:STACKIT_CLI_PROFILEenvironment variable~/.config/stackit/cli-profile.txt"default"profileTechnical Details
The implementation leverages the SDK's new
config.WithCLIProviderAuth()function, which:Cross-platform credential storage:
~/.stackit/cli-provider-auth-storage.txtUsage Example
Before (Current Workflow)
After (With CLI Auth)
Design Decisions
Explicit Opt-In (RFC #880 Requirement)
The feature requires
cli_auth = trueto avoid confusion about authentication behavior. Users must consciously enable CLI authentication, making it clear where credentials originate.Minimal Coupling
The provider only depends on the SDK's configuration interface. All credential management, token refresh, and storage logic resides in the SDK's
core/cliauthpackage, maintaining clean separation of concerns.Backward Compatibility
Existing authentication methods continue to work unchanged. The new feature is purely additive, with no breaking changes to provider configuration or behavior.
Documentation Updates Needed
Migration Path
go.modto use SDK version with CLI auth supportChecklist
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)