@@ -3,11 +3,11 @@ package iterative
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "encoding/base64"
6
7
"encoding/json"
7
8
"fmt"
8
9
"html/template"
9
10
"strconv"
10
- "strings"
11
11
12
12
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -182,27 +182,27 @@ func provisionerCode(d *schema.ResourceData) (string, error) {
182
182
InstanceType {
183
183
SchemaVersion : 0 ,
184
184
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 ),
194
185
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 : "" ,
197
197
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 : "" ,
206
206
},
207
207
},
208
208
},
@@ -212,16 +212,14 @@ func provisionerCode(d *schema.ResourceData) (string, error) {
212
212
return code , err
213
213
}
214
214
215
- //return string(jsonResource), nil
216
-
217
215
data := make (map [string ]string )
218
216
data ["token" ] = d .Get ("token" ).(string )
219
217
data ["repo" ] = d .Get ("repo" ).(string )
220
218
data ["driver" ] = d .Get ("driver" ).(string )
221
219
data ["labels" ] = d .Get ("labels" ).(string )
222
220
data ["idle_timeout" ] = strconv .Itoa (d .Get ("idle_timeout" ).(int ))
223
221
data ["name" ] = d .Get ("name" ).(string )
224
- data ["tf_resource" ] = string (jsonResource )
222
+ data ["tf_resource" ] = base64 . StdEncoding . EncodeToString (jsonResource )
225
223
226
224
tmpl , err := template .New ("deploy" ).Parse (`#!/bin/bash
227
225
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 -
230
228
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
231
229
sudo apt update && sudo apt-get install -y terraform nodejs
232
230
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 &
234
232
sleep 10
235
233
` )
236
234
var customDataBuffer bytes.Buffer
237
235
err = tmpl .Execute (& customDataBuffer , data )
238
236
239
237
if err == nil {
240
- code = strings . Replace ( customDataBuffer .String (), "TF_RESOURCE" , string ( jsonResource ), 1 )
238
+ code = customDataBuffer .String ()
241
239
}
242
240
243
241
return code , nil
0 commit comments