Skip to content

Commit a1d2840

Browse files
authored
fix: ensure use_local_config is correctly applied and validated (#321)
1 parent 08682d2 commit a1d2840

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

internal/provider/model_provider.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,33 @@ func (p ArgoCDProviderConfig) setCoreOpts(opts *apiclient.ClientOptions) (bool,
183183
func (p ArgoCDProviderConfig) setLocalConfigOpts(opts *apiclient.ClientOptions) (bool, diag.Diagnostics) {
184184
var diags diag.Diagnostics
185185

186-
useLocalConfig := opts.PortForward || opts.PortForwardNamespace != ""
186+
useLocalConfig := p.UseLocalConfig.ValueBool()
187187
switch useLocalConfig {
188188
case true:
189+
if opts.ServerAddr != "" {
190+
diags.AddWarning("setting `server_addr` alongside `use_local_config = true` is unnecessary and not recommended as this will overwrite the address retrieved from the local ArgoCD context.", "")
191+
}
192+
193+
if !p.Username.IsNull() {
194+
diags.AddWarning("`username` is ignored when `use_local_config = true`.", "")
195+
}
196+
189197
opts.Context = getDefaultString(p.Context, "ARGOCD_CONTEXT")
190198

191199
cp := getDefaultString(p.ConfigPath, "ARGOCD_CONFIG_PATH")
192200

193201
if cp != "" {
194202
opts.ConfigPath = p.ConfigPath.ValueString()
195-
return useLocalConfig, nil
203+
break
196204
}
197205

198206
cp, err := localconfig.DefaultLocalConfigPath()
199207
if err == nil {
200208
opts.ConfigPath = cp
201-
return useLocalConfig, nil
209+
break
202210
}
203211

204212
diags.Append(diagnostics.Error("failed to find default ArgoCD config path", err)...)
205-
206-
if opts.ServerAddr != "" {
207-
diags.AddWarning("setting `server_addr` alongside `use_local_config = true` is unnecessary and not recommended as this will overwrite the address retrieved from the local ArgoCD context.", "")
208-
}
209-
210-
if !p.Username.IsNull() {
211-
diags.AddWarning("`username` is ignored when `use_local_config = true`.", "")
212-
}
213213
case false:
214214
// Log warnings if explicit configuration has been provided for local config when `use_local_config` is not enabled.
215215
if !p.ConfigPath.IsNull() {

0 commit comments

Comments
 (0)