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

Packet bare metal cloud hosting platform provider #2260

Merged
merged 1 commit into from
Oct 7, 2015
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
12 changes: 12 additions & 0 deletions builtin/bins/provider-packet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"github.com/hashicorp/terraform/builtin/providers/packet"
"github.com/hashicorp/terraform/plugin"
)

func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: packet.Provider,
})
}
18 changes: 18 additions & 0 deletions builtin/providers/packet/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package packet

import (
"github.com/packethost/packngo"
)

const (
consumerToken = "aZ9GmqHTPtxevvFq9SK3Pi2yr9YCbRzduCSXF2SNem5sjB91mDq7Th3ZwTtRqMWZ"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used by us to identify the source of a request, this is the one we issued for terraform. basically, it is not required, but if it is not present then we rate limit the requests. it is also not used for authentication, that is what the end user's auth token is used for. does that make sense?

)

type Config struct {
AuthToken string
}

// Client() returns a new client for accessing packet.
func (c *Config) Client() *packngo.Client {
return packngo.NewClient(consumerToken, c.AuthToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, https://www.packet.net/dev/api/#authentication

Is the consumerToken something undocumented?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a note on your other note, happy to add to the docs if that will be clear to end users, but it is not a parameter that should / will change unless folks are editing source code for some reason, like forking terraform for another service or something. does that make sense?

}
36 changes: 36 additions & 0 deletions builtin/providers/packet/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package packet

import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)

// Provider returns a schema.Provider for Packet.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"auth_token": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("PACKET_AUTH_TOKEN", nil),
Description: "The API auth key for API operations.",
},
},

ResourcesMap: map[string]*schema.Resource{
"packet_device": resourcePacketDevice(),
"packet_ssh_key": resourcePacketSSHKey(),
"packet_project": resourcePacketProject(),
},

ConfigureFunc: providerConfigure,
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
AuthToken: d.Get("auth_token").(string),
}

return config.Client(), nil
}
35 changes: 35 additions & 0 deletions builtin/providers/packet/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package packet

import (
"os"
"testing"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)

var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider

func init() {
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
"packet": testAccProvider,
}
}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}

func testAccPreCheck(t *testing.T) {
if v := os.Getenv("PACKET_AUTH_TOKEN"); v == "" {
t.Fatal("PACKET_AUTH_TOKEN must be set for acceptance tests")
}
}
Loading