-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
sitehost_ssh_key
resource for creating, modifying and del…
…eting SSH Keys
- Loading branch information
1 parent
55a4114
commit 41679ad
Showing
17 changed files
with
501 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sitehost_ssh_key Data Source - terraform-provider-sitehost" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# sitehost_ssh_key (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `content` (String) The `content` is the contents of the public key. | ||
- `label` (String) The `label` is the name of the SSH Key, and is displayed in CP. | ||
|
||
### Optional | ||
|
||
- `custom_image_access` (String) `custom_image_access` determines whether the key can be used to access custom images. | ||
|
||
### Read-Only | ||
|
||
- `date_added` (String) The `date_added` is the date/time when the SSH Key was added. | ||
- `date_updated` (String) The `date_updated` is the date/time when the SSH Key was updated. | ||
- `id` (String) The `id` is the ID of the SSH Key within SiteHost's systems. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
page_title: "sitehost_ssh_key Resource - terraform-provider-sitehost" | ||
subcategory: "" | ||
description: Provides a SiteHost SSH Key resource. This can be used to create, modify, and delete SSH Keys. | ||
|
||
--- | ||
|
||
# sitehost_ssh_key (Resource) | ||
|
||
Provides a SiteHost SSH Key resource. This can be used to create, modify, and delete SSH Keys. | ||
|
||
## Example Usage | ||
```hcl | ||
# Create an SSH Key | ||
resource "sitehost_ssh_key" "key" { | ||
label = "My New SSH Key" | ||
content = "ssh-rsa AAAAB3..." | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
### Required | ||
|
||
- `label` (String) The SSH Key label. | ||
- `content` (String, Sensitive) The string content of your SSH Public Key. | ||
|
||
### Optional | ||
|
||
- `custom_image_access` (String) Whether or not the SSH Key will have access to custom images (1: True, 0: False). | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the SSH Key. | ||
- `date_added` (String) The timestamp for when the SSH Key was created. | ||
- `date_updated` (String) The timestamp for when the SSH key was last updated. Defaults to the `date_added` value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SiteHost SSH Key | ||
|
||
This example adds an SSH Key to your account, for use when creating new servers. | ||
|
||
> Note: To run this example, first configure your SiteHost provider as described in <https://kb.sitehost.nz/developers/terraform-provider>. | ||
## Prerequisites | ||
|
||
Your `Client ID` and `API Key` values can be generated<https://cp.sitehost.nz/api/list-keys> by clicking "Add API Key". You can find out how to do this in our [knowledge base](https://kb.sitehost.nz/developers/api). | ||
|
||
You will need to export your SiteHost Client ID and API Key as an environment variable: | ||
|
||
```sh | ||
export TF_VAR_sitehost_client_id="Put your SiteHost Client ID here" | ||
export TF_VAR_sitehost_api_key="Put your SiteHost API key here" | ||
export TF_VAR_ssh_key_label="Put the SSH Key label here" | ||
export TF_VAR_ssh_key_data="Put the contents of your SSH Public Key here" | ||
``` | ||
|
||
## Run this example | ||
|
||
From the `examples/ssh_key` directory. | ||
|
||
```sh | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
> The SSH Key should be added | ||
## Destroy the Resources | ||
|
||
Clean up by removing all the resources that were created in one command: | ||
|
||
```sh | ||
terraform destroy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
terraform { | ||
required_providers { | ||
sitehost = { | ||
source = "sitehostnz/sitehost" | ||
version = "~> 1.1.1" | ||
} | ||
} | ||
} | ||
|
||
provider "sitehost" { | ||
client_id = var.sitehost_client_id | ||
api_key = var.sitehost_api_key | ||
api_endpoint = "https://api.sitehost.nz/1.1/" | ||
} | ||
|
||
resource "sitehost_ssh_key" "sitehost_ssh_key_create" { | ||
label = var.ssh_key_label | ||
content = var.ssh_key_data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "sitehost_client_id" { | ||
description = "SiteHost API v1.1 Client ID" | ||
} | ||
|
||
variable "sitehost_api_key" { | ||
description = "SiteHost API v1.1 API Key" | ||
} | ||
|
||
variable "ssh_key_label" { | ||
description = "Label for the SSH Key" | ||
} | ||
|
||
variable "ssh_key_data" { | ||
description = "Content of the SSH Public Key" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package sshkey | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
sshkey "github.com/sitehostnz/gosh/pkg/api/ssh/key" | ||
"github.com/sitehostnz/terraform-provider-sitehost/sitehost/helper" | ||
) | ||
|
||
// DataSource returns a schema with the function to read Server resource. | ||
func DataSource() *schema.Resource { | ||
recordSchema := sshKeyDataSourceSchema() | ||
|
||
return &schema.Resource{ | ||
ReadContext: readDataSource, | ||
Schema: recordSchema, | ||
} | ||
} | ||
|
||
// readDataSource is a function to read an SSH Key. | ||
func readDataSource(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | ||
conf, ok := meta.(*helper.CombinedConfig) | ||
if !ok { | ||
return diag.Errorf("failed to convert meta object") | ||
} | ||
|
||
client := sshkey.New(conf.Client) | ||
|
||
resp, err := client.Get(context.Background(), sshkey.GetRequest{ | ||
ID: d.Id(), | ||
}) | ||
if err != nil { | ||
return diag.Errorf("Error retrieving SSH Key: %s", err) | ||
} | ||
|
||
if !resp.Status { | ||
return diag.Errorf("Error retrieving SSH Key: %s", resp.Msg) | ||
} | ||
|
||
if diagErr := setData(resp, d); diagErr != nil { | ||
return diagErr | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.