From d4467e446f3ec4bb2d63e329c84b64c0f34c32d2 Mon Sep 17 00:00:00 2001 From: Daniel Barnes Date: Fri, 5 Aug 2022 15:07:59 -0700 Subject: [PATCH] Improper terraform ref causes `Extraneous JSON` error (#1121) --- src/terraform.js | 75 ++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/terraform.js b/src/terraform.js index 37dd856ac..d99fd17f8 100644 --- a/src/terraform.js +++ b/src/terraform.js @@ -1,5 +1,6 @@ const fs = require('fs').promises; const { ltr } = require('semver'); +const winston = require('winston'); const { exec, tfCapture } = require('./utils'); const MIN_TF_VER = '0.14.0'; @@ -77,43 +78,47 @@ const iterativeProviderTpl = ({ tpiVersion }) => ({ } }); -const iterativeCmlRunnerTpl = (opts = {}) => ({ - ...iterativeProviderTpl(opts), - resource: { - iterative_cml_runner: { - runner: { - ...(opts.awsSecurityGroup && { - aws_security_group: opts.awsSecurityGroup - }), - ...(opts.awsSubnet && { aws_subnet: opts.awsSubnet }), - ...(opts.cloud && { cloud: opts.cloud }), - ...(opts.cmlVersion && { cml_version: opts.cmlVersion }), - ...(opts.dockerVolumes && { docker_volumes: opts.dockerVolumes }), - ...(opts.driver && { driver: opts.driver }), - ...(opts.gpu && { instance_gpu: opts.gpu }), - ...(opts.hddSize && { instance_hdd_size: opts.hddSize }), - ...(typeof opts.idleTimeout !== 'undefined' && { - idle_timeout: opts.idleTimeout - }), - ...(opts.labels && { labels: opts.labels }), - ...(opts.metadata && { metadata: opts.metadata }), - ...(opts.name && { name: opts.name }), - ...(opts.permissionSet && { - instance_permission_set: opts.permissionSet - }), - ...(opts.region && { region: opts.region }), - ...(opts.repo && { repo: opts.repo }), - ...(opts.single && { single: opts.single }), - ...(opts.spot && { spot: opts.spot }), - ...(opts.spotPrice && { spot_price: opts.spotPrice }), - ...(opts.sshPrivate && { ssh_private: opts.sshPrivate }), - ...(opts.startupScript && { startup_script: opts.startupScript }), - ...(opts.token && { token: opts.token }), - ...(opts.type && { instance_type: opts.type }) +const iterativeCmlRunnerTpl = (opts = {}) => { + const tfObj = { + ...iterativeProviderTpl(opts), + resource: { + iterative_cml_runner: { + runner: { + ...(opts.awsSecurityGroup && { + aws_security_group: opts.awsSecurityGroup + }), + ...(opts.awsSubnet && { aws_subnet_id: opts.awsSubnet }), + ...(opts.cloud && { cloud: opts.cloud }), + ...(opts.cmlVersion && { cml_version: opts.cmlVersion }), + ...(opts.dockerVolumes && { docker_volumes: opts.dockerVolumes }), + ...(opts.driver && { driver: opts.driver }), + ...(opts.gpu && { instance_gpu: opts.gpu }), + ...(opts.hddSize && { instance_hdd_size: opts.hddSize }), + ...(typeof opts.idleTimeout !== 'undefined' && { + idle_timeout: opts.idleTimeout + }), + ...(opts.labels && { labels: opts.labels }), + ...(opts.metadata && { metadata: opts.metadata }), + ...(opts.name && { name: opts.name }), + ...(opts.permissionSet && { + instance_permission_set: opts.permissionSet + }), + ...(opts.region && { region: opts.region }), + ...(opts.repo && { repo: opts.repo }), + ...(opts.single && { single: opts.single }), + ...(opts.spot && { spot: opts.spot }), + ...(opts.spotPrice && { spot_price: opts.spotPrice }), + ...(opts.sshPrivate && { ssh_private: opts.sshPrivate }), + ...(opts.startupScript && { startup_script: opts.startupScript }), + ...(opts.token && { token: opts.token }), + ...(opts.type && { instance_type: opts.type }) + } } } - } -}); + }; + winston.debug(`terraform data: ${JSON.stringify(tfObj)}`); + return tfObj; +}; const checkMinVersion = async () => { const ver = await version();