Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
cache: true
- run: go mod download
- run: go build -v .
- name: Run linters
uses: golangci/golangci-lint-action@v6
with:
version: latest
# - name: Run linters
# uses: golangci/golangci-lint-action@v7
# with:
# version: latest

generate:
runs-on: ubuntu-latest
Expand Down
8 changes: 3 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters
version: "2"
issues:
max-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
default: none
enable:
- durationcheck
- errcheck
- copyloopvar
- forcetypeassert
- godot
- gofmt
- gosimple
- ineffassign
- makezero
- misspell
Expand All @@ -24,4 +22,4 @@ linters:
- unconvert
- unparam
- unused
- govet
- govet
6 changes: 3 additions & 3 deletions client/buildingblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type MeshBuildingBlockSpec struct {
}

type MeshBuildingBlockIO struct {
Key string `json:"key" tfsdk:"key"`
Value interface{} `json:"value" tfsdk:"value"`
ValueType string `json:"valueType" tfsdk:"value_type"`
Key string `json:"key" tfsdk:"key"`
Value any `json:"value" tfsdk:"value"`
ValueType string `json:"valueType" tfsdk:"value_type"`
}

type MeshBuildingBlockParent struct {
Expand Down
141 changes: 141 additions & 0 deletions client/buildingblock_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package client

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)

const (
CONTENT_TYPE_BUILDING_BLOCK_V2 = "application/vnd.meshcloud.api.meshbuildingblock.v2-preview.hal+json"
)

type MeshBuildingBlockV2 struct {
ApiVersion string `json:"apiVersion" tfsdk:"api_version"`
Kind string `json:"kind" tfsdk:"kind"`
Metadata MeshBuildingBlockV2Metadata `json:"metadata" tfsdk:"metadata"`
Spec MeshBuildingBlockV2Spec `json:"spec" tfsdk:"spec"`
Status MeshBuildingBlockV2Status `json:"status" tfsdk:"status"`
}

type MeshBuildingBlockV2Metadata struct {
Uuid string `json:"uuid" tfsdk:"uuid"`
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
CreatedOn string `json:"createdOn" tfsdk:"created_on"`
MarkedForDeletionOn *string `json:"markedForDeletionOn" tfsdk:"marked_for_deletion_on"`
MarkedForDeletionBy *string `json:"markedForDeletionBy" tfsdk:"marked_for_deletion_by"`
}

type MeshBuildingBlockV2Spec struct {
BuildingBlockDefinitionVersionRef MeshBuildingBlockV2DefinitionVersionRef `json:"buildingBlockDefinitionVersionRef" tfsdk:"building_block_definition_version_ref"`
TargetRef MeshBuildingBlockV2TargetRef `json:"targetRef" tfsdk:"target_ref"`
DisplayName string `json:"displayName" tfsdk:"display_name"`

Inputs []MeshBuildingBlockIO `json:"inputs" tfsdk:"inputs"`
ParentBuildingBlocks []MeshBuildingBlockParent `json:"parentBuildingBlocks" tfsdk:"parent_building_blocks"`
}

type MeshBuildingBlockV2DefinitionVersionRef struct {
Uuid string `json:"uuid" tfsdk:"uuid"`
}

type MeshBuildingBlockV2TargetRef struct {
Kind string `json:"kind" tfsdk:"kind"`
Uuid *string `json:"uuid" tfsdk:"uuid"`
Identifier *string `json:"identifier" tfsdk:"identifier"`
}

type MeshBuildingBlockV2Create struct {
ApiVersion string `json:"apiVersion" tfsdk:"api_version"`
Kind string `json:"kind" tfsdk:"kind"`
Spec MeshBuildingBlockV2Spec `json:"spec" tfsdk:"spec"`
}

type MeshBuildingBlockV2Status struct {
Status string `json:"status" tfsdk:"status"`
Outputs []MeshBuildingBlockIO `json:"outputs" tfsdk:"outputs"`
ForcePurge bool `json:"forcePurge" tfsdk:"force_purge"`
}

func (c *MeshStackProviderClient) ReadBuildingBlockV2(uuid string) (*MeshBuildingBlockV2, error) {
targetUrl := c.urlForBuildingBlock(uuid)

req, err := http.NewRequest("GET", targetUrl.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", CONTENT_TYPE_BUILDING_BLOCK_V2)

res, err := c.doAuthenticatedRequest(req)
if err != nil {
return nil, err
}

defer res.Body.Close()

data, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if res.StatusCode == 404 {
return nil, nil
}

if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

var bb MeshBuildingBlockV2
err = json.Unmarshal(data, &bb)
if err != nil {
return nil, err
}

return &bb, nil
}

func (c *MeshStackProviderClient) CreateBuildingBlockV2(bb *MeshBuildingBlockV2Create) (*MeshBuildingBlockV2, error) {
payload, err := json.Marshal(bb)
if err != nil {
return nil, err
}

req, err := http.NewRequest("POST", c.endpoints.BuildingBlocks.String(), bytes.NewBuffer(payload))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", CONTENT_TYPE_BUILDING_BLOCK_V2)
req.Header.Set("Accept", CONTENT_TYPE_BUILDING_BLOCK_V2)

res, err := c.doAuthenticatedRequest(req)
if err != nil {
return nil, err
}

defer res.Body.Close()

data, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

var createdBb MeshBuildingBlockV2
err = json.Unmarshal(data, &createdBb)
if err != nil {
return nil, err
}

return &createdBb, nil
}

func (c *MeshStackProviderClient) DeleteBuildingBlockV2(uuid string) error {
targetUrl := c.urlForBuildingBlock(uuid)
return c.deleteMeshObject(*targetUrl, 202)
}
118 changes: 118 additions & 0 deletions docs/data-sources/building_block_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meshstack_building_block_v2 Data Source - terraform-provider-meshstack"
subcategory: ""
description: |-
Single building block by UUID.
~> Note: This resource is in preview. It's incomplete and will change in the near future.
---

# meshstack_building_block_v2 (Data Source)

Single building block by UUID.

~> **Note:** This resource is in preview. It's incomplete and will change in the near future.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `metadata` (Attributes) Building block metadata. (see [below for nested schema](#nestedatt--metadata))

### Read-Only

- `api_version` (String) Building block datatype version
- `kind` (String) meshObject type, always `meshBuildingBlock`.
- `spec` (Attributes) Building block specification. (see [below for nested schema](#nestedatt--spec))
- `status` (Attributes) Current building block status. (see [below for nested schema](#nestedatt--status))

<a id="nestedatt--metadata"></a>
### Nested Schema for `metadata`

Required:

- `uuid` (String) UUID which uniquely identifies the building block.

Read-Only:

- `created_on` (String) Timestamp of building block creation.
- `marked_for_deletion_by` (String) For deleted building blocks: user who requested deletion.
- `marked_for_deletion_on` (String) For deleted building blocks: timestamp of deletion.
- `owned_by_workspace` (String) The workspace containing this building block.


<a id="nestedatt--spec"></a>
### Nested Schema for `spec`

Read-Only:

- `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))
- `display_name` (String) Display name for the building block as shown in meshPanel.
- `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))
- `parent_building_blocks` (Attributes List) List of parent building blocks. (see [below for nested schema](#nestedatt--spec--parent_building_blocks))
- `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))

<a id="nestedatt--spec--building_block_definition_version_ref"></a>
### Nested Schema for `spec.building_block_definition_version_ref`

Read-Only:

- `uuid` (String) UUID of the building block definition.


<a id="nestedatt--spec--inputs"></a>
### Nested Schema for `spec.inputs`

Read-Only:

- `value_bool` (Boolean)
- `value_file` (String)
- `value_int` (Number)
- `value_list` (String) JSON encoded list of objects.
- `value_single_select` (String)
- `value_string` (String)


<a id="nestedatt--spec--parent_building_blocks"></a>
### Nested Schema for `spec.parent_building_blocks`

Read-Only:

- `buildingblock_uuid` (String) UUID of the parent building block.
- `definition_uuid` (String) UUID of the parent building block definition.


<a id="nestedatt--spec--target_ref"></a>
### Nested Schema for `spec.target_ref`

Read-Only:

- `identifier` (String) Identifier of the target workspace.
- `kind` (String) Target kind for this building block, depends on building block definition type. One of `meshTenant`, `meshWorkspace`.
- `uuid` (String) UUID of the target tenant.



<a id="nestedatt--status"></a>
### Nested Schema for `status`

Read-Only:

- `force_purge` (Boolean) Indicates whether an operator has requested purging of this Building Block.
- `outputs` (Attributes Map) Building block outputs. Each output has exactly one value attribute set. (see [below for nested schema](#nestedatt--status--outputs))
- `status` (String) Execution status. One of `WAITING_FOR_DEPENDENT_INPUT`, `WAITING_FOR_OPERATOR_INPUT`, `PENDING`, `IN_PROGRESS`, `SUCCEEDED`, `FAILED`.

<a id="nestedatt--status--outputs"></a>
### Nested Schema for `status.outputs`

Read-Only:

- `value_bool` (Boolean)
- `value_file` (String)
- `value_int` (Number)
- `value_list` (String) JSON encoded list of objects.
- `value_single_select` (String)
- `value_string` (String)
Loading
Loading