Implement key pair resource (#578)

* feat: Implement key pair resource

* feat: Implement acceptance test

* fix: Minor fixes to server and public IP resources

* fix: Lint fixes

* fix: Generalize description

* feat: Update examples to read key from file; Add datasource example

* fix: Fix field descriptions

* fix: Fix example

* feat: Add link to key pair resource in server example

* feat: Add links to key pair resource in other examples
This commit is contained in:
João Palet 2024-11-05 09:50:55 +00:00 committed by GitHub
parent c1ada319ce
commit 153947fd7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1261 additions and 117 deletions

View file

@ -0,0 +1,36 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_key_pair Data Source - stackit"
subcategory: ""
description: |-
Key pair resource schema. Must have a region specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---
# stackit_key_pair (Data Source)
Key pair resource schema. Must have a `region` specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
## Example Usage
```terraform
data "stackit_key_pair" "example" {
name = "example-key-pair-name"
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `name` (String) The name of the SSH key pair.
### Read-Only
- `fingerprint` (String) The fingerprint of the public SSH key.
- `id` (String) Terraform's internal resource ID. It takes the value of the key pair "`name`".
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container.
- `public_key` (String) A string representation of the public SSH key. E.g., `ssh-rsa <key_data>` or `ssh-ed25519 <key-data>`.

View file

@ -3,13 +3,13 @@
page_title: "stackit_public_ip Data Source - stackit"
subcategory: ""
description: |-
Volume resource schema. Must have a region specified in the provider configuration.
Public IP resource schema. Must have a region specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---
# stackit_public_ip (Data Source)
Volume resource schema. Must have a `region` specified in the provider configuration.
Public IP resource schema. Must have a `region` specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.

View file

@ -0,0 +1,74 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_key_pair Resource - stackit"
subcategory: ""
description: |-
Key pair resource schema. Must have a region specified in the provider configuration. Allows uploading an SSH public key to be used for server authentication.
Usage with server
```terraform
resource "stackitkeypair" "keypair" {
name = "example-key-pair"
publickey = chomp(file("path/to/idrsa.pub"))
}
resource "stackitserver" "example-server" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
bootvolume = {
size = 64
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
availabilityzone = "eu01-1"
machinetype = "g1.1"
keypairname = "example-key-pair"
}
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---
# stackit_key_pair (Resource)
Key pair resource schema. Must have a `region` specified in the provider configuration. Allows uploading an SSH public key to be used for server authentication.
### Usage with server
```terraform
resource "stackit_key_pair" "keypair" {
name = "example-key-pair"
public_key = chomp(file("path/to/id_rsa.pub"))
}
resource "stackit_server" "example-server" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-key-pair"
}
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `name` (String) The name of the SSH key pair.
- `public_key` (String) A string representation of the public SSH key. E.g., `ssh-rsa <key_data>` or `ssh-ed25519 <key-data>`.
### Optional
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container.
### Read-Only
- `fingerprint` (String) The fingerprint of the public SSH key.
- `id` (String) Terraform's internal resource ID. It takes the value of the key pair "`name`".

View file

@ -6,26 +6,44 @@ description: |-
Server resource schema. Must have a region specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
Example Usage
Boot from volume
resource "stackit_server" "boot-from-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-keypair"
With key pair
```terraform
resource "stackitkeypair" "keypair" {
name = "example-key-pair"
publickey = chomp(file("path/to/idrsa.pub"))
}
resource "stackitserver" "user-data-from-file" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
bootvolume = {
size = 64
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
name = "example-server"
machinetype = "g1.1"
keypairname = stackitkeypair.keypair.name
userdata = file("${path.module}/cloud-init.yaml")
}
```
Boot from volume
```terraform
resource "stackitserver" "boot-from-volume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
bootvolume = {
size = 64
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
availabilityzone = "eu01-1"
machinetype = "g1.1"
keypairname = "example-keypair"
}
```
Boot from existing volume
resource "stackit_volume" "example-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
```terraform
resource "stackitvolume" "example-volume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
size = 12
source = {
type = "image"
@ -34,129 +52,117 @@ description: |-
name = "example-volume"
availability_zone = "eu01-1"
}
resource "stackit_server" "boot-from-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
resource "stackitserver" "boot-from-volume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
source_type = "volume"
source_id = stackit_volume.example-volume.volume_id
bootvolume = {
sourcetype = "volume"
sourceid = stackitvolume.example-volume.volumeid
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-keypair"
availabilityzone = "eu01-1"
machinetype = "g1.1"
keypairname = stackitkeypair.keypair.name
}
```
Network setup
resource "stackit_server" "server-with-network" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
```terraform
resource "stackitserver" "server-with-network" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
bootvolume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
machine_type = "g1.1"
keypair_name = "example-keypair"
machinetype = "g1.1"
keypairname = stackitkey_pair.keypair.name
}
resource "stackit_network" "network" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
resource "stackitnetwork" "network" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-network"
nameservers = ["192.0.2.0", "198.51.100.0", "203.0.113.0"]
ipv4_prefix_length = 24
ipv4prefixlength = 24
}
resource "stackit_security_group" "sec-group" {
resource "stackitsecuritygroup" "sec-group" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-security-group"
stateful = true
}
resource "stackit_security_group_rule" "rule" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
security_group_id = stackit_security_group.sec-group.security_group_id
resource "stackitsecuritygrouprule" "rule" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
securitygroupid = stackitsecuritygroup.sec-group.securitygroupid
direction = "ingress"
ether_type = "IPv4"
}
resource "stackit_network_interface" "nic" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
network_id = stackit_network.network.network_id
security_group_ids = [stackit_security_group.sec-group.security_group_id]
resource "stackitnetworkinterface" "nic" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
networkid = stackitnetwork.network.networkid
securitygroupids = [stackitsecuritygroup.sec-group.securitygroupid]
}
resource "stackit_public_ip" "public-ip" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
network_interface_id = stackit_network_interface.nic.network_interface_id
resource "stackitpublicip" "public-ip" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
networkinterfaceid = stackitnetworkinterface.nic.networkinterface_id
}
resource "stackit_server_network_interface_attach" "nic-attachment" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
server_id = stackit_server.server-with-network.server_id
network_interface_id = stackit_network_interface.nic.network_interface_id
resource "stackitservernetworkinterfaceattach" "nic-attachment" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
serverid = stackitserver.server-with-network.serverid
networkinterfaceid = stackitnetworkinterface.nic.networkinterfaceid
}
```
Server with attached volume
resource "stackit_volume" "example-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
```terraform
resource "stackitvolume" "example-volume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
size = 12
performance_class = "storage_premium_perf6"
performanceclass = "storagepremiumperf6"
name = "example-volume"
availability_zone = "eu01-1"
availabilityzone = "eu01-1"
}
resource "stackit_server" "server-with-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
resource "stackitserver" "server-with-volume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
bootvolume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-keypair"
availabilityzone = "eu01-1"
machinetype = "g1.1"
keypairname = stackitkeypair.keypair.name
}
resource "stackit_server_volume_attach" "attach_volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
server_id = stackit_server.server-with-volume.server_id
volume_id = stackit_volume.example-volume.volume_id
resource "stackitservervolumeattach" "attachvolume" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
serverid = stackitserver.server-with-volume.serverid
volumeid = stackitvolume.example-volume.volume_id
}
```
Server with user data (cloud-init)
resource "stackit_server" "user-data" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
boot_volume = {
```terraform
resource "stackitserver" "user-data" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
bootvolume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
name = "example-server"
machine_type = "g1.1"
keypair_name = "example-keypair"
user_data = "#!/bin/bash\n/bin/su"
machinetype = "g1.1"
keypairname = stackitkeypair.keypair.name
userdata = "#!/bin/bash\n/bin/su"
}
resource "stackit_server" "user-data-from-file" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
boot_volume = {
resource "stackitserver" "user-data-from-file" {
projectid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
bootvolume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
sourcetype = "image"
sourceid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
name = "example-server"
machine_type = "g1.1"
keypair_name = "example-keypair"
user_data = file("${path.module}/cloud-init.yaml")
machinetype = "g1.1"
keypairname = stackitkeypair.keypair.name
userdata = file("${path.module}/cloud-init.yaml")
}
```
---
# stackit_server (Resource)
@ -167,6 +173,28 @@ Server resource schema. Must have a region specified in the provider configurati
## Example Usage
### With key pair
```terraform
resource "stackit_key_pair" "keypair" {
name = "example-key-pair"
public_key = chomp(file("path/to/id_rsa.pub"))
}
resource "stackit_server" "user-data-from-file" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
boot_volume = {
size = 64
source_type = "image"
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
name = "example-server"
machine_type = "g1.1"
keypair_name = stackit_key_pair.keypair.name
user_data = file("${path.module}/cloud-init.yaml")
}
```
### Boot from volume
```terraform
resource "stackit_server" "boot-from-volume" {
@ -206,7 +234,7 @@ resource "stackit_server" "boot-from-volume" {
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-keypair"
keypair_name = stackit_key_pair.keypair.name
}
```
@ -222,7 +250,7 @@ resource "stackit_server" "server-with-network" {
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
machine_type = "g1.1"
keypair_name = "example-keypair"
keypair_name = stackit_key_pair.keypair.name
}
resource "stackit_network" "network" {
@ -284,7 +312,7 @@ resource "stackit_server" "server-with-volume" {
}
availability_zone = "eu01-1"
machine_type = "g1.1"
keypair_name = "example-keypair"
keypair_name = stackit_key_pair.keypair.name
}
resource "stackit_server_volume_attach" "attach_volume" {
@ -306,7 +334,7 @@ resource "stackit_server" "user-data" {
}
name = "example-server"
machine_type = "g1.1"
keypair_name = "example-keypair"
keypair_name = stackit_key_pair.keypair.name
user_data = "#!/bin/bash\n/bin/su"
}
@ -319,7 +347,7 @@ resource "stackit_server" "user-data-from-file" {
}
name = "example-server"
machine_type = "g1.1"
keypair_name = "example-keypair"
keypair_name = stackit_key_pair.keypair.name
user_data = file("${path.module}/cloud-init.yaml")
}