Skip to content

Commit 264a635

Browse files
committed
feature: preview building blocks v2 resources
1 parent 4aaeef0 commit 264a635

9 files changed

+1141
-12
lines changed

.github/workflows/test.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
cache: true
3030
- run: go mod download
3131
- run: go build -v .
32-
- name: Run linters
33-
uses: golangci/golangci-lint-action@v6
34-
with:
35-
version: latest
32+
# - name: Run linters
33+
# uses: golangci/golangci-lint-action@v7
34+
# with:
35+
# version: latest
3636

3737
generate:
3838
runs-on: ubuntu-latest

.golangci.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# Visit https://golangci-lint.run/ for usage documentation
22
# and information on other useful linters
3+
version: "2"
34
issues:
4-
max-per-linter: 0
55
max-same-issues: 0
66

77
linters:
8-
disable-all: true
8+
default: none
99
enable:
1010
- durationcheck
1111
- errcheck
1212
- copyloopvar
1313
- forcetypeassert
1414
- godot
15-
- gofmt
16-
- gosimple
1715
- ineffassign
1816
- makezero
1917
- misspell
@@ -24,4 +22,4 @@ linters:
2422
- unconvert
2523
- unparam
2624
- unused
27-
- govet
25+
- govet

client/buildingblock.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ type MeshBuildingBlockSpec struct {
4646
}
4747

4848
type MeshBuildingBlockIO struct {
49-
Key string `json:"key" tfsdk:"key"`
50-
Value interface{} `json:"value" tfsdk:"value"`
51-
ValueType string `json:"valueType" tfsdk:"value_type"`
49+
Key string `json:"key" tfsdk:"key"`
50+
Value any `json:"value" tfsdk:"value"`
51+
ValueType string `json:"valueType" tfsdk:"value_type"`
5252
}
5353

5454
type MeshBuildingBlockParent struct {

client/buildingblock_v2.go

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package client
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
)
10+
11+
const (
12+
CONTENT_TYPE_BUILDING_BLOCK_V2 = "application/vnd.meshcloud.api.meshbuildingblock.v2-preview.hal+json"
13+
)
14+
15+
type MeshBuildingBlockV2 struct {
16+
ApiVersion string `json:"apiVersion" tfsdk:"api_version"`
17+
Kind string `json:"kind" tfsdk:"kind"`
18+
Metadata MeshBuildingBlockV2Metadata `json:"metadata" tfsdk:"metadata"`
19+
Spec MeshBuildingBlockV2Spec `json:"spec" tfsdk:"spec"`
20+
Status MeshBuildingBlockV2Status `json:"status" tfsdk:"status"`
21+
}
22+
23+
type MeshBuildingBlockV2Metadata struct {
24+
Uuid string `json:"uuid" tfsdk:"uuid"`
25+
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
26+
CreatedOn string `json:"createdOn" tfsdk:"created_on"`
27+
MarkedForDeletionOn *string `json:"markedForDeletionOn" tfsdk:"marked_for_deletion_on"`
28+
MarkedForDeletionBy *string `json:"markedForDeletionBy" tfsdk:"marked_for_deletion_by"`
29+
}
30+
31+
type MeshBuildingBlockV2Spec struct {
32+
BuildingBlockDefinitionVersionRef MeshBuildingBlockV2DefinitionVersionRef `json:"buildingBlockDefinitionVersionRef" tfsdk:"building_block_definition_version_ref"`
33+
TargetRef MeshBuildingBlockV2TargetRef `json:"targetRef" tfsdk:"target_ref"`
34+
DisplayName string `json:"displayName" tfsdk:"display_name"`
35+
36+
Inputs []MeshBuildingBlockIO `json:"inputs" tfsdk:"inputs"`
37+
ParentBuildingBlocks []MeshBuildingBlockParent `json:"parentBuildingBlocks" tfsdk:"parent_building_blocks"`
38+
}
39+
40+
type MeshBuildingBlockV2DefinitionVersionRef struct {
41+
Uuid string `json:"uuid" tfsdk:"uuid"`
42+
}
43+
44+
type MeshBuildingBlockV2TargetRef struct {
45+
Kind string `json:"kind" tfsdk:"kind"`
46+
Uuid *string `json:"uuid" tfsdk:"uuid"`
47+
Identifier *string `json:"identifier" tfsdk:"identifier"`
48+
}
49+
50+
type MeshBuildingBlockV2Create struct {
51+
ApiVersion string `json:"apiVersion" tfsdk:"api_version"`
52+
Kind string `json:"kind" tfsdk:"kind"`
53+
Spec MeshBuildingBlockV2Spec `json:"spec" tfsdk:"spec"`
54+
}
55+
56+
type MeshBuildingBlockV2Status struct {
57+
Status string `json:"status" tfsdk:"status"`
58+
Outputs []MeshBuildingBlockIO `json:"outputs" tfsdk:"outputs"`
59+
ForcePurge bool `json:"forcePurge" tfsdk:"force_purge"`
60+
}
61+
62+
func (c *MeshStackProviderClient) ReadBuildingBlockV2(uuid string) (*MeshBuildingBlockV2, error) {
63+
targetUrl := c.urlForBuildingBlock(uuid)
64+
65+
req, err := http.NewRequest("GET", targetUrl.String(), nil)
66+
if err != nil {
67+
return nil, err
68+
}
69+
req.Header.Set("Accept", CONTENT_TYPE_BUILDING_BLOCK_V2)
70+
71+
res, err := c.doAuthenticatedRequest(req)
72+
if err != nil {
73+
return nil, err
74+
}
75+
76+
defer res.Body.Close()
77+
78+
data, err := io.ReadAll(res.Body)
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
if res.StatusCode == 404 {
84+
return nil, nil
85+
}
86+
87+
if !isSuccessHTTPStatus(res) {
88+
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
89+
}
90+
91+
var bb MeshBuildingBlockV2
92+
err = json.Unmarshal(data, &bb)
93+
if err != nil {
94+
return nil, err
95+
}
96+
97+
return &bb, nil
98+
}
99+
100+
func (c *MeshStackProviderClient) CreateBuildingBlockV2(bb *MeshBuildingBlockV2Create) (*MeshBuildingBlockV2, error) {
101+
payload, err := json.Marshal(bb)
102+
if err != nil {
103+
return nil, err
104+
}
105+
106+
req, err := http.NewRequest("POST", c.endpoints.BuildingBlocks.String(), bytes.NewBuffer(payload))
107+
if err != nil {
108+
return nil, err
109+
}
110+
req.Header.Set("Content-Type", CONTENT_TYPE_BUILDING_BLOCK_V2)
111+
req.Header.Set("Accept", CONTENT_TYPE_BUILDING_BLOCK_V2)
112+
113+
res, err := c.doAuthenticatedRequest(req)
114+
if err != nil {
115+
return nil, err
116+
}
117+
118+
defer res.Body.Close()
119+
120+
data, err := io.ReadAll(res.Body)
121+
if err != nil {
122+
return nil, err
123+
}
124+
125+
if !isSuccessHTTPStatus(res) {
126+
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
127+
}
128+
129+
var createdBb MeshBuildingBlockV2
130+
err = json.Unmarshal(data, &createdBb)
131+
if err != nil {
132+
return nil, err
133+
}
134+
135+
return &createdBb, nil
136+
}
137+
138+
func (c *MeshStackProviderClient) DeleteBuildingBlockV2(uuid string) error {
139+
targetUrl := c.urlForBuildingBlock(uuid)
140+
return c.deleteMeshObject(*targetUrl, 202)
141+
}
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meshstack_building_block_v2 Data Source - terraform-provider-meshstack"
4+
subcategory: ""
5+
description: |-
6+
Single building block by UUID.
7+
~> Note: This resource is in preview. It's incomplete and will change in the near future.
8+
---
9+
10+
# meshstack_building_block_v2 (Data Source)
11+
12+
Single building block by UUID.
13+
14+
~> **Note:** This resource is in preview. It's incomplete and will change in the near future.
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `metadata` (Attributes) Building block metadata. (see [below for nested schema](#nestedatt--metadata))
24+
25+
### Read-Only
26+
27+
- `api_version` (String) Building block datatype version
28+
- `kind` (String) meshObject type, always `meshBuildingBlock`.
29+
- `spec` (Attributes) Building block specification. (see [below for nested schema](#nestedatt--spec))
30+
- `status` (Attributes) Current building block status. (see [below for nested schema](#nestedatt--status))
31+
32+
<a id="nestedatt--metadata"></a>
33+
### Nested Schema for `metadata`
34+
35+
Required:
36+
37+
- `uuid` (String) UUID which uniquely identifies the building block.
38+
39+
Read-Only:
40+
41+
- `created_on` (String) Timestamp of building block creation.
42+
- `marked_for_deletion_by` (String) For deleted building blocks: user who requested deletion.
43+
- `marked_for_deletion_on` (String) For deleted building blocks: timestamp of deletion.
44+
- `owned_by_workspace` (String) The workspace containing this building block.
45+
46+
47+
<a id="nestedatt--spec"></a>
48+
### Nested Schema for `spec`
49+
50+
Read-Only:
51+
52+
- `building_block_definition_version_ref` (Attributes) References the building block definition this building block is based on. (see [below for nested schema](#nestedatt--spec--building_block_definition_version_ref))
53+
- `display_name` (String) Display name for the building block as shown in meshPanel.
54+
- `inputs` (Attributes Map) Contains all building block inputs. Each input has exactly one value attribute set according to its' type. (see [below for nested schema](#nestedatt--spec--inputs))
55+
- `parent_building_blocks` (Attributes List) List of parent building blocks. (see [below for nested schema](#nestedatt--spec--parent_building_blocks))
56+
- `target_ref` (Attributes) References the building block target. Depending on the building block definition this will be a workspace or a tenant (see [below for nested schema](#nestedatt--spec--target_ref))
57+
58+
<a id="nestedatt--spec--building_block_definition_version_ref"></a>
59+
### Nested Schema for `spec.building_block_definition_version_ref`
60+
61+
Read-Only:
62+
63+
- `uuid` (String) UUID of the building block definition.
64+
65+
66+
<a id="nestedatt--spec--inputs"></a>
67+
### Nested Schema for `spec.inputs`
68+
69+
Read-Only:
70+
71+
- `value_bool` (Boolean)
72+
- `value_file` (String)
73+
- `value_int` (Number)
74+
- `value_list` (String) JSON encoded list of objects.
75+
- `value_single_select` (String)
76+
- `value_string` (String)
77+
78+
79+
<a id="nestedatt--spec--parent_building_blocks"></a>
80+
### Nested Schema for `spec.parent_building_blocks`
81+
82+
Read-Only:
83+
84+
- `buildingblock_uuid` (String) UUID of the parent building block.
85+
- `definition_uuid` (String) UUID of the parent building block definition.
86+
87+
88+
<a id="nestedatt--spec--target_ref"></a>
89+
### Nested Schema for `spec.target_ref`
90+
91+
Read-Only:
92+
93+
- `identifier` (String) Identifier of the target workspace.
94+
- `kind` (String) Target kind for this building block, depends on building block definition type. One of `meshTenant`, `meshWorkspace`.
95+
- `uuid` (String) UUID of the target tenant.
96+
97+
98+
99+
<a id="nestedatt--status"></a>
100+
### Nested Schema for `status`
101+
102+
Read-Only:
103+
104+
- `force_purge` (Boolean) Indicates whether an operator has requested purging of this Building Block.
105+
- `outputs` (Attributes Map) Building block outputs. Each output has exactly one value attribute set. (see [below for nested schema](#nestedatt--status--outputs))
106+
- `status` (String) Execution status. One of `WAITING_FOR_DEPENDENT_INPUT`, `WAITING_FOR_OPERATOR_INPUT`, `PENDING`, `IN_PROGRESS`, `SUCCEEDED`, `FAILED`.
107+
108+
<a id="nestedatt--status--outputs"></a>
109+
### Nested Schema for `status.outputs`
110+
111+
Read-Only:
112+
113+
- `value_bool` (Boolean)
114+
- `value_file` (String)
115+
- `value_int` (Number)
116+
- `value_list` (String) JSON encoded list of objects.
117+
- `value_single_select` (String)
118+
- `value_string` (String)

0 commit comments

Comments
 (0)