mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
8921e10d71
Here is an example that will setup the following: + An SSH key resource. + A virtual server resource that uses an existing SSH key. + A virtual server resource using an existing SSH key and a Terraform managed SSH key (created as "test_key_1" in the example below). (create this as sl.tf and run terraform commands from this directory): ```hcl provider "softlayer" { username = "" api_key = "" } resource "softlayer_ssh_key" "test_key_1" { name = "test_key_1" public_key = "${file(\"~/.ssh/id_rsa_test_key_1.pub\")}" # Windows Example: # public_key = "${file(\"C:\ssh\keys\path\id_rsa_test_key_1.pub\")}" } resource "softlayer_virtual_guest" "my_server_1" { name = "my_server_1" domain = "example.com" ssh_keys = ["123456"] image = "DEBIAN_7_64" region = "ams01" public_network_speed = 10 cpu = 1 ram = 1024 } resource "softlayer_virtual_guest" "my_server_2" { name = "my_server_2" domain = "example.com" ssh_keys = ["123456", "${softlayer_ssh_key.test_key_1.id}"] image = "CENTOS_6_64" region = "ams01" public_network_speed = 10 cpu = 1 ram = 1024 } ``` You'll need to provide your SoftLayer username and API key, so that Terraform can connect. If you don't want to put credentials in your configuration file, you can leave them out: ``` provider "softlayer" {} ``` ...and instead set these environment variables: - **SOFTLAYER_USERNAME**: Your SoftLayer username - **SOFTLAYER_API_KEY**: Your API key
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package softlayer
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
return &schema.Provider{
|
|
Schema: map[string]*schema.Schema{
|
|
"username": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("SOFTLAYER_USERNAME", nil),
|
|
Description: "The user name for SoftLayer API operations.",
|
|
},
|
|
"api_key": &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
DefaultFunc: schema.EnvDefaultFunc("SOFTLAYER_API_KEY", nil),
|
|
Description: "The API key for SoftLayer API operations.",
|
|
},
|
|
},
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
"softlayer_virtual_guest": resourceSoftLayerVirtualGuest(),
|
|
"softlayer_ssh_key": resourceSoftLayerSSHKey(),
|
|
},
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
}
|
|
}
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
config := Config{
|
|
Username: d.Get("username").(string),
|
|
ApiKey: d.Get("api_key").(string),
|
|
}
|
|
|
|
return config.Client()
|
|
}
|