Skip to content

Commit

Permalink
refactor: pull out duplicate io list schema
Browse files Browse the repository at this point in the history
  • Loading branch information
henryde committed Apr 30, 2024
1 parent d8531df commit ef739ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 6 additions & 0 deletions examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ data "meshstack_buildingblock" "test" {
}
}

data "meshstack_buildingblock" "test_failed" {
metadata = {
uuid = "4570f298-1f6a-48d0-8f93-13dac606ceb0"
}
}

output "bb_provider_uuid" {
value = data.meshstack_buildingblock.test.metadata.definition_uuid
}
36 changes: 15 additions & 21 deletions internal/provider/buildingblock_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ func (d *buildingBlockDataSource) Metadata(ctx context.Context, req datasource.M
}

func (d *buildingBlockDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
// not sure if it is okay to use this value multiple times
ioList := schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"key": schema.StringAttribute{Computed: true},
"value": schema.StringAttribute{Computed: true},
"value_type": schema.StringAttribute{Computed: true},
},
},
}

resp.Schema = schema.Schema{
MarkdownDescription: "BuildingBlock data source",

Expand Down Expand Up @@ -63,16 +75,7 @@ func (d *buildingBlockDataSource) Schema(ctx context.Context, req datasource.Sch
Attributes: map[string]schema.Attribute{

"display_name": schema.StringAttribute{Computed: true},
"inputs": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"key": schema.StringAttribute{Computed: true},
"value": schema.StringAttribute{Computed: true},
"value_type": schema.StringAttribute{Computed: true},
},
},
},
"inputs": ioList,
"parent_building_blocks": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Expand All @@ -89,17 +92,8 @@ func (d *buildingBlockDataSource) Schema(ctx context.Context, req datasource.Sch
Computed: true,
Attributes: map[string]schema.Attribute{

"status": schema.StringAttribute{Computed: true},
"outputs": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"key": schema.StringAttribute{Computed: true},
"value": schema.StringAttribute{Computed: true},
"value_type": schema.StringAttribute{Computed: true},
},
},
},
"status": schema.StringAttribute{Computed: true},
"outputs": ioList,
},
},
},
Expand Down

0 comments on commit ef739ae

Please sign in to comment.