Skip to content

Commit 688e0c4

Browse files
authored
Merge pull request #1133 from RafaySystems/RC-45007-fixes
Rc 45007 fixes
2 parents 3b148e6 + 973225c commit 688e0c4

File tree

5 files changed

+102
-9
lines changed

5 files changed

+102
-9
lines changed

docs/index.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,35 @@ provider "rafay" {
112112
The Rafay provider offers a flexible means of providing credentials for
113113
authentication. The following methods are supported, in this order, and
114114
explained below:
115-
115+
- Direct Credentials in Provider Configuration
116116
- Environment variables
117117
- Credentials/configuration file
118118

119119

120+
### Direct Credentials in Provider Configuration
121+
122+
You can provide credentials directly in the `rafay` provider block. This is the recommended approach when fetching credentials from a secret management tool like HashiCorp Vault.
123+
124+
```terraform
125+
provider "rafay" {
126+
api_key = data.vault_kv_secret_v2.rafay.data.api_key
127+
rest_endpoint = data.vault_kv_secret_v2.rafay.data.endpoint
128+
project = data.vault_kv_secret_v2.rafay.data.project
129+
}
130+
```
131+
132+
Or with hardcoded values (not recommended for production):
133+
134+
```terraform
135+
provider "rafay" {
136+
api_key = "ra2.xxxxxxxxxxxxx"
137+
rest_endpoint = "console.rafay.dev"
138+
project = "defaultproject"
139+
}
140+
```
141+
142+
This method takes precedence over environment variables and the configuration file.
143+
120144
### Environment Variables
121145

122146
You can provide your credentials via the `RCTL_REST_ENDPOINT`, `RCTL_API_KEY`,
@@ -155,5 +179,10 @@ provider "rafay" {
155179

156180
### Optional
157181

182+
- **api_key** (String, Sensitive) Rafay API key. Can also be set via the `RCTL_API_KEY` environment variable.
183+
- **ignore_insecure_tls_error** (Boolean) Skip TLS certificate verification.
184+
- **project** (String) Rafay project name. Can also be set via the `RCTL_PROJECT` environment variable.
185+
- **provider_config_file** (String) Path to Rafay configuration file. Defaults to `~/.rafay/cli/config.json`. Can also be set via the `RAFAY_PROVIDER_CONFIG` environment variable.
186+
- **rest_endpoint** (String) Rafay API endpoint (e.g., `console.rafay.dev`). Can also be set via the `RCTL_REST_ENDPOINT` environment variable.
158187
- **ignore_insecure_tls_error** (Boolean)
159188
- **provider_config_file** (String)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ toolchain go1.24.9
66

77
require (
88
github.com/RafaySystems/edge-common v1.24.1-0.20240905053610-494a83a439f8
9-
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251031043157-2e9b455c9bfc
10-
github.com/RafaySystems/rctl v1.29.1-0.20251009073106-3a01a70d5f7f
9+
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251103113511-05b1a32bbbc0
10+
github.com/RafaySystems/rctl v1.29.1-0.20251105214534-501a9e6c91c1
1111
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
1212
github.com/go-yaml/yaml v2.1.0+incompatible
1313
github.com/goccy/go-yaml v1.9.5

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ github.com/RafaySystems/edge-common v1.24.1-0.20240905053610-494a83a439f8 h1:Pce
2222
github.com/RafaySystems/edge-common v1.24.1-0.20240905053610-494a83a439f8/go.mod h1:5mRn2xN25Y8mpObHyOwDB3OLudeuglzHTQX9IiNHxhM=
2323
github.com/RafaySystems/paas-common v0.0.0-20250519095800-e92646adcd6e h1:SrznY+xkaQ4BkX0HXGa0upur7RAtR6UsTsdMNEgBreY=
2424
github.com/RafaySystems/paas-common v0.0.0-20250519095800-e92646adcd6e/go.mod h1:vDR0S28Q+hwE/5wO0L/Ohn9CZwaI/o2QuPupJ2iLI7k=
25-
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251031043157-2e9b455c9bfc h1:7hfknF6cW0o3Ecbkf86O1w4tm7XbewZYRwh92QgPniw=
26-
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251031043157-2e9b455c9bfc/go.mod h1:NozE55WdAl4Td8+GMPxbRN/qI5tu8tkPBH/hj8aZqSE=
27-
github.com/RafaySystems/rctl v1.29.1-0.20251009073106-3a01a70d5f7f h1:D14avgXPoI7B3rRYwynLJiE3BxzgMVejIUl9SvcvWcE=
28-
github.com/RafaySystems/rctl v1.29.1-0.20251009073106-3a01a70d5f7f/go.mod h1:tn0SlvXgdHfrVBeoe4wCwmhW30+zw8b1efp9uSTKWPY=
25+
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251103113511-05b1a32bbbc0 h1:8LKWepImU4h35JCxDZ17GGpuQ4oWJB8WY1D9IXMNl3o=
26+
github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20251103113511-05b1a32bbbc0/go.mod h1:NozE55WdAl4Td8+GMPxbRN/qI5tu8tkPBH/hj8aZqSE=
27+
github.com/RafaySystems/rctl v1.29.1-0.20251105214534-501a9e6c91c1 h1:Ay0PO/aJuFD6VNvNESuPRRyKZS1itdKbdk3z1bBEr6A=
28+
github.com/RafaySystems/rctl v1.29.1-0.20251105214534-501a9e6c91c1/go.mod h1:wkUnTFcFBbgivx61WxuKG53dOwbWpdYakiGiRhqQV9U=
2929
github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv2QzDdQ=
3030
github.com/RoaringBitmap/roaring v1.9.4/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90=
3131
github.com/abhay-krishna/cluster-api v1.4.2-eksa.1 h1:mO+idOdh9Bpumgo41WJcrASPtJGSgmRxHNiwtUdUa+E=

internal/provider/provider.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/tls"
66
"net/http"
7+
"os"
78
"os/user"
89
"path/filepath"
910
"strings"
@@ -46,6 +47,9 @@ func New(version string) func() provider.Provider {
4647
type RafayFwProviderModel struct {
4748
ProviderConfigFile types.String `tfsdk:"provider_config_file"`
4849
IgnoreInsecureTlsError basetypes.BoolValue `tfsdk:"ignore_insecure_tls_error"`
50+
ApiKey types.String `tfsdk:"api_key"`
51+
RestEndpoint types.String `tfsdk:"rest_endpoint"`
52+
Project types.String `tfsdk:"project"`
4953
}
5054

5155
func (p *RafayFwProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
@@ -57,6 +61,19 @@ func (p *RafayFwProvider) Schema(ctx context.Context, req provider.SchemaRequest
5761
"ignore_insecure_tls_error": schema.BoolAttribute{
5862
Optional: true,
5963
},
64+
"api_key": schema.StringAttribute{
65+
Description: "Rafay API key",
66+
Optional: true,
67+
Sensitive: true,
68+
},
69+
"rest_endpoint": schema.StringAttribute{
70+
Description: "Rafay API endpoint",
71+
Optional: true,
72+
},
73+
"project": schema.StringAttribute{
74+
Description: "Rafay project",
75+
Optional: true,
76+
},
6077
},
6178
}
6279

@@ -77,15 +94,29 @@ func (p *RafayFwProvider) Configure(ctx context.Context, req provider.ConfigureR
7794
return
7895
}
7996

97+
apiKey := data.ApiKey.ValueString()
98+
restEndpoint := data.RestEndpoint.ValueString()
99+
project := data.Project.ValueString()
100+
101+
cliCtx := rctlcontext.GetContext()
102+
if apiKey != "" && restEndpoint != "" {
103+
cliCtx.APIKey = apiKey
104+
cliCtx.RestEndpoint = restEndpoint
105+
106+
// The project is handled by setting an environment variable, which rctl already supports.
107+
if project != "" {
108+
os.Setenv("RCTL_PROJECT", project)
109+
}
110+
}
111+
80112
configFile := data.ProviderConfigFile.ValueString()
81113
ignoreTlsError := data.IgnoreInsecureTlsError
82114

83115
tflog.Info(ctx, "rafay provider config file", map[string]interface{}{
84116
"config_file": configFile,
85117
})
86118

87-
cliCtx := rctlcontext.GetContext()
88-
119+
89120
if configFile != "" {
90121
var err error
91122

rafay/provider.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/tls"
66
"log"
77
"net/http"
8+
"os"
89
"os/user"
910
"path/filepath"
1011
"strings"
@@ -31,6 +32,25 @@ func New(_ string) func() *schema.Provider {
3132
Type: schema.TypeBool,
3233
Optional: true,
3334
},
35+
"api_key": &schema.Schema{
36+
Type: schema.TypeString,
37+
Description: "Rafay API key",
38+
Optional: true,
39+
Sensitive: true,
40+
DefaultFunc: schema.EnvDefaultFunc("RCTL_API_KEY", nil),
41+
},
42+
"rest_endpoint": &schema.Schema{
43+
Type: schema.TypeString,
44+
Description: "Rafay API endpoint",
45+
Optional: true,
46+
DefaultFunc: schema.EnvDefaultFunc("RCTL_REST_ENDPOINT", nil),
47+
},
48+
"project": &schema.Schema{
49+
Type: schema.TypeString,
50+
Description: "Rafay project",
51+
Optional: true,
52+
DefaultFunc: schema.EnvDefaultFunc("RCTL_PROJECT", nil),
53+
},
3454
},
3555
ResourcesMap: map[string]*schema.Resource{
3656
"rafay_project": resourceProject(),
@@ -152,9 +172,22 @@ func providerConfigure(ctx context.Context, rd *schema.ResourceData) (interface{
152172

153173
config_file := rd.Get("provider_config_file").(string)
154174
ignoreTlsError := rd.Get("ignore_insecure_tls_error").(bool)
175+
apiKey := rd.Get("api_key").(string)
176+
restEndpoint := rd.Get("rest_endpoint").(string)
177+
project := rd.Get("project").(string)
155178

156179
log.Printf("rafay provider config file %s", config_file)
157180
cliCtx := rctlcontext.GetContext()
181+
182+
// If direct credentials provided, use them (takes precedence)
183+
if apiKey != "" && restEndpoint != "" {
184+
cliCtx.APIKey = apiKey
185+
cliCtx.RestEndpoint = restEndpoint
186+
if project != "" {
187+
os.Setenv("RCTL_PROJECT", project)
188+
}
189+
}
190+
158191
if config_file != "" {
159192
var err error
160193

0 commit comments

Comments
 (0)