Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 05d22a5

Browse files
ndegoryDavid Chung
authored andcommitted
base64 encode the userdata for AWS and DigitalOcean in the Terraform config (#460)
Signed-off-by: Nicolas Degory <[email protected]>
1 parent cb420e3 commit 05d22a5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

examples/instance/terraform/plugin.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"encoding/base64"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -25,9 +26,9 @@ import (
2526
// This example uses terraform as the instance plugin.
2627
// It is very similar to the file instance plugin. When we
2728
// provision an instance, we write a *.tf.json file in the directory
28-
// and call terra apply. For describing instances, we parse the
29-
// result of terra show. Destroying an instance is simply removing a
30-
// tf.json file and call terra apply again.
29+
// and call terraform apply. For describing instances, we parse the
30+
// result of terraform show. Destroying an instance is simply removing a
31+
// tf.json file and call terraform apply again.
3132

3233
type plugin struct {
3334
Dir string
@@ -324,7 +325,7 @@ func (p *plugin) ensureUniqueFile() string {
324325

325326
func ensureUniqueFile(dir string) string {
326327
n := fmt.Sprintf("instance-%d", time.Now().Unix())
327-
// if we can open then we have to try again... the file cannot exist currently
328+
// if we can open then we have to try again... the file cannot exist currently
328329
if f, err := os.Open(filepath.Join(dir, n) + ".tf.json"); err == nil {
329330
f.Close()
330331
return ensureUniqueFile(dir)
@@ -434,7 +435,7 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
434435
// merge the inits
435436
switch properties.Type {
436437
case "aws_instance", "digitalocean_droplet":
437-
addUserData(properties.Value, "user_data", spec.Init)
438+
addUserData(properties.Value, "user_data", base64.StdEncoding.EncodeToString([]byte(spec.Init)))
438439
case "softlayer_virtual_guest":
439440
addUserData(properties.Value, "user_metadata", spec.Init)
440441
case "azurerm_virtual_machine":

examples/instance/terraform/plugin_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"io/ioutil"
67
"os"
@@ -207,7 +208,7 @@ func run(t *testing.T, resourceType, properties string) {
207208
"label2": "value2",
208209
"Name": string(*id),
209210
}, props["tags"])
210-
require.Equal(t, instanceSpec.Init, props["user_data"])
211+
require.Equal(t, base64.StdEncoding.EncodeToString([]byte(instanceSpec.Init)), props["user_data"])
211212
}
212213

213214
// label resources

0 commit comments

Comments
 (0)