Skip to content

Commit

Permalink
specify TPI version (#885)
Browse files Browse the repository at this point in the history
* specify TPI version

* set tpi version

* npm run do_snapshots

Co-authored-by: Daniel Barnes <dabarnes2b@gmail.com>
Co-authored-by: Helio Machado <0x2b3bfa0+git@googlemail.com>
  • Loading branch information
3 people authored Apr 16, 2022
1 parent 4c57f93 commit 0ccd79f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 67 deletions.
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: {
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

2 comments on commit 0ccd79f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.