-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
191 lines (165 loc) · 7.88 KB
/
Copy pathmain.go
File metadata and controls
191 lines (165 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package main
import (
"context"
"log"
"os"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
resource_pod "github.com/runpod/terraform-provider-runpod/internal/provider/resource_pod"
resource_pod_action "github.com/runpod/terraform-provider-runpod/internal/provider/resource_pod_action"
resource_machine "github.com/runpod/terraform-provider-runpod/internal/provider/resource_machine"
resource_network_volume "github.com/runpod/terraform-provider-runpod/internal/provider/resource_network_volume"
resource_endpoint "github.com/runpod/terraform-provider-runpod/internal/provider/resource_endpoint"
resource_endpoint_job "github.com/runpod/terraform-provider-runpod/internal/provider/resource_endpoint_job"
resource_endpoint_worker "github.com/runpod/terraform-provider-runpod/internal/provider/resource_endpoint_worker"
resource_template "github.com/runpod/terraform-provider-runpod/internal/provider/resource_template"
resource_container_registry_auth "github.com/runpod/terraform-provider-runpod/internal/provider/resource_container_registry_auth"
resource_ecr_delegation "github.com/runpod/terraform-provider-runpod/internal/provider/resource_ecr_delegation"
datasource_pod "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_pod"
datasource_machine "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_machine"
datasource_machines "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_machines"
datasource_gpu_types "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_gpu_types"
datasource_data_centers "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_data_centers"
datasource_user "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_user"
datasource_template "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_template"
datasource_container_registry_auth "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_container_registry_auth"
datasource_ecr_delegations "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_ecr_delegations"
datasource_endpoint_jobs "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_endpoint_jobs"
datasource_endpoint_job_logs "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_endpoint_job_logs"
datasource_endpoint_workers "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_endpoint_workers"
datasource_endpoint_worker_logs "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_endpoint_worker_logs"
datasource_billing_pod "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_billing_pod"
datasource_billing_network_volume "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_billing_network_volume"
datasource_billing_endpoint "github.com/runpod/terraform-provider-runpod/internal/provider/datasource_billing_endpoint"
client "github.com/runpod/terraform-provider-runpod/internal/provider/client"
)
func main() {
log.Println("Starting RunPod provider...")
err := providerserver.Serve(context.Background(), func() provider.Provider {
log.Println("Creating provider instance...")
return newProvider()
}, providerserver.ServeOpts{
Address: "registry.terraform.io/runpod/runpod",
})
if err != nil {
log.Printf("Provider server error: %v\n", err)
}
}
func newProvider() provider.Provider {
log.Println("newProvider() called")
return &runpodProvider{}
}
type runpodProvider struct {
apiKey string
baseUrl string
graphqlUrl string
client *client.RunPodClient
}
type providerConfig struct {
ApiKey types.String `tfsdk:"api_key"`
BaseUrl types.String `tfsdk:"base_url"`
}
func (p *runpodProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
log.Println("Metadata() called")
resp.TypeName = "runpod"
}
func (p *runpodProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
log.Println("Schema() called")
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"api_key": schema.StringAttribute{
Optional: true,
Sensitive: true,
Description: "RunPod API key",
MarkdownDescription: "RunPod API key. Can also be set via the `RUNPOD_API_KEY` environment variable.",
},
"base_url": schema.StringAttribute{
Optional: true,
Description: "RunPod API base URL",
MarkdownDescription: "RunPod API base URL. Can also be set via the `RUNPOD_BASE_URL` environment variable. Defaults to `https://api.runpod.io/v2`.",
},
},
}
}
func (p *runpodProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
log.Println("Configure() called")
var cfg providerConfig
diags := req.Config.Get(ctx, &cfg)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
if !cfg.ApiKey.IsNull() && !cfg.ApiKey.IsUnknown() {
p.apiKey = cfg.ApiKey.ValueString()
}
if !cfg.BaseUrl.IsNull() && !cfg.BaseUrl.IsUnknown() {
p.baseUrl = cfg.BaseUrl.ValueString()
}
if p.apiKey == "" {
p.apiKey = os.Getenv("RUNPOD_API_KEY")
}
if p.baseUrl == "" {
p.baseUrl = os.Getenv("RUNPOD_BASE_URL")
}
if p.baseUrl == "" {
p.baseUrl = "https://api.runpod.io/v2"
}
p.graphqlUrl = "https://api.runpod.io/graphql"
if p.apiKey == "" {
resp.Diagnostics.AddError(
"Missing API Key",
"RunPod API key is required. Set it via provider config or RUNPOD_API_KEY environment variable.",
)
return
}
p.client = client.NewRunPodClient(p.apiKey, p.graphqlUrl, p.baseUrl)
// Pass client wrapper for pod_action resource (uses REST only)
clientWrapper := &client.RunPodClientWrapper{
APIKey: p.apiKey,
RestBaseURL: p.baseUrl,
}
resp.ResourceData = clientWrapper
resp.DataSourceData = p.client
log.Printf("API base URL: %s\n", p.baseUrl)
log.Printf("GraphQL URL: %s\n", p.graphqlUrl)
}
func (p *runpodProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
log.Println("DataSources() called")
return []func() datasource.DataSource{
datasource_pod.NewPodDataSource,
datasource_machine.NewMachineDataSource,
datasource_machines.NewMachinesDataSource,
datasource_gpu_types.NewGpuTypesDataSource,
datasource_data_centers.NewDataCentersDataSource,
datasource_user.NewUserDataSource,
datasource_template.NewTemplateDataSource,
datasource_container_registry_auth.NewContainerRegistryAuthDataSource,
datasource_ecr_delegations.NewEcrDelegationsDataSource,
datasource_endpoint_jobs.NewEndpointJobsDataSource,
datasource_endpoint_job_logs.NewEndpointJobLogsDataSource,
datasource_endpoint_workers.NewEndpointWorkersDataSource,
datasource_endpoint_worker_logs.NewEndpointWorkerLogsDataSource,
datasource_billing_pod.NewBillingPodDataSource,
datasource_billing_network_volume.NewBillingNetworkVolumeDataSource,
datasource_billing_endpoint.NewBillingEndpointDataSource,
}
}
func (p *runpodProvider) Resources(ctx context.Context) []func() resource.Resource {
log.Println("Resources() called")
return []func() resource.Resource{
resource_pod.NewPodResource,
resource_pod_action.NewPodActionResource,
resource_machine.NewMachineResource,
resource_network_volume.NewNetworkVolumeResource,
resource_endpoint.NewEndpointResource,
resource_endpoint_job.NewEndpointJobResource,
resource_endpoint_worker.NewEndpointWorkerResource,
resource_template.NewTemplateResource,
resource_container_registry_auth.NewContainerRegistryAuthResource,
resource_ecr_delegation.NewEcrDelegationResource,
}
}