Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Tanzu Vsphere resource #65

Merged
merged 7 commits into from
Jun 27, 2022
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
10 changes: 5 additions & 5 deletions docs/data-sources/aws_nodepool.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
page_title: "TMC: tmc_nodepool"
page_title: "TMC: tmc_aws_nodepool"
layout: "tmc"
subcategory: "TKG Cluster"
description: |-
Get information on a specific nodepool of a AWS cluster in Tanzu Mission Control (TMC)
---

# Data Source: tmc_cluster
# Data Source: tmc_aws_nodepool

The TMC Nodepool data resource can be used to get the information of a nodepool for a AWS cluster in Tanzu Mission Control (TMC).

Expand All @@ -31,9 +31,9 @@ The following arguments are supported:
## Attributes Reference

* `id` - The UID of the Tanzu Cluster.
* `description` - (Optional) The description of the nodepool.
* `node_labels` - (Optional) A map of node labels to assign to the resource.
* `cloud_labels` - (Optional) A map of cloud labels to assign to the resource.
* `description` - The description of the nodepool.
* `node_labels` - A map of node labels to assign to the resource.
* `cloud_labels` - A map of cloud labels to assign to the resource.
* `availability_zone` - The AWS availability zone for the cluster's worker nodes.
* `instance_type` - Instance type of the EC2 nodes to be used as part of the nodepool.
* `version` - Version of Kubernetes to be used in the cluster.
32 changes: 32 additions & 0 deletions docs/data-sources/management_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
page_title: "TMC: tmc_management_cluster"
layout: "tmc"
subcategory: "Tanzu Management Clusters"
description: |-
Get information on a Management Cluster in the TMC platform
---

# Data Source: tmc_management_cluster

Use this data source to get the details about a management cluster in TMC platform.

## Example Usage
# Get details of a cluster group in the Tanzu platform.
```terraform
data "tmc_management_cluster" "example" {
name = "example-cluster"
}
```

## Argument Reference

* `name` - (Required) The name of the management cluster to lookup in the TMC platform.

## Attributes Reference

* `id` - Unique Identifiers (UID) of the found management cluster group in the TMC platform.
* `description` - Description of the management cluster.
* `labels` - A mapping of labels of the resource.
* `kubernetes_provider_type` - Type of cluster to be registered into TMC. Can be one of `tkg`, `tkgservice`, `tkghosted` or `other`
* `default_cluster_group` - Default cluster group for the workload clusters.
* `registration_url` - An URL to fetch the Tanzu Agent installation YAML which is necessary to establish connection to the registered cluster (if available)
36 changes: 36 additions & 0 deletions docs/data-sources/namespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
page_title: "TMC: tmc_namespace"
layout: "tmc"
subcategory: "Tanzu Namespace"
description: |-
Get information on a specific namespace of a cluster in Tanzu Mission Control (TMC)
---

# Data Source: tmc_namespace

The TMC Namespace data resource can be used to get the information of a namespace for a cluster in Tanzu Mission Control (TMC).

```terraform
data "tmc_namespace" "example" {
cluster_name = "example-cluster"
management_cluster = "example-hosted"
provisioner_name = "example-provisioner"
name = "example-ns"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the namespace. Changing the name forces recreation of this resource.
* `cluster_name` - (Required) The name of the Tanzu Cluster for which the namespace is to be created.
* `management_cluster` - (Required) Name of the management cluster used to provision the cluster.
* `provisioner_name` - (Required) Name of the provisioner to be used.

## Attributes Reference

* `id` - The UID of the Tanzu Cluster.
* `description` - The description of the nodepool.
* `workspace_name` - Name of the workspace for the created namespace.
* `labels` - A map of labels to assign to the resource.
4 changes: 2 additions & 2 deletions docs/resources/aws_nodepool.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
page_title: "TMC: tmc_nodepool"
page_title: "TMC: tmc_aws_nodepool"
layout: "tmc"
subcategory: "TKG Cluster"
description: |-
Creates and manages a nodepool for a AWS cluster in the TMC platform
---

# Resource: tmc_cluster
# Resource: tmc_aws_nodepool

The TMC Cluster resource allows requesting the creation of a nodepool for a AWS cluster in Tanzu Mission Control (TMC).

Expand Down
39 changes: 39 additions & 0 deletions docs/resources/management_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
page_title: "TMC: tmc_management_cluster"
layout: "tmc"
subcategory: "Tanzu Management Clusters"
description: |-
Creates and Registers a Management Cluster in the TMC platform
---

# Resource: tmc_management_cluster

The TMC Management Cluster resource allows requesting the creation of a management cluster in Tanzu Mission Control (TMC).

!> **Note**: This resource does not support `update` operation and hence will be destroyed and recreated for every change.

```terraform
resource "tmc_management_cluster" "example" {
name = "tf-mgmt-cluster"
description = "terraform created mgmt cluster"
kubernetes_provider_type = "tkg"
default_cluster_group = "default"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the Tanzu Management Cluster. Changing the name forces recreation of this resource.
* `description` - (Optional) The description of the Tanzu Management Cluster.
* `labels` - (Optional) A map of labels to assign to the resource.
* `kubernetes_provider_type` - (Required) Type of cluster to be registered into TMC. Can be one of `tkg`, `tkgservice`, `tkghosted` or `other`
* `default_cluster_group` - (Required) Default cluster group for the workload clusters.

## Attributes Reference

In addition to all arguments above, the following attribute is exported:

* `id` - The UID of the Tanzu Management Cluster.
* `registration_url` - An URL to fetch the Tanzu Agent installation YAML which is necessary to establish connection to the registered cluster.
43 changes: 43 additions & 0 deletions docs/resources/namespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
page_title: "TMC: tmc_namespace"
layout: "tmc"
subcategory: "Tanzu Namespace"
description: |-
Creates and manages a namespace for a cluster in the TMC platform
---

# Resource: tmc_namespace

The TMC Namespace resource allows requesting the creation of a namespace for a cluster in Tanzu Mission Control (TMC).

```terraform
resource "tmc_namespace" "example" {
name = "example-ns"
description = "terraform created mgmt cluster"
cluster_name = "example-cluster"
management_cluster = "example-hosted"
provisioner_name = "example-provisioner"
workspace_name = "default"
labels = {
"CreatedBy" = "terraform"
}
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the Namespace. Changing the name forces recreation of this resource.
* `description` - (Optional) The description of the namespace.
* `cluster_name` - (Required) The name of the Tanzu Cluster for which the namespace is to be created.
* `management_cluster` - (Required) Name of the management cluster used to provision the cluster.
* `provisioner_name` - (Required) Name of the provisioner to be used.
* `workspace_name` - (Required) Name of the workspace for the created namespace.
* `labels` - (Optional) A map of labels to assign to the resource.

## Attributes Reference

In addition to all arguments above, the following attribute is exported:

* `id` - The UID of the Tanzu Namespace.
78 changes: 78 additions & 0 deletions docs/resources/tmc_vsphere_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
page_title: "TMC: tmc_vsphere_cluster"
layout: "tmc"
subcategory: "TKG Cluster"
description: |-
Creates and manages a Vsphere Cluster in the TMC platform
---

# Resource: tmc_cluster

The TMC Cluster resource allows requesting the creation of a Vsphere cluster in Tanzu Mission Control (TMC). It also deals with managing the attributes and lifecycle of the cluster.


```terraform
resource "tmc_vsphere_cluster" "example" {
name = "example-vsphere-cluster"
management_cluster = "example-vpshere-mgmt-cluster"
provisioner_name = "example-provisioner"

version = "v1.21.6+vmware.1-tkg.1.b3d708a"
cluster_group = "default"

control_plane_spec {
class = "best-effort-xsmall"
storage_class = "vsphere-tanzu-example-storage-policy"
}

nodepool {
nodepool_name = "example-nodepool"
worker_node_count = 1
node_class = "best-effort-small"
node_storage_class = "vsphere-tanzu-example-storage-policy"
}
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) (Forces Replacement) The name of the Tanzu Cluster. Changing the name forces recreation of this resource.
* `description` - (Optional) (Forces Replacement) The description of the Tanzu Cluster.
* `labels` - (Optional) A map of labels to assign to the resource.
* `cluster_group` - (Required) A map of labels to assign to the resource.
* `management_cluster` - (Required) (Forces Replacement) Name of the management cluster used to provision the cluster.
* `provisioner_name` - (Required) (Forces Replacement) Name of the provisioner to be used.
* `version` - (Required) (Forces Replacement) Version of Kubernetes to be used in the cluster.
* `region` - (Required) (Forces Replacement) AWS region of the cluster.
* `pod_cidrblock` - (Optional) (Forces Replacement) Pod CIDR for Kubernetes pods. Defaults to 192.168.0.0/16.
* `service_cidrblock` - (Optional) (Forces Replacement) Service CIDR for Kubernetes services. Defaults to 10.96.0.0/12.
* [`control_plane_spec`](#control_plane_spec) - (Required) (Forces Replacement) Contains information related to the Control Plane of the cluster
* [`nodepool`](#nodepool) - (Required) (Forces Replacement) Contains information related to the Nodepool of the cluster

## Nested Blocks

#### `control_plane_spec`

#### Arguments

* `class` - (Required) Indicates the size of the VMs to be provisioned.
* `storage_class` - (Required) Storage Class to be used for storage of the disks which store the root filesystems of the nodes

#### `nodepool`

#### Arguments

* `nodepool_name` - (Required) Determines the name of the nodepool
* `worker_node_count` - (Required) Determines the number of worker nodes provisioned
* `node_class` - (Required) Determines the class of the worker node
* `node_storage_class` - (Required) Determines the storage policy used for the worker node


## Attributes Reference

In addition to all arguments above, the following attribute is exported:

* `id` - The UID of the Tanzu Cluster.
* `resource_version` - An identifier used to track changes to the resource
107 changes: 107 additions & 0 deletions tanzuclient/mgmt_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package tanzuclient

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

var k8sProviderTypeMap = map[string]string{
"tkg": "VMWARE_TANZU_KUBERNETES_GRID",
"tkgservice": "VMWARE_TANZU_KUBERNETES_GRID_SERVICE",
"tkghosted": "VMWARE_TANZU_KUBERNETES_GRID_HOSTED",
"other": "KUBERNETES_PROVIDER_UNSPECIFIED",
}

type MgmtClusterSpec struct {
KubernetesProviderType string `json:"kubernetesProviderType"`
DefaultClusterGroup string `json:"defaultClusterGroup"`
}

type ManagementCluster struct {
FullName *FullName `json:"fullName"`
Meta *MetaData `json:"meta"`
Spec *MgmtClusterSpec `json:"spec"`
Status struct {
RegistrationURL string `json:"registrationUrl,omitempty"`
}
}

type MgmtClusterJsonObject struct {
MgmtCluster ManagementCluster `json:"managementCluster"`
}

func (c *Client) CreateMgmtCluster(name string, defaultCg string, k8sProviderType string, description string, labels map[string]interface{}) (*ManagementCluster, error) {
requestURL := fmt.Sprintf("%s/v1alpha1/managementclusters", c.baseURL)

newMgmtCluster := &ManagementCluster{
FullName: &FullName{
Name: name,
},
Meta: &MetaData{
Description: description,
Labels: labels,
},
Spec: &MgmtClusterSpec{
KubernetesProviderType: k8sProviderTypeMap[k8sProviderType],
DefaultClusterGroup: defaultCg,
},
}

newMgmtClusterObject := &MgmtClusterJsonObject{
MgmtCluster: *newMgmtCluster,
}

json_data, err := json.Marshal(newMgmtClusterObject) // returns []byte
if err != nil {
return nil, err
}

req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(json_data))
if err != nil {
return nil, err
}

res := MgmtClusterJsonObject{}

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

return &res.MgmtCluster, nil
}

func (c *Client) GetMgmtCluster(name string) (*ManagementCluster, error) {
requestURL := fmt.Sprintf("%s/v1alpha1/managementclusters/%s", c.baseURL, name)

req, err := http.NewRequest("GET", requestURL, nil)
if err != nil {
return nil, err
}

res := MgmtClusterJsonObject{}

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

return &res.MgmtCluster, nil
}

func (c *Client) DeleteMgmtCluster(name string) error {
requestURL := fmt.Sprintf("%s/v1alpha1/managementclusters/%s", c.baseURL, name)

req, err := http.NewRequest("DELETE", requestURL, nil)
if err != nil {
return err
}

res := MgmtClusterJsonObject{}

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

return nil
}
Loading