From f71646a0f4f6937d571292ad38fd833f4815e2a9 Mon Sep 17 00:00:00 2001 From: Tommy Murphy Date: Sun, 14 Aug 2016 16:38:37 -0400 Subject: [PATCH] provider/digitalocean: trim whitespace from ssh key (#8173) --- .../digitalocean/resource_digitalocean_ssh_key.go | 4 ++++ .../digitalocean/resource_digitalocean_ssh_key_test.go | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go b/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go index 1495cb67d..db57085b6 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go +++ b/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "strconv" + "strings" "github.com/digitalocean/godo" "github.com/hashicorp/terraform/helper/schema" @@ -34,6 +35,9 @@ func resourceDigitalOceanSSHKey() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + StateFunc: func(val interface{}) string { + return strings.TrimSpace(val.(string)) + }, }, "fingerprint": &schema.Schema{ diff --git a/builtin/providers/digitalocean/resource_digitalocean_ssh_key_test.go b/builtin/providers/digitalocean/resource_digitalocean_ssh_key_test.go index e14833fe9..ed64cf0f4 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_ssh_key_test.go +++ b/builtin/providers/digitalocean/resource_digitalocean_ssh_key_test.go @@ -27,7 +27,7 @@ func TestAccDigitalOceanSSHKey_Basic(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_ssh_key.foobar", "name", "foobar"), resource.TestCheckResourceAttr( - "digitalocean_ssh_key.foobar", "public_key", testAccValidPublicKey), + "digitalocean_ssh_key.foobar", "public_key", strings.TrimSpace(testAccValidPublicKey)), ), }, }, @@ -111,6 +111,5 @@ resource "digitalocean_ssh_key" "foobar" { public_key = "%s" }`, testAccValidPublicKey) -var testAccValidPublicKey = strings.TrimSpace(` -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR -`) +var testAccValidPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR +`