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

docs: added additional examples to SSH resources. #531

Merged
merged 5 commits into from
Oct 29, 2024
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
30 changes: 27 additions & 3 deletions docs/data-sources/ssh_key.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "spectrocloud_ssh_key Data Source - terraform-provider-spectrocloud"
subcategory: ""
description: |-

The SSH key data source allows you to retrieve information about SSH keys in Palette.
---

# spectrocloud_ssh_key (Data Source)

The SSH key data source allows you to retrieve information about SSH keys in Palette.

To learn more about SSH Keys in Palette, review the [SSH Keys](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) section of the documentation.

## Example Usage



You can specify the context as `project` or `tenant` to get the SSH key from the respective context.


Example with context as `project`.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "test-tf-ssh"
context = "project"
}
```

Example with context as `tenant`.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "global-tf-ssh"
context = "tenant"
}
```

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

Expand All @@ -23,4 +47,4 @@ description: |-

### Read-Only

- `ssh_key` (String, Sensitive) The SSH key value.
- `ssh_key` (String, Sensitive) The SSH key value. This is the public key that was uploaded to Palette.
49 changes: 40 additions & 9 deletions docs/resources/ssh_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,70 @@
page_title: "spectrocloud_ssh_key Resource - terraform-provider-spectrocloud"
subcategory: ""
description: |-

The SSH key resource allows you to manage SSH keys in Palette.
---

# spectrocloud_ssh_key (Resource)


The SSH key resource allows you to manage SSH keys in Palette.

You can learn more about managing ssh key by reviewing the [Create and Manage DNS Mappings](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) guide.
You can learn more about managing SSH keys in Palette by reviewing the [SSH Keys](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) guide.

~> The `ssh_key` resource will not generate an SSH key pair. You must provide the public key to an existing SSH key as a string value to the `ssh_key` attribute. Refer to the [Generate Key with TLS Provider](#generate-ssh-key-with-tls-provider) section for additonal guidance.

## Example Usage

An example of creating an ssh key assets in project or tenant context.
An example of creating an SSH key resource in Palette.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "test-tf-ssh"
context = "project"
resource "spectrocloud_ssh_key" "ssh_tenant" {
name = "ssh-dev-1"
context = "project"
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ....."
}
```

The example below demonstrates how to create an SSH key resource in Palette with the `context` attribute set to `tenant`.

```hcl
resource "spectrocloud_ssh_key" "ssh_tenant" {
name = "ssh-dev-1"
context = "tenant"
ssh_key = data.spectrocloud_ssh_key.ssh_project.ssh_key
ssh_key = var.ssh_key_value
}
```

### Generate SSH Key with TLS Provider

The `ssh_key` resource will not generate an SSH key pair for you. This resource allows you upload and manage existing SSH keys in Palette that you can use to access your clusters. You can use the official HashiCorp [TLS provider](https://registry.terraform.io/providers/hashicorp/tls/latest/docs) to generate an SSH key pair and use the public key as a string value to the `ssh_key` attribute.


The following is an example of using the [`tls_private_key`](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) resource to generate an SSH key pair and use the public key as a string value to the `sshe_key` resource's `ssh_key` attribute. Keep in mind that you must specify the TLS provider in the `required_providers` block.


-> Use the `trimspace` function to remove any leading or trailing white spaces from the public key string.

```hcl
resource "tls_private_key" "default_ssh_key" {
algorithm = "RSA"
rsa_bits = "4096"
}

resource "spectrocloud_ssh_key" "primary_key_1" {
name = "ssh-dev-1"
context = "tenant"
ssh_key = trimspace(tls_private_key.default_ssh_key.public_key_openssh)
}
```


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

### Required

- `name` (String) The name of the SSH key resource.
- `ssh_key` (String, Sensitive) The SSH key value.
- `ssh_key` (String, Sensitive) The SSH key value. This is the public key that will be used to access the cluster. Must be in the [Authorized Keys](https://www.ssh.com/academy/ssh/authorized-keys-openssh#format-of-the-authorized-keys-file) format, such as `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ...`

### Optional

Expand Down
4 changes: 3 additions & 1 deletion spectrocloud/data_source_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package spectrocloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -11,6 +12,7 @@ import (
func dataSourceSSHKey() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceSSHKeyRead,
Description: "The SSH key data source allows you to retrieve information about SSH keys in Palette.",

Schema: map[string]*schema.Schema{
"id": {
Expand All @@ -30,7 +32,7 @@ func dataSourceSSHKey() *schema.Resource {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "The SSH key value.",
Description: "The SSH key value. This is the public key that was uploaded to Palette.",
},
"context": {
Type: schema.TypeString,
Expand Down
6 changes: 4 additions & 2 deletions spectrocloud/resource_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package spectrocloud

import (
"context"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/spectrocloud/palette-sdk-go/api/models"
"time"
)

func resourceSSHKey() *schema.Resource {
Expand All @@ -15,6 +16,7 @@ func resourceSSHKey() *schema.Resource {
ReadContext: resourceSSHKeyRead,
UpdateContext: resourceSSHKeyUpdate,
DeleteContext: resourceSSHKeyDelete,
Description: "The SSH key resource allows you to manage SSH keys in Palette.",

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Expand All @@ -32,7 +34,7 @@ func resourceSSHKey() *schema.Resource {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: "The SSH key value.",
Description: "The SSH key value. This is the public key that will be used to access the cluster. Must be in the [Authorized Keys](https://www.ssh.com/academy/ssh/authorized-keys-openssh#format-of-the-authorized-keys-file) format, such as `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ...`",
},
"context": {
Type: schema.TypeString,
Expand Down
39 changes: 39 additions & 0 deletions templates/data-sources/ssh_key.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | plainmarkdown | trimspace | prefixlines " " }}

To learn more about SSH Keys in Palette, review the [SSH Keys](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) section of the documentation.

## Example Usage



You can specify the context as `project` or `tenant` to get the SSH key from the respective context.


Example with context as `project`.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "test-tf-ssh"
context = "project"
}
```

Example with context as `tenant`.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "global-tf-ssh"
context = "tenant"
}
```

{{ .SchemaMarkdown | trimspace }}
43 changes: 37 additions & 6 deletions templates/resources/ssh_key.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,54 @@ description: |-

{{ .Description | plainmarkdown | trimspace | prefixlines " " }}

You can learn more about managing ssh key by reviewing the [Create and Manage DNS Mappings](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) guide.
You can learn more about managing SSH keys in Palette by reviewing the [SSH Keys](https://docs.spectrocloud.com/clusters/cluster-management/ssh-keys/) guide.

~> The `ssh_key` resource will not generate an SSH key pair. You must provide the public key to an existing SSH key as a string value to the `ssh_key` attribute. Refer to the [Generate Key with TLS Provider](#generate-ssh-key-with-tls-provider) section for additonal guidance.

## Example Usage

An example of creating an ssh key assets in project or tenant context.
An example of creating an SSH key resource in Palette.

```hcl
data "spectrocloud_ssh_key" "ssh_project" {
name = "test-tf-ssh"
context = "project"
resource "spectrocloud_ssh_key" "ssh_tenant" {
name = "ssh-dev-1"
context = "project"
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ....."
}
```

The example below demonstrates how to create an SSH key resource in Palette with the `context` attribute set to `tenant`.

```hcl
resource "spectrocloud_ssh_key" "ssh_tenant" {
name = "ssh-dev-1"
context = "tenant"
ssh_key = data.spectrocloud_ssh_key.ssh_project.ssh_key
ssh_key = var.ssh_key_value
}
```

### Generate SSH Key with TLS Provider

The `ssh_key` resource will not generate an SSH key pair for you. This resource allows you upload and manage existing SSH keys in Palette that you can use to access your clusters. You can use the official HashiCorp [TLS provider](https://registry.terraform.io/providers/hashicorp/tls/latest/docs) to generate an SSH key pair and use the public key as a string value to the `ssh_key` attribute.


The following is an example of using the [`tls_private_key`](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) resource to generate an SSH key pair and use the public key as a string value to the `sshe_key` resource's `ssh_key` attribute. Keep in mind that you must specify the TLS provider in the `required_providers` block.


-> Use the `trimspace` function to remove any leading or trailing white spaces from the public key string.

```hcl
resource "tls_private_key" "default_ssh_key" {
algorithm = "RSA"
rsa_bits = "4096"
}

resource "spectrocloud_ssh_key" "primary_key_1" {
name = "ssh-dev-1"
context = "tenant"
ssh_key = trimspace(tls_private_key.default_ssh_key.public_key_openssh)
}
```


{{ .SchemaMarkdown | trimspace }}
Loading