Skip to content

Commit 73912dd

Browse files
committed
base64
1 parent 52f30aa commit 73912dd

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

examples/main.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
terraform {
22
required_providers {
3-
iterative = {
4-
versions = ["0.6"]
5-
source = "github.com/iterative/iterative"
6-
}
7-
83
# iterative = {
9-
# source = "iterative/iterative"
10-
# version = "0.5.3"
4+
# versions = ["0.6"]
5+
# source = "github.com/iterative/iterative"
116
# }
7+
8+
iterative = {
9+
source = "iterative/iterative"
10+
version = "0.5.4"
11+
}
1212
}
1313
}
1414

@@ -23,17 +23,17 @@ resource "iterative_machine" "machine-az" {
2323
*/
2424

2525

26-
resource "iterative_runner" "runner-az" {
27-
name = "holy-moly4"
28-
token = "arszDpb3xtNdKaXmQ6vN"
29-
repo = "https://gitlab.com/DavidGOrtega/3_tensorboard"
30-
driver = "gitlab"
31-
labels = "tf"
26+
# resource "iterative_runner" "runner-az" {
27+
# name = "holy-moly5"
28+
# token = "arszDpb3xtNdKaXmQ6vN"
29+
# repo = "https://gitlab.com/DavidGOrtega/3_tensorboard"
30+
# driver = "gitlab"
31+
# labels = "tf"
3232

33-
cloud = "azure"
34-
region = "us-west"
35-
instance_type = "m"
36-
}
33+
# cloud = "azure"
34+
# region = "us-west"
35+
# instance_type = "m"
36+
# }
3737

3838
/*
3939
resource "iterative_machine" "machine-aws" {

iterative/resource_runner.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package iterative
33
import (
44
"bytes"
55
"context"
6+
"encoding/base64"
67
"encoding/json"
78
"fmt"
89
"html/template"
910
"strconv"
10-
"strings"
1111

1212
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -182,27 +182,27 @@ func provisionerCode(d *schema.ResourceData) (string, error) {
182182
InstanceType{
183183
SchemaVersion: 0,
184184
Attributes: AttributesType{
185-
Name: d.Get("name").(string),
186-
Labels: d.Get("name").(string),
187-
IdleTimeout: d.Get("idle_timeout").(int),
188-
Repo: d.Get("name").(string),
189-
Token: d.Get("name").(string),
190-
Driver: d.Get("name").(string),
191-
AwsSecurityGroup: d.Get("name").(string),
192-
Cloud: d.Get("name").(string),
193-
CustomData: d.Get("name").(string),
194185
ID: d.Get("name").(string),
195-
Image: d.Get("name").(string),
196-
InstanceGpu: d.Get("name").(string),
186+
Name: "",
187+
Labels: "",
188+
IdleTimeout: d.Get("idle_timeout").(int),
189+
Repo: "",
190+
Token: "",
191+
Driver: "",
192+
AwsSecurityGroup: "",
193+
Cloud: "",
194+
CustomData: "",
195+
Image: "",
196+
InstanceGpu: "",
197197
InstanceHddSize: d.Get("instance_hdd_size").(int),
198-
InstanceID: d.Get("name").(string),
199-
InstanceIP: d.Get("name").(string),
200-
InstanceLaunchTime: d.Get("name").(string),
201-
InstanceType: d.Get("name").(string),
202-
Region: d.Get("name").(string),
203-
SSHName: d.Get("name").(string),
204-
SSHPrivate: d.Get("name").(string),
205-
SSHPublic: d.Get("name").(string),
198+
InstanceID: "",
199+
InstanceIP: "",
200+
InstanceLaunchTime: "",
201+
InstanceType: "",
202+
Region: "",
203+
SSHName: "",
204+
SSHPrivate: "",
205+
SSHPublic: "",
206206
},
207207
},
208208
},
@@ -212,16 +212,14 @@ func provisionerCode(d *schema.ResourceData) (string, error) {
212212
return code, err
213213
}
214214

215-
//return string(jsonResource), nil
216-
217215
data := make(map[string]string)
218216
data["token"] = d.Get("token").(string)
219217
data["repo"] = d.Get("repo").(string)
220218
data["driver"] = d.Get("driver").(string)
221219
data["labels"] = d.Get("labels").(string)
222220
data["idle_timeout"] = strconv.Itoa(d.Get("idle_timeout").(int))
223221
data["name"] = d.Get("name").(string)
224-
data["tf_resource"] = string(jsonResource)
222+
data["tf_resource"] = base64.StdEncoding.EncodeToString(jsonResource)
225223

226224
tmpl, err := template.New("deploy").Parse(`#!/bin/bash
227225
echo "APT::Get::Assume-Yes \"true\";" | sudo tee -a /etc/apt/apt.conf.d/90assumeyes
@@ -230,14 +228,14 @@ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
230228
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
231229
sudo apt update && sudo apt-get install -y terraform nodejs
232230
sudo npm install -g git+https://github.com/iterative/cml.git#cml-runner
233-
nohup cml-runner{{if .name}} --name {{.name}}{{end}}{{if .labels}} --labels {{.labels}}{{end}}{{if .idle_timeout}} --idle-timeout {{.idle_timeout}}{{end}}{{if .driver}} --driver {{.driver}}{{end}}{{if .repo}} --repo {{.repo}}{{end}}{{if .token}} --token {{.token}}{{end}}{{if .tf_resource}} --tf_resource='TF_RESOURCE'{{end}} < /dev/null > std.out 2> std.err &
231+
nohup cml-runner{{if .name}} --name {{.name}}{{end}}{{if .labels}} --labels {{.labels}}{{end}}{{if .idle_timeout}} --idle-timeout {{.idle_timeout}}{{end}}{{if .driver}} --driver {{.driver}}{{end}}{{if .repo}} --repo {{.repo}}{{end}}{{if .token}} --token {{.token}}{{end}}{{if .tf_resource}} --tf_resource={{.tf_resource}}{{end}} < /dev/null > std.out 2> std.err &
234232
sleep 10
235233
`)
236234
var customDataBuffer bytes.Buffer
237235
err = tmpl.Execute(&customDataBuffer, data)
238236

239237
if err == nil {
240-
code = strings.Replace(customDataBuffer.String(), "TF_RESOURCE", string(jsonResource), 1)
238+
code = customDataBuffer.String()
241239
}
242240

243241
return code, nil

0 commit comments

Comments
 (0)