Skip to content

Commit 1223f21

Browse files
committed
implement datasource skeleton for hetzner server. terraform plan executes now in provider-install-verification
1 parent 0a57e74 commit 1223f21

File tree

5 files changed

+48
-36
lines changed

5 files changed

+48
-36
lines changed

Diff for: examples/provider-install-verification/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
hetznerrobot = {
4+
source = "DigitecGalaxus/hetznerrobot"
5+
}
6+
}
7+
}
8+
9+
provider "hetznerrobot" {}
10+
11+
data "hetznerrobot_server" "example" {}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/digitecgalaxus/terraform-provider-hetznerrobot
1+
module terraform-provider-hetznerrobot
22

33
go 1.22.7
44

Diff for: internal/provider/example_data_source.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@ import (
1414
"github.com/hashicorp/terraform-plugin-log/tflog"
1515
)
1616

17+
type ServerDataSource struct {
18+
client *http.Client
19+
}
20+
1721
// Ensure provider defined types fully satisfy framework interfaces.
18-
var _ datasource.DataSource = &ExampleDataSource{}
22+
var _ datasource.DataSource = &ServerDataSource{}
1923

20-
func NewExampleDataSource() datasource.DataSource {
21-
return &ExampleDataSource{}
24+
func NewServerDataSource() datasource.DataSource {
25+
return &ServerDataSource{}
2226
}
2327

2428
// ExampleDataSource defines the data source implementation.
25-
type ExampleDataSource struct {
26-
client *http.Client
27-
}
2829

2930
// ExampleDataSourceModel describes the data source data model.
30-
type ExampleDataSourceModel struct {
31+
type ServerDataSourceDataSourceModel struct {
3132
ConfigurableAttribute types.String `tfsdk:"configurable_attribute"`
3233
Id types.String `tfsdk:"id"`
3334
}
3435

35-
func (d *ExampleDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
36-
resp.TypeName = req.ProviderTypeName + "_example"
36+
func (d *ServerDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
37+
resp.TypeName = req.ProviderTypeName + "_server"
3738
}
3839

39-
func (d *ExampleDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
40+
func (d *ServerDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
4041
resp.Schema = schema.Schema{
4142
// This description is used by the documentation generator and the language server.
4243
MarkdownDescription: "Example data source",
@@ -47,14 +48,14 @@ func (d *ExampleDataSource) Schema(ctx context.Context, req datasource.SchemaReq
4748
Optional: true,
4849
},
4950
"id": schema.StringAttribute{
50-
MarkdownDescription: "Example identifier",
51+
MarkdownDescription: "Hetzner Server ID",
5152
Computed: true,
5253
},
5354
},
5455
}
5556
}
5657

57-
func (d *ExampleDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
58+
func (d *ServerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
5859
// Prevent panic if the provider has not been configured.
5960
if req.ProviderData == nil {
6061
return
@@ -74,8 +75,8 @@ func (d *ExampleDataSource) Configure(ctx context.Context, req datasource.Config
7475
d.client = client
7576
}
7677

77-
func (d *ExampleDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
78-
var data ExampleDataSourceModel
78+
func (d *ServerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
79+
var data ServerDataSourceDataSourceModel
7980

8081
// Read Terraform configuration data into the model
8182
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

Diff for: internal/provider/provider.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ import (
1616
"github.com/hashicorp/terraform-plugin-framework/types"
1717
)
1818

19-
// Ensure ScaffoldingProvider satisfies various provider interfaces.
20-
var _ provider.Provider = &ScaffoldingProvider{}
21-
var _ provider.ProviderWithFunctions = &ScaffoldingProvider{}
22-
var _ provider.ProviderWithEphemeralResources = &ScaffoldingProvider{}
19+
// Ensure HetznerRobotProvider satisfies various provider interfaces.
20+
var _ provider.Provider = &HetznerRobotProvider{}
21+
var _ provider.ProviderWithFunctions = &HetznerRobotProvider{}
22+
var _ provider.ProviderWithEphemeralResources = &HetznerRobotProvider{}
2323

24-
// ScaffoldingProvider defines the provider implementation.
25-
type ScaffoldingProvider struct {
24+
// HetznerRobotProvider defines the provider implementation.
25+
type HetznerRobotProvider struct {
2626
// version is set to the provider version on release, "dev" when the
2727
// provider is built and ran locally, and "test" when running acceptance
2828
// testing.
2929
version string
3030
}
3131

32-
// ScaffoldingProviderModel describes the provider data model.
33-
type ScaffoldingProviderModel struct {
32+
// HetznerRobotProviderModel describes the provider data model.
33+
type HetznerRobotProviderModel struct {
3434
Endpoint types.String `tfsdk:"endpoint"`
3535
}
3636

37-
func (p *ScaffoldingProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
38-
resp.TypeName = "scaffolding"
37+
func (p *HetznerRobotProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
38+
resp.TypeName = "hetznerrobot"
3939
resp.Version = p.version
4040
}
4141

42-
func (p *ScaffoldingProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
42+
func (p *HetznerRobotProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
4343
resp.Schema = schema.Schema{
4444
Attributes: map[string]schema.Attribute{
4545
"endpoint": schema.StringAttribute{
@@ -50,8 +50,8 @@ func (p *ScaffoldingProvider) Schema(ctx context.Context, req provider.SchemaReq
5050
}
5151
}
5252

53-
func (p *ScaffoldingProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
54-
var data ScaffoldingProviderModel
53+
func (p *HetznerRobotProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
54+
var data HetznerRobotProviderModel
5555

5656
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
5757

@@ -68,33 +68,33 @@ func (p *ScaffoldingProvider) Configure(ctx context.Context, req provider.Config
6868
resp.ResourceData = client
6969
}
7070

71-
func (p *ScaffoldingProvider) Resources(ctx context.Context) []func() resource.Resource {
71+
func (p *HetznerRobotProvider) Resources(ctx context.Context) []func() resource.Resource {
7272
return []func() resource.Resource{
7373
NewExampleResource,
7474
}
7575
}
7676

77-
func (p *ScaffoldingProvider) EphemeralResources(ctx context.Context) []func() ephemeral.EphemeralResource {
77+
func (p *HetznerRobotProvider) EphemeralResources(ctx context.Context) []func() ephemeral.EphemeralResource {
7878
return []func() ephemeral.EphemeralResource{
7979
NewExampleEphemeralResource,
8080
}
8181
}
8282

83-
func (p *ScaffoldingProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
83+
func (p *HetznerRobotProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
8484
return []func() datasource.DataSource{
85-
NewExampleDataSource,
85+
NewServerDataSource,
8686
}
8787
}
8888

89-
func (p *ScaffoldingProvider) Functions(ctx context.Context) []func() function.Function {
89+
func (p *HetznerRobotProvider) Functions(ctx context.Context) []func() function.Function {
9090
return []func() function.Function{
9191
NewExampleFunction,
9292
}
9393
}
9494

9595
func New(version string) func() provider.Provider {
9696
return func() provider.Provider {
97-
return &ScaffoldingProvider{
97+
return &HetznerRobotProvider{
9898
version: version,
9999
}
100100
}

Diff for: main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"flag"
99
"log"
1010

11-
"github.com/digitecgalaxus/terraform-provider-hetznerrobot/internal/provider"
1211
"github.com/hashicorp/terraform-plugin-framework/providerserver"
12+
"terraform-provider-hetznerrobot/internal/provider"
1313
)
1414

1515
var (
@@ -31,7 +31,7 @@ func main() {
3131
// TODO: Update this string with the published name of your provider.
3232
// Also update the tfplugindocs generate command to either remove the
3333
// -provider-name flag or set its value to the updated provider name.
34-
Address: "registry.terraform.io/hashicorp/scaffolding",
34+
Address: "digitecgalaxus.ch/DigitecGalaxus/hetznerrobot",
3535
Debug: debug,
3636
}
3737

0 commit comments

Comments
 (0)