@@ -3,11 +3,11 @@ package iterative
33import (
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
227225echo "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 -
230228sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
231229sudo apt update && sudo apt-get install -y terraform nodejs
232230sudo 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 &
234232sleep 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