generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add skeleton for buildingblock resource
- Loading branch information
Showing
11 changed files
with
250 additions
and
181 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
resource "buildingblock" "example" { | ||
definition_uuid = "some-definition-uuid" | ||
definition_version = 1 | ||
tenant_identifier = "tenantIdentifier" | ||
|
||
name = "some-name" | ||
display_name = "displayname" | ||
|
||
inputs = { | ||
key_1 = "value" | ||
key_2 = 5 | ||
key_3 = true | ||
} | ||
|
||
parents = [ | ||
{ | ||
definition_uuid = "some-parent-definition-uuid" | ||
uuid = "some-parent-block-uuid" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
) | ||
|
||
// Ensure provider defined types fully satisfy framework interfaces. | ||
var _ datasource.DataSource = &BuildingBlockDataSource{} | ||
|
||
func NewBuildingBlockSource() datasource.DataSource { | ||
return &BuildingBlockDataSource{} | ||
} | ||
|
||
type BuildingBlockDataSource struct { | ||
client *MeshStackProviderClient | ||
} | ||
|
||
type BuildingBlockDataSourceModel struct { | ||
} | ||
|
||
func (d *BuildingBlockDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_buildingblock" | ||
} | ||
|
||
func (d *BuildingBlockDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
MarkdownDescription: "BuildingBlock data source", | ||
|
||
Attributes: map[string]schema.Attribute{}, | ||
} | ||
} | ||
|
||
func (d *BuildingBlockDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*MeshStackProviderClient) | ||
|
||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Data Source Configure Type", | ||
fmt.Sprintf("Expected *MeshStackProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
func (d *BuildingBlockDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
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/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
"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 { | ||
Uuid types.String `tfsdk:"uuid"` | ||
DefinitionUUid types.String `tfsdk:"definition_uuid"` | ||
DefinitionVersion types.Int64 `tfsdk:"definition_version"` | ||
TenantIdentifier types.String `tfsdk:"tenant_identifier"` | ||
Name types.String `tfsdk:"name"` | ||
DisplayName types.String `tfsdk:"display_name"` | ||
Inputs types.Map `tfsdk:"inputs"` | ||
Parents types.Set `tfsdk:"parents"` | ||
} | ||
|
||
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{ | ||
"uuid": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "UUID of the Building Block (generated)", | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"definition_uuid": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "The UUID of the Building Block definition, that is used for this Building Block.", | ||
}, | ||
"definition_version": schema.Int64Attribute{ | ||
Required: true, | ||
MarkdownDescription: "Version number of the Building Block definition, that is used for this Building Block.", | ||
}, | ||
"tenant_identifier": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "The identifier of the tenant, this Building Block belongs to.", | ||
}, | ||
"name": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "The name of the Building Block.", | ||
}, | ||
"display_name": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "The display name of the Building Block.", | ||
}, | ||
"inputs": schema.StringAttribute{ | ||
Optional: true, | ||
MarkdownDescription: "Assigned input values for the Building Block.", | ||
}, | ||
"parents": schema.SetAttribute{ | ||
Optional: true, | ||
MarkdownDescription: "The Building Blocks, that are parents of this Building Block.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
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) { | ||
var data BuildingBlockResourceModel | ||
|
||
// read from PLAN | ||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// TODO use client to create resource | ||
|
||
// save to STATE | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *BuildingBlockResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { | ||
var data BuildingBlockResourceModel | ||
|
||
// read from STATE | ||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// save to STATE | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *BuildingBlockResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { | ||
var data BuildingBlockResourceModel | ||
|
||
// read from PLAN | ||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// TODO use client to update resource | ||
|
||
// save to STATE | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *BuildingBlockResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { | ||
var data BuildingBlockResourceModel | ||
|
||
// read from STATE | ||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// TODO use client to delete resource | ||
} | ||
|
||
func (r *BuildingBlockResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { | ||
resource.ImportStatePassthroughID(ctx, path.Root("uuid"), req, resp) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.