Skip to content

Commit

Permalink
chore: add skeleton for buildingblock resource
Browse files Browse the repository at this point in the history
  • Loading branch information
j0g3sc committed Nov 17, 2023
1 parent 1326220 commit 0466f13
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 181 deletions.
30 changes: 0 additions & 30 deletions docs/data-sources/scaffolding_example.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/data-sources/scaffolding_example/data-source.tf

This file was deleted.

6 changes: 4 additions & 2 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
provider "scaffolding" {
# example configuration here
provider "meshstack" {
endpoint = "meshfed.url"
apikey = "API_KEY"
apisecret = "API_SECRET"
}
2 changes: 2 additions & 0 deletions examples/resources/buildingblocks/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resource "buildingblock" "example" {
}
3 changes: 0 additions & 3 deletions examples/resources/scaffolding_example/resource.tf

This file was deleted.

76 changes: 76 additions & 0 deletions internal/provider/buildingblock_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package provider

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ resource.Resource = &BuildingBlockResource{}
var _ resource.ResourceWithImportState = &BuildingBlockResource{}

func NewBuildingBlockResource() resource.Resource {
return &BuildingBlockResource{}
}

type BuildingBlockResource struct {
client *MeshStackProviderClient
}

type BuildingBlockResourceModel struct {
ConfigurableAttribute types.String `tfsdk:"configurable_attribute"`
Defaulted types.String `tfsdk:"defaulted"`
Id types.String `tfsdk:"id"`
}

func (r *BuildingBlockResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_buildingblock"
}

func (r *BuildingBlockResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Building Block",

Attributes: map[string]schema.Attribute{},
}
}

func (r *BuildingBlockResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

client, ok := req.ProviderData.(*MeshStackProviderClient)

if !ok {
resp.Diagnostics.AddError(
"Unexpected Resource Configure Type",
fmt.Sprintf("Expected *MeshStackProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

r.client = client
}

func (r *BuildingBlockResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
}

func (r *BuildingBlockResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
}

func (r *BuildingBlockResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
}

func (r *BuildingBlockResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
}

func (r *BuildingBlockResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}
104 changes: 0 additions & 104 deletions internal/provider/example_data_source.go

This file was deleted.

32 changes: 0 additions & 32 deletions internal/provider/example_data_source_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/provider/example_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *ExampleResource) Configure(ctx context.Context, req resource.ConfigureR
if !ok {
resp.Diagnostics.AddError(
"Unexpected Resource Configure Type",
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
fmt.Sprintf("Expected *MeshStackProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
Expand Down
11 changes: 5 additions & 6 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func (p *MeshStackProvider) Schema(ctx context.Context, req provider.SchemaReque
Attributes: map[string]schema.Attribute{
"endpoint": schema.StringAttribute{
MarkdownDescription: "Example provider attribute",
Optional: false,
Required: true,
},
"apikey": schema.StringAttribute{
MarkdownDescription: "API Key to authenticate against the meshStack API",
Optional: false,
Required: true,
},
"apisecret": schema.StringAttribute{
MarkdownDescription: "API Secret to authenticate against the meshStack API",
Optional: false,
Required: true,
},
},
}
Expand Down Expand Up @@ -95,13 +95,12 @@ func buildClient(url *url.URL, model MeshStackProviderModel) *MeshStackProviderC
func (p *MeshStackProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewExampleResource,
NewBuildingBlockResource,
}
}

func (p *MeshStackProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewExampleDataSource,
}
return []func() datasource.DataSource{}
}

func New(version string) func() provider.Provider {
Expand Down

0 comments on commit 0466f13

Please sign in to comment.