Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify TPI version #885

Merged
merged 4 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const runCloud = async (opts) => {

const { token, repo, driver } = cml;
const {
tpiVersion,
labels,
idleTimeout,
name,
Expand Down Expand Up @@ -156,6 +157,7 @@ const runCloud = async (opts) => {
'GPU model "tesla" has been deprecated; please use "v100" instead.'
);
tpl = tf.iterativeCmlRunnerTpl({
tpiVersion,
repo,
token,
driver,
Expand Down Expand Up @@ -345,6 +347,7 @@ const run = async (opts) => {

opts.workdir = opts.workdir || `${homedir()}/.cml/${opts.name}`;
const {
tpiVersion,
driver,
repo,
token,
Expand Down Expand Up @@ -372,7 +375,7 @@ const run = async (opts) => {

await fs.mkdir(tfPath, { recursive: true });
const tfMainPath = join(tfPath, 'main.tf');
const tpl = tf.iterativeProviderTpl();
const tpl = tf.iterativeProviderTpl({ tpiVersion });
await fs.writeFile(tfMainPath, tpl);
await tf.init({ dir: tfPath });
await tf.apply({ dir: tfPath });
Expand Down Expand Up @@ -436,6 +439,12 @@ exports.handler = async (opts) => {
exports.builder = (yargs) =>
yargs.env('CML_RUNNER').options(
kebabcaseKeys({
tpiVersion: {
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
type: 'string',
default: '>= 0.9.10',
description:
'Pin the iterative/iterative terraform provider to a specific version. i.e. "= 0.10.4" See: https://www.terraform.io/language/expressions/version-constraints'
},
dockerVolumes: {
type: 'array',
default: [],
Expand Down
6 changes: 6 additions & 0 deletions bin/cml/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe('CML e2e', () => {
--version Show version number [boolean]
--log Maximum log level
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
--tpi-version Pin the iterative/iterative
terraform provider to a specific
version. i.e. \\"= 0.10.4\\" See:
https://www.terraform.io/language/ex
pressions/version-constraints
[string] [default: \\">= 0.9.10\\"]
--docker-volumes Docker volumes. This feature is only
supported in GitLab
[array] [default: []]
Expand Down
17 changes: 7 additions & 10 deletions src/terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ const destroy = async (opts = {}) => {
const mapCloudMetadata = (metadata) =>
Object.entries(metadata).map(([key, value]) => `${key} = "${value || ''}"`);

const iterativeProviderTpl = () => {
return `
terraform {
const iterativeProviderTpl = (opts = {}) => {
const { tpiVersion } = opts;
return `terraform {
required_providers {
iterative = {
source = "iterative/iterative"
}
iterative = { source = "iterative/iterative"${
tpiVersion ? `, version = "${tpiVersion}"` : ''
} }
}
}
provider "iterative" {}
`;
};
Expand Down Expand Up @@ -91,9 +90,7 @@ const iterativeCmlRunnerTpl = (opts = {}) => {
dockerVolumes
} = opts;

const template = `
${iterativeProviderTpl()}
const template = `${iterativeProviderTpl(opts)}
resource "iterative_cml_runner" "runner" {
${repo ? `repo = "${repo}"` : ''}
${token ? `token = "${token}"` : ''}
Expand Down
70 changes: 14 additions & 56 deletions src/terraform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ describe('Terraform tests', () => {
test('default options', async () => {
const output = iterativeCmlRunnerTpl({});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
Expand Down Expand Up @@ -65,19 +59,13 @@ describe('Terraform tests', () => {
awsSecurityGroup: 'mysg'
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down Expand Up @@ -125,19 +113,13 @@ describe('Terraform tests', () => {
spotPrice: '0.0001'
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down Expand Up @@ -186,19 +168,13 @@ describe('Terraform tests', () => {
metadata: { one: 'value', two: null }
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down Expand Up @@ -250,19 +226,13 @@ describe('Terraform tests', () => {
dockerVolumes: ['/aa:/aa', '/bb:/bb']
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down Expand Up @@ -312,19 +282,13 @@ describe('Terraform tests', () => {
awsSecurityGroup: 'mysg'
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down Expand Up @@ -373,19 +337,13 @@ describe('Terraform tests', () => {
startupScript: 'c3VkbyBlY2hvICdoZWxsbyB3b3JsZCcgPj4gL3Vzci9oZWxsby50eHQ='
});
expect(output).toMatchInlineSnapshot(`
"
terraform {
"terraform {
required_providers {
iterative = {
source = \\"iterative/iterative\\"
}
iterative = { source = \\"iterative/iterative\\" }
}
}
provider \\"iterative\\" {}
resource \\"iterative_cml_runner\\" \\"runner\\" {
repo = \\"https://\\"
token = \\"abc\\"
Expand Down