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

@ -5,6 +5,28 @@ Server resource schema. Must have a region specified in the provider configurati
~> 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` + "\n" + `
### With key pair` + "\n" +
"```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")
}
` + "\n```" + `
### Boot from volume` + "\n" +
"```terraform" + `
@ -45,7 +67,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
}
` + "\n```" + `
@ -61,7 +83,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" {
@ -123,7 +145,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" {
@ -145,7 +167,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"
}
@ -158,7 +180,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")
}
` + "\n```"

View file

@ -563,7 +563,7 @@ func mapFields(ctx context.Context, serverResp *iaas.Server, model *Model) error
} else if serverResp.Id != nil {
serverId = *serverResp.Id
} else {
return fmt.Errorf("Server id not present")
return fmt.Errorf("server id not present")
}
idParts := []string{