Merge branch 'master' into aws-go-vpn
This commit is contained in:
commit
7565e69ba3
|
@ -30,6 +30,7 @@ IMPROVEMENTS:
|
|||
info. [GH-1029]
|
||||
* **New config function: `split`** - Split a value based on a delimiter.
|
||||
This is useful for faking lists as parameters to modules.
|
||||
* **New resource: `digitalocean_ssh_key`** [GH-1074]
|
||||
* core: The serial of the state is only updated if there is an actual
|
||||
change. This will lower the amount of state changing on things
|
||||
like refresh.
|
||||
|
|
3
Makefile
3
Makefile
|
@ -12,6 +12,9 @@ bin: generate
|
|||
dev: generate
|
||||
@TF_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
|
||||
quickdev: generate
|
||||
@TF_QUICKDEV=1 TF_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||
|
||||
# test runs the unit tests and vets the code
|
||||
test: generate
|
||||
TF_ACC= go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4
|
||||
|
|
|
@ -156,7 +156,6 @@ func resourceAwsDbInstance() *schema.Resource {
|
|||
"final_snapshot_identifier": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"db_subnet_group_name": &schema.Schema{
|
||||
|
|
|
@ -21,6 +21,7 @@ func Provider() terraform.ResourceProvider {
|
|||
"digitalocean_domain": resourceDigitalOceanDomain(),
|
||||
"digitalocean_droplet": resourceDigitalOceanDroplet(),
|
||||
"digitalocean_record": resourceDigitalOceanRecord(),
|
||||
"digitalocean_ssh_key": resourceDigitalOceanSSHKey(),
|
||||
},
|
||||
|
||||
ConfigureFunc: providerConfigure,
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package digitalocean
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/pearkes/digitalocean"
|
||||
)
|
||||
|
||||
func resourceDigitalOceanSSHKey() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceDigitalOceanSSHKeyCreate,
|
||||
Read: resourceDigitalOceanSSHKeyRead,
|
||||
Update: resourceDigitalOceanSSHKeyUpdate,
|
||||
Delete: resourceDigitalOceanSSHKeyDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"public_key": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"fingerprint": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceDigitalOceanSSHKeyCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*digitalocean.Client)
|
||||
|
||||
// Build up our creation options
|
||||
opts := &digitalocean.CreateSSHKey{
|
||||
Name: d.Get("name").(string),
|
||||
PublicKey: d.Get("public_key").(string),
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] SSH Key create configuration: %#v", opts)
|
||||
id, err := client.CreateSSHKey(opts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating SSH Key: %s", err)
|
||||
}
|
||||
|
||||
d.SetId(id)
|
||||
log.Printf("[INFO] SSH Key: %s", id)
|
||||
|
||||
return resourceDigitalOceanSSHKeyRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceDigitalOceanSSHKeyRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*digitalocean.Client)
|
||||
|
||||
key, err := client.RetrieveSSHKey(d.Id())
|
||||
if err != nil {
|
||||
// If the key is somehow already destroyed, mark as
|
||||
// succesfully gone
|
||||
if strings.Contains(err.Error(), "404 Not Found") {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error retrieving SSH key: %s", err)
|
||||
}
|
||||
|
||||
d.Set("name", key.Name)
|
||||
d.Set("fingerprint", key.Fingerprint)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDigitalOceanSSHKeyUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*digitalocean.Client)
|
||||
|
||||
var newName string
|
||||
if v, ok := d.GetOk("name"); ok {
|
||||
newName = v.(string)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] SSH key update name: %#v", newName)
|
||||
err := client.RenameSSHKey(d.Id(), newName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to update SSH key: %s", err)
|
||||
}
|
||||
|
||||
return resourceDigitalOceanSSHKeyRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceDigitalOceanSSHKeyDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*digitalocean.Client)
|
||||
|
||||
log.Printf("[INFO] Deleting SSH key: %s", d.Id())
|
||||
err := client.DestroySSHKey(d.Id())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting SSH key: %s", err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package digitalocean
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/pearkes/digitalocean"
|
||||
)
|
||||
|
||||
func TestAccDigitalOceanSSHKey_Basic(t *testing.T) {
|
||||
var key digitalocean.SSHKey
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDigitalOceanSSHKeyDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccCheckDigitalOceanSSHKeyConfig_basic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDigitalOceanSSHKeyExists("digitalocean_ssh_key.foobar", &key),
|
||||
testAccCheckDigitalOceanSSHKeyAttributes(&key),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_ssh_key.foobar", "name", "foobar"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_ssh_key.foobar", "public_key", "abcdef"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanSSHKeyDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*digitalocean.Client)
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "digitalocean_ssh_key" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Try to find the key
|
||||
_, err := client.RetrieveSSHKey(rs.Primary.ID)
|
||||
|
||||
if err == nil {
|
||||
fmt.Errorf("SSH key still exists")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanSSHKeyAttributes(key *digitalocean.SSHKey) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
if key.Name != "foobar" {
|
||||
return fmt.Errorf("Bad name: %s", key.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanSSHKeyExists(n string, key *digitalocean.SSHKey) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", n)
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("No Record ID is set")
|
||||
}
|
||||
|
||||
client := testAccProvider.Meta().(*digitalocean.Client)
|
||||
|
||||
foundKey, err := client.RetrieveSSHKey(rs.Primary.ID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if foundKey.Name != rs.Primary.ID {
|
||||
return fmt.Errorf("Record not found")
|
||||
}
|
||||
|
||||
*key = foundKey
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccCheckDigitalOceanSSHKeyConfig_basic = `
|
||||
resource "digitalocean_ssh_key" "foobar" {
|
||||
name = "foobar"
|
||||
public_key = "abcdef"
|
||||
}`
|
|
@ -19,9 +19,11 @@ GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
|||
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
|
||||
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}
|
||||
|
||||
# Install dependencies
|
||||
echo "==> Getting dependencies..."
|
||||
go get ./...
|
||||
# Install dependencies unless running in quick mode
|
||||
if [ "${TF_QUICKDEV}x" == "x" ]; then
|
||||
echo "==> Getting dependencies..."
|
||||
go get ./...
|
||||
fi
|
||||
|
||||
# Delete the old dir
|
||||
echo "==> Removing old directory..."
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'middleman-hashicorp', github: 'hashicorp/middleman-hashicorp'
|
||||
gem 'middleman-hashicorp', git: 'https://github.com/hashicorp/middleman-hashicorp'
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
GIT
|
||||
remote: git://github.com/hashicorp/middleman-hashicorp.git
|
||||
revision: 30c15f93fb501041cff97c490b60ddc96c8314c9
|
||||
remote: https://github.com/hashicorp/middleman-hashicorp
|
||||
revision: 783fe9517dd02badb85e5ddfeda4d8e35bbd05a8
|
||||
specs:
|
||||
middleman-hashicorp (0.1.0)
|
||||
bootstrap-sass (~> 3.2)
|
||||
bootstrap-sass (~> 3.3)
|
||||
builder (~> 3.2)
|
||||
less (~> 2.6)
|
||||
middleman (~> 3.3)
|
||||
middleman-livereload (~> 3.3)
|
||||
middleman-livereload (~> 3.4)
|
||||
middleman-minify-html (~> 3.4)
|
||||
middleman-syntax (~> 2.0)
|
||||
rack-contrib (~> 1.1)
|
||||
rack-contrib (~> 1.2)
|
||||
rack-rewrite (~> 1.5)
|
||||
rack-ssl-enforcer (~> 0.2)
|
||||
redcarpet (~> 3.1)
|
||||
redcarpet (~> 3.2)
|
||||
therubyracer (~> 0.12)
|
||||
thin (~> 1.6)
|
||||
|
||||
|
@ -26,7 +26,7 @@ GEM
|
|||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 1.1)
|
||||
autoprefixer-rails (5.0.0.2)
|
||||
autoprefixer-rails (5.1.7)
|
||||
execjs
|
||||
json
|
||||
bootstrap-sass (3.3.3)
|
||||
|
@ -35,11 +35,11 @@ GEM
|
|||
builder (3.2.2)
|
||||
celluloid (0.16.0)
|
||||
timers (~> 4.0.0)
|
||||
chunky_png (1.3.3)
|
||||
chunky_png (1.3.4)
|
||||
coffee-script (2.3.0)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.8.0)
|
||||
coffee-script-source (1.9.1)
|
||||
commonjs (0.2.7)
|
||||
compass (1.0.3)
|
||||
chunky_png (~> 1.2)
|
||||
|
@ -58,8 +58,8 @@ GEM
|
|||
eventmachine (>= 0.12.9)
|
||||
http_parser.rb (~> 0.6.0)
|
||||
erubis (2.7.0)
|
||||
eventmachine (1.0.4)
|
||||
execjs (2.2.2)
|
||||
eventmachine (1.0.7)
|
||||
execjs (2.4.0)
|
||||
ffi (1.9.6)
|
||||
haml (4.0.6)
|
||||
tilt
|
||||
|
@ -69,9 +69,9 @@ GEM
|
|||
uber (~> 0.0.4)
|
||||
htmlcompressor (0.1.2)
|
||||
http_parser.rb (0.6.0)
|
||||
i18n (0.6.11)
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
kramdown (1.5.0)
|
||||
kramdown (1.6.0)
|
||||
less (2.6.0)
|
||||
commonjs (~> 0.2.7)
|
||||
libv8 (3.16.14.7)
|
||||
|
@ -79,23 +79,23 @@ GEM
|
|||
celluloid (>= 0.15.2)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
middleman (3.3.7)
|
||||
middleman (3.3.10)
|
||||
coffee-script (~> 2.2)
|
||||
compass (>= 1.0.0, < 2.0.0)
|
||||
compass-import-once (= 1.0.5)
|
||||
execjs (~> 2.0)
|
||||
haml (>= 4.0.5)
|
||||
kramdown (~> 1.2)
|
||||
middleman-core (= 3.3.7)
|
||||
middleman-core (= 3.3.10)
|
||||
middleman-sprockets (>= 3.1.2)
|
||||
sass (>= 3.4.0, < 4.0)
|
||||
uglifier (~> 2.5)
|
||||
middleman-core (3.3.7)
|
||||
middleman-core (3.3.10)
|
||||
activesupport (~> 4.1.0)
|
||||
bundler (~> 1.1)
|
||||
erubis
|
||||
hooks (~> 0.3)
|
||||
i18n (~> 0.6.9)
|
||||
i18n (~> 0.7.0)
|
||||
listen (>= 2.7.9, < 3.0)
|
||||
padrino-helpers (~> 0.12.3)
|
||||
rack (>= 1.4.5, < 2.0)
|
||||
|
@ -109,7 +109,7 @@ GEM
|
|||
middleman-minify-html (3.4.0)
|
||||
htmlcompressor (~> 0.1.0)
|
||||
middleman-core (>= 3.2)
|
||||
middleman-sprockets (3.4.1)
|
||||
middleman-sprockets (3.4.2)
|
||||
middleman-core (>= 3.3)
|
||||
sprockets (~> 2.12.1)
|
||||
sprockets-helpers (~> 1.1.0)
|
||||
|
@ -118,12 +118,12 @@ GEM
|
|||
middleman-core (~> 3.2)
|
||||
rouge (~> 1.0)
|
||||
minitest (5.5.1)
|
||||
multi_json (1.10.1)
|
||||
padrino-helpers (0.12.4)
|
||||
multi_json (1.11.0)
|
||||
padrino-helpers (0.12.5)
|
||||
i18n (~> 0.6, >= 0.6.7)
|
||||
padrino-support (= 0.12.4)
|
||||
padrino-support (= 0.12.5)
|
||||
tilt (~> 1.4.1)
|
||||
padrino-support (0.12.4)
|
||||
padrino-support (0.12.5)
|
||||
activesupport (>= 3.1)
|
||||
rack (1.6.0)
|
||||
rack-contrib (1.2.0)
|
||||
|
@ -139,8 +139,8 @@ GEM
|
|||
ffi (>= 0.5.0)
|
||||
redcarpet (3.2.2)
|
||||
ref (1.0.5)
|
||||
rouge (1.7.7)
|
||||
sass (3.4.10)
|
||||
rouge (1.8.0)
|
||||
sass (3.4.13)
|
||||
sprockets (2.12.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
|
@ -166,7 +166,7 @@ GEM
|
|||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
uber (0.0.13)
|
||||
uglifier (2.7.0)
|
||||
uglifier (2.7.1)
|
||||
execjs (>= 0.3.0)
|
||||
json (>= 1.8.0)
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
layout: "digitalocean"
|
||||
page_title: "DigitalOcean: digitalocean_ssh_key"
|
||||
sidebar_current: "docs-do-resource-ssh-key"
|
||||
description: |-
|
||||
Provides a DigitalOcean SSH key resource.
|
||||
---
|
||||
|
||||
# digitalocean\_ssh_key
|
||||
|
||||
Provides a DigitalOcean SSH key resource to allow you manage SSH
|
||||
keys for Droplet access. Keys created with this resource
|
||||
can be referenced in your droplet configuration via their ID or
|
||||
fingerprint.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
# Create a new SSH key
|
||||
resource "digitalocean_ssh_key" "default" {
|
||||
name = "Terraform Example"
|
||||
public_key = "${file("/Users/terraform/.ssh/id_rsa.pub")}"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the SSH key for identification
|
||||
* `public_key` - (Required) The public key. If this is a file, it
|
||||
can be read using the file interpolation function
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The unique ID of the key
|
||||
* `name` - The name of the SSH key
|
||||
* `public_key` - The text of the public key
|
||||
* `fingerprint` - The fingerprint of the SSH key
|
|
@ -96,9 +96,13 @@
|
|||
<a href="/docs/providers/aws/r/vpc.html">aws_vpc</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-vpc-peering") %>>
|
||||
<a href="/docs/providers/aws/r/vpc_peering.html">aws_vpc_peering</a>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-vpn-gateway") %>>
|
||||
<a href="/docs/providers/aws/r/vpn_gateway.html">aws_vpn_gateway</a>
|
||||
</li>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
<li<%= sidebar_current("docs-do-resource-record") %>>
|
||||
<a href="/docs/providers/do/r/record.html">digitalocean_record</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-do-resource-ssh-key") %>>
|
||||
<a href="/docs/providers/do/r/ssh_key.html">digitalocean_ssh_key</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue