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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
FEATURES:
- Added `meshstack_workspace` resource.
- Added `meshstack_workspace` data source.
- Added `meshstack_tenant_v4` resource.
- Added `meshstack_tenant_v4` data source.

FIXES:
- Allow `value_code` in `meshstack_building_block_v2` and `meshstack_building_block` resources.
Expand Down
144 changes: 144 additions & 0 deletions client/tenant_v4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package client

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

const CONTENT_TYPE_TENANT_V4 = "application/vnd.meshcloud.api.meshtenant.v4-preview.hal+json"

type MeshTenantV4 struct {
ApiVersion string `json:"apiVersion" tfsdk:"api_version"`
Kind string `json:"kind" tfsdk:"kind"`
Metadata MeshTenantV4Metadata `json:"metadata" tfsdk:"metadata"`
Spec MeshTenantV4Spec `json:"spec" tfsdk:"spec"`
Status MeshTenantV4Status `json:"status" tfsdk:"status"`
}

type MeshTenantV4Metadata struct {
Uuid string `json:"uuid" tfsdk:"uuid"`
OwnedByProject string `json:"ownedByProject" tfsdk:"owned_by_project"`
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
CreatedOn string `json:"createdOn" tfsdk:"created_on"`
MarkedForDeletionOn *string `json:"markedForDeletionOn" tfsdk:"marked_for_deletion_on"`
DeletedOn *string `json:"deletedOn" tfsdk:"deleted_on"`
}

type MeshTenantV4Spec struct {
PlatformIdentifier string `json:"platformIdentifier" tfsdk:"platform_identifier"`
PlatformTenantId *string `json:"platformTenantId" tfsdk:"platform_tenant_id"`
LandingZoneIdentifier *string `json:"landingZoneIdentifier" tfsdk:"landing_zone_identifier"`
Quotas *[]MeshTenantQuota `json:"quotas" tfsdk:"quotas"`
}

type MeshTenantV4Status struct {
TenantName string `json:"tenantName" tfsdk:"tenant_name"`
PlatformTypeIdentifier string `json:"platformTypeIdentifier" tfsdk:"platform_type_identifier"`
PlatformWorkspaceIdentifier *string `json:"platformWorkspaceIdentifier" tfsdk:"platform_workspace_identifier"`
Tags map[string][]string `json:"tags" tfsdk:"tags"`
}

type MeshTenantV4Create struct {
Metadata MeshTenantV4CreateMetadata `json:"metadata" tfsdk:"metadata"`
Spec MeshTenantV4CreateSpec `json:"spec" tfsdk:"spec"`
}

type MeshTenantV4CreateMetadata struct {
OwnedByProject string `json:"ownedByProject" tfsdk:"owned_by_project"`
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
}

type MeshTenantV4CreateSpec struct {
PlatformIdentifier string `json:"platformIdentifier" tfsdk:"platform_identifier"`
LandingZoneIdentifier *string `json:"landingZoneIdentifier" tfsdk:"landing_zone_identifier"`
PlatformTenantId *string `json:"platformTenantId" tfsdk:"platform_tenant_id"`
Quotas *[]MeshTenantQuota `json:"quotas" tfsdk:"quotas"`
}

func (c *MeshStackProviderClient) urlForTenantV4(uuid string) *url.URL {
return c.endpoints.Tenants.JoinPath(uuid)
}

func (c *MeshStackProviderClient) ReadTenantV4(uuid string) (*MeshTenantV4, error) {
targetUrl := c.urlForTenantV4(uuid)
req, err := http.NewRequest("GET", targetUrl.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", CONTENT_TYPE_TENANT_V4)

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 tenant MeshTenantV4
err = json.Unmarshal(data, &tenant)
if err != nil {
return nil, err
}

return &tenant, nil
}

func (c *MeshStackProviderClient) CreateTenantV4(tenant *MeshTenantV4Create) (*MeshTenantV4, error) {
payload, err := json.Marshal(tenant)
if err != nil {
return nil, err
}

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

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 createdTenant MeshTenantV4
err = json.Unmarshal(data, &createdTenant)
if err != nil {
return nil, err
}

return &createdTenant, nil
}

func (c *MeshStackProviderClient) DeleteTenantV4(uuid string) error {
targetUrl := c.urlForTenantV4(uuid)
return c.deleteMeshObject(*targetUrl, 202)
}
84 changes: 84 additions & 0 deletions docs/data-sources/tenant_v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meshstack_tenant_v4 Data Source - terraform-provider-meshstack"
subcategory: ""
description: |-
Fetches details of a single tenant by UUID.
~> Note: This resource is in preview and may change in the near future.
---

# meshstack_tenant_v4 (Data Source)

Fetches details of a single tenant by UUID.

~> **Note:** This resource is in preview and may change in the near future.

## Example Usage

```terraform
data "meshstack_tenant_v4" "example" {
metadata = {
uuid = "00000000-0000-0000-0000-000000000000" # Tenant UUID
}
}
```

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

### Required

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

### Read-Only

- `api_version` (String) Tenant datatype version
- `kind` (String) meshObject type, always `meshTenant`.
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))
- `status` (Attributes) Tenant status. (see [below for nested schema](#nestedatt--status))

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

Required:

- `uuid` (String) UUID of the tenant.

Read-Only:

- `created_on` (String) The date the tenant was created.
- `deleted_on` (String) If the tenant has been submitted for deletion by a workspace manager, the date is shown here.
- `marked_for_deletion_on` (String) Date when the tenant was marked for deletion.
- `owned_by_project` (String) Identifier of the project the tenant belongs to.
- `owned_by_workspace` (String) Identifier of the workspace the tenant belongs to.


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

Read-Only:

- `landing_zone_identifier` (String) Identifier of landing zone to assign to this tenant.
- `platform_identifier` (String) Identifier of the target platform.
- `platform_tenant_id` (String) Platform-specific tenant ID.
- `quotas` (Attributes List) Set of applied tenant quotas. (see [below for nested schema](#nestedatt--spec--quotas))

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

Read-Only:

- `key` (String)
- `value` (Number)



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

Read-Only:

- `platform_type_identifier` (String) Identifier of the platform type.
- `platform_workspace_identifier` (String) Identifier of the platform workspace.
- `tags` (Map of List of String) Tags assigned to this tenant.
- `tenant_name` (String) Name of the tenant.
118 changes: 118 additions & 0 deletions docs/resources/tenant_v4.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_tenant_v4 Resource - terraform-provider-meshstack"
subcategory: ""
description: |-
Manages a meshTenant with API version 4.
~> Note: This resource is in preview and may change in the near future.
---

# meshstack_tenant_v4 (Resource)

Manages a `meshTenant` with API version 4.

~> **Note:** This resource is in preview and may change in the near future.

## Example Usage

```terraform
data "meshstack_project" "example" {
metadata = {
name = "my-project-identifier"
owned_by_workspace = "my-workspace-identifier"
}
}

resource "meshstack_tenant_v4" "example" {
metadata = {
owned_by_workspace = data.meshstack_project.example.metadata.owned_by_workspace
owned_by_project = data.meshstack_project.example.metadata.name
}

spec = {
platform_identifier = "my-platform-identifier"
landing_zone_identifier = "platform-landing-zone-identifier"
}
}
```

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

### Required

- `metadata` (Attributes) Metadata of the tenant. The `owned_by_workspace` and `owned_by_project` attributes must be set here. (see [below for nested schema](#nestedatt--metadata))
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))

### Read-Only

- `api_version` (String) API version of the tenant resource.
- `kind` (String) The kind of the meshObject, always `meshTenant`.
- `status` (Attributes) Tenant status. (see [below for nested schema](#nestedatt--status))

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

Required:

- `owned_by_project` (String) The identifier of the project that the tenant belongs to.
- `owned_by_workspace` (String) The identifier of the workspace that the tenant belongs to.

Read-Only:

- `created_on` (String) The creation timestamp of the meshTenant (e.g. `2020-12-22T09:37:43Z`).
- `deleted_on` (String) The deletion timestamp of the tenant (e.g. `2020-12-22T09:37:43Z`).
- `marked_for_deletion_on` (String) The timestamp when the tenant was marked for deletion (e.g. `2020-12-22T09:37:43Z`).
- `uuid` (String) The unique identifier (UUID) of the tenant.


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

Required:

- `platform_identifier` (String) Identifier of the target platform.

Optional:

- `landing_zone_identifier` (String) The identifier of the landing zone to assign to this tenant.
- `platform_tenant_id` (String) The identifier of the tenant on the platform (e.g. GCP project ID or Azure subscription ID). If this is not set, a new tenant will be created. If this is set, an existing tenant will be imported. Otherwise, this field will be empty until a successful replication has run.
- `quotas` (Attributes Set) Landing zone quota settings will be applied by default but can be changed here. (see [below for nested schema](#nestedatt--spec--quotas))

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

Required:

- `key` (String)
- `value` (Number)



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

Read-Only:

- `platform_type_identifier` (String) Identifier of the platform type.
- `platform_workspace_identifier` (String) Some platforms create representations of workspaces, in such cases this will contain the identifier of the workspace on the platform.
- `quotas` (Attributes Set) The effective quotas applied to the tenant. (see [below for nested schema](#nestedatt--status--quotas))
- `tags` (Map of List of String) Tags assigned to this tenant.
- `tenant_name` (String) The full tenant name, a concatenation of the workspace identifier, project identifier and platform identifier.

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

Read-Only:

- `key` (String)
- `value` (Number)

## Import

Import is supported using the following syntax:

```shell
# import via uuid
terraform import 'meshstack_tenant_v4.example' '00000000-0000-0000-0000-000000000000'
```
5 changes: 5 additions & 0 deletions examples/data-sources/meshstack_tenant_v4/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "meshstack_tenant_v4" "example" {
metadata = {
uuid = "00000000-0000-0000-0000-000000000000" # Tenant UUID
}
}
2 changes: 2 additions & 0 deletions examples/resources/meshstack_tenant_v4/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# import via uuid
terraform import 'meshstack_tenant_v4.example' '00000000-0000-0000-0000-000000000000'
18 changes: 18 additions & 0 deletions examples/resources/meshstack_tenant_v4/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data "meshstack_project" "example" {
metadata = {
name = "my-project-identifier"
owned_by_workspace = "my-workspace-identifier"
}
}

resource "meshstack_tenant_v4" "example" {
metadata = {
owned_by_workspace = data.meshstack_project.example.metadata.owned_by_workspace
owned_by_project = data.meshstack_project.example.metadata.name
}

spec = {
platform_identifier = "my-platform-identifier"
landing_zone_identifier = "platform-landing-zone-identifier"
}
}
Loading
Loading